Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit api usage #145

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages = ["src/abbfreeathome"]

[project]
name = "local-abbfreeathome"
version = "1.17.4"
version = "1.18.0"
authors = [
{ name="Adam Kingsley", email="[email protected]" },
]
Expand Down
10 changes: 6 additions & 4 deletions src/abbfreeathome/devices/dimming_actuator.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ def forced_position(self) -> str | None:

async def turn_on(self):
"""Turn on the dimmer."""
await self._set_switching_datapoint("1")
self._state = True
if not self._state:
await self._set_switching_datapoint("1")
self._state = True

async def turn_off(self):
"""Turn on the dimmer."""
await self._set_switching_datapoint("0")
self._state = False
if self._state:
await self._set_switching_datapoint("0")
self._state = False

async def set_brightness(self, value: int):
"""
Expand Down
10 changes: 6 additions & 4 deletions src/abbfreeathome/devices/switch_actuator.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ def forced_position(self) -> str | None:

async def turn_on(self):
"""Turn on the switch."""
await self._set_switching_datapoint("1")
self._state = True
if not self._state:
await self._set_switching_datapoint("1")
self._state = True

async def turn_off(self):
"""Turn on the switch."""
await self._set_switching_datapoint("0")
self._state = False
if self._state:
await self._set_switching_datapoint("0")
self._state = False

async def set_forced_position(self, forced_position_name: str):
"""Set the forced-option on the switch."""
Expand Down
28 changes: 26 additions & 2 deletions tests/test_dimming_actuator.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ async def test_initial_state(dimming_actuator):


@pytest.mark.asyncio
async def test_turn_on(dimming_actuator):
async def test_turn_on_while_off(dimming_actuator):
"""Test to turning on the DimmingActuator."""
dimming_actuator._state = False
assert dimming_actuator.state is False
await dimming_actuator.turn_on()
assert dimming_actuator.state is True
dimming_actuator._api.set_datapoint.assert_called_with(
Expand All @@ -65,8 +67,20 @@ async def test_turn_on(dimming_actuator):


@pytest.mark.asyncio
async def test_turn_off(dimming_actuator):
async def test_turn_on_while_on(dimming_actuator):
"""Test to turning on the DimmingActuator, while already on."""
dimming_actuator._state = True
assert dimming_actuator.state is True
await dimming_actuator.turn_on()
assert dimming_actuator.state is True
dimming_actuator._api.set_datapoint.assert_not_called()


@pytest.mark.asyncio
async def test_turn_off_while_on(dimming_actuator):
"""Test to turning off the DimmingActuator."""
dimming_actuator._state = True
assert dimming_actuator.state is True
await dimming_actuator.turn_off()
assert dimming_actuator.state is False
dimming_actuator._api.set_datapoint.assert_called_with(
Expand All @@ -77,6 +91,16 @@ async def test_turn_off(dimming_actuator):
)


@pytest.mark.asyncio
async def test_turn_off_while_off(dimming_actuator):
"""Test to turning off the DimmingActuator, while already off."""
dimming_actuator._state = False
assert dimming_actuator.state is False
await dimming_actuator.turn_off()
assert dimming_actuator.state is False
dimming_actuator._api.set_datapoint.assert_not_called()


@pytest.mark.asyncio
async def test_set_brightness(dimming_actuator):
"""Test to set brightness off the DimmingActuator."""
Expand Down
28 changes: 26 additions & 2 deletions tests/test_switch_actuator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ async def test_initial_state(switch_actuator):


@pytest.mark.asyncio
async def test_turn_on(switch_actuator):
async def test_turn_on_while_off(switch_actuator):
"""Test to turning on of the switch."""
switch_actuator._state = False
assert switch_actuator.state is False
await switch_actuator.turn_on()
assert switch_actuator.state is True
switch_actuator._api.set_datapoint.assert_called_with(
Expand All @@ -66,8 +68,20 @@ async def test_turn_on(switch_actuator):


@pytest.mark.asyncio
async def test_turn_off(switch_actuator):
async def test_turn_on_while_on(switch_actuator):
"""Test to turning on of the switch, while already on."""
switch_actuator._state = True
assert switch_actuator.state is True
await switch_actuator.turn_on()
assert switch_actuator.state is True
switch_actuator._api.set_datapoint.assert_not_called()


@pytest.mark.asyncio
async def test_turn_off_while_on(switch_actuator):
"""Test to turning off of the switch."""
switch_actuator._state = True
assert switch_actuator.state is True
await switch_actuator.turn_off()
assert switch_actuator.state is False
switch_actuator._api.set_datapoint.assert_called_with(
Expand All @@ -78,6 +92,16 @@ async def test_turn_off(switch_actuator):
)


@pytest.mark.asyncio
async def test_turn_off_while_off(switch_actuator):
"""Test to turning off of the switch, while already off."""
switch_actuator._state = False
assert switch_actuator.state is False
await switch_actuator.turn_off()
assert switch_actuator.state is False
switch_actuator._api.set_datapoint.assert_not_called()


@pytest.mark.asyncio
async def test_set_forced(switch_actuator):
"""Test to set the forced option of the switch."""
Expand Down
Loading