Skip to content

Commit

Permalink
add preferred position functionnality to shutter
Browse files Browse the repository at this point in the history
  • Loading branch information
PoppyPop committed May 23, 2024
1 parent 4296c98 commit 9603096
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/pyatmo/modules/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,15 @@ 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
if target_position < -2:
target_position = -1

json_roller_shutter = {
"modules": [
{
"id": self.entity_id,
"target_position": max(min(100, target_position), -1),
"target_position": min(100, target_position),
"bridge": self.bridge,
},
],
Expand All @@ -439,6 +443,11 @@ async def async_stop(self) -> bool:

return await self.async_set_target_position(-1)

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

return await self.async_set_target_position(-2)


class CameraMixin(EntityBase):
"""Mixin for camera data."""
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_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 9603096

Please sign in to comment.