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

Add preferred position functionnality to shutter #499

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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:
PoppyPop marked this conversation as resolved.
Show resolved Hide resolved
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:
PoppyPop marked this conversation as resolved.
Show resolved Hide resolved
"""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()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Test for edge case of target_position < -2

Consider adding a test case to ensure that when target_position is set to a value less than -2, it defaults to -1. This will help verify the backward compatibility and the new functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test assert await module.async_set_target_position(-10) already cover this

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