Skip to content

Fix lens mask required component and state #1386

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

Merged
merged 2 commits into from
Dec 19, 2024
Merged
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
5 changes: 3 additions & 2 deletions kasa/smartcam/modules/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def _initialize_features(self) -> None:
self._device,
id="state",
name="State",
container=self,
attribute_getter="is_on",
attribute_setter="set_state",
type=Feature.Type.Switch,
Expand All @@ -50,7 +51,7 @@ def _initialize_features(self) -> None:
def is_on(self) -> bool:
"""Return the device on state."""
if lens_mask := self._device.modules.get(Module.LensMask):
return lens_mask.state
return not lens_mask.enabled
return True

async def set_state(self, on: bool) -> Annotated[dict, FeatureAttribute()]:
Expand All @@ -60,7 +61,7 @@ async def set_state(self, on: bool) -> Annotated[dict, FeatureAttribute()]:
"""
if lens_mask := self._device.modules.get(Module.LensMask):
# Turning off enables the privacy mask which is why value is reversed.
return await lens_mask.set_state(not on)
return await lens_mask.set_enabled(not on)
return {}

def _get_credentials(self) -> Credentials | None:
Expand Down
10 changes: 6 additions & 4 deletions kasa/smartcam/modules/lensmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@
class LensMask(SmartCamModule):
"""Implementation of lens mask module."""

REQUIRED_COMPONENT = "lensMask"

QUERY_GETTER_NAME = "getLensMaskConfig"
QUERY_MODULE_NAME = "lens_mask"
QUERY_SECTION_NAMES = "lens_mask_info"

@property
def state(self) -> bool:
def enabled(self) -> bool:
"""Return the lens mask state."""
return self.data["lens_mask_info"]["enabled"] == "off"
return self.data["lens_mask_info"]["enabled"] == "on"

async def set_state(self, state: bool) -> dict:
async def set_enabled(self, enable: bool) -> dict:
"""Set the lens mask state."""
params = {"enabled": "on" if state else "off"}
params = {"enabled": "on" if enable else "off"}
return await self._device._query_setter_helper(
"setLensMaskConfig", self.QUERY_MODULE_NAME, "lens_mask_info", params
)
Loading