Skip to content

Commit

Permalink
Merge pull request #499 from PoppyPop/development
Browse files Browse the repository at this point in the history
Add preferred position functionnality to shutter
  • Loading branch information
jabesq authored Jun 18, 2024
2 parents fe405ab + 727ca4d commit 6eef5b9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/pyatmo/modules/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ async def async_set_fan_speed(self, speed: int) -> bool:
class ShutterMixin(EntityBase):
"""Mixin for shutter data."""

__open_position = 100
__close_position = 0
__stop_position = -1
__preferred_position = -2

def __init__(self, home: Home, module: ModuleT):
"""Initialize shutter mixin."""

Expand All @@ -414,11 +419,16 @@ def __init__(self, home: Home, module: ModuleT):
async def async_set_target_position(self, target_position: int) -> bool:
"""Set shutter to target position."""

# in case of a too low value, we default to stop and not the preferred position
# We check against __preferred_position that is the lower known value
if target_position < self.__preferred_position:
target_position = self.__stop_position

json_roller_shutter = {
"modules": [
{
"id": self.entity_id,
"target_position": max(min(100, target_position), -1),
"target_position": min(self.__open_position, target_position),
"bridge": self.bridge,
},
],
Expand All @@ -428,17 +438,22 @@ async def async_set_target_position(self, target_position: int) -> bool:
async def async_open(self) -> bool:
"""Open shutter."""

return await self.async_set_target_position(100)
return await self.async_set_target_position(self.__open_position)

async def async_close(self) -> bool:
"""Close shutter."""

return await self.async_set_target_position(0)
return await self.async_set_target_position(self.__close_position)

async def async_stop(self) -> bool:
"""Stop shutter."""

return await self.async_set_target_position(-1)
return await self.async_set_target_position(self.__stop_position)

async def async_move_to_preferred_position(self) -> bool:
"""Move shutter to preferred position."""

return await self.async_set_target_position(self.__preferred_position)


class CameraMixin(EntityBase):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_shutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ def gen_json_data(position):
endpoint="api/setstate",
)

assert await module.async_move_to_preferred_position()
mock_resp.assert_awaited_with(
params=gen_json_data(-2),
endpoint="api/setstate",
)

assert await module.async_set_target_position(47)
mock_resp.assert_awaited_with(
params=gen_json_data(47),
Expand Down

0 comments on commit 6eef5b9

Please sign in to comment.