8000 Add feature for ambient light sensor by shifty35 · Pull Request #787 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

Add feature for ambient light sensor #787

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
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
8 changes: 4 additions & 4 deletions devtools/helpers/smartrequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def get_device_time() -> "SmartRequest":

@staticmethod
def get_wireless_scan_info(
params: Optional[GetRulesParams] = None
params: Optional[GetRulesParams] = None,
) -> "SmartRequest":
"""Get wireless scan info."""
return SmartRequest(
Expand Down Expand Up @@ -273,7 +273,7 @@ def get_auto_light_info() -> "SmartRequest":

@staticmethod
def get_dynamic_light_effect_rules(
params: Optional[GetRulesParams] = None
params: Optional[GetRulesParams] = None,
) -> "SmartRequest":
"""Get dynamic light effect rules."""
return SmartRequest(
Expand All @@ -292,7 +292,7 @@ def set_light_info(params: LightInfoParams) -> "SmartRequest":

@staticmethod
def set_dynamic_light_effect_rule_enable(
params: DynamicLightEffectParams
params: DynamicLightEffectParams,
) -> "SmartRequest":
"""Enable dynamic light effect rule."""
return SmartRequest("set_dynamic_light_effect_rule_enable", params)
Expand All @@ -312,7 +312,7 @@ def get_component_info_requests(component_nego_response) -> List["SmartRequest"]

@staticmethod
def _create_request_dict(
smart_request: Union["SmartRequest", List["SmartRequest"]]
smart_request: Union["SmartRequest", List["SmartRequest"]],
) -> dict:
"""Create request dict to be passed to SmartProtocol.query()."""
if isinstance(smart_request, list):
Expand Down
28 changes: 26 additions & 2 deletions kasa/iot/modules/ambientlight.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Implementation of the ambient light (LAS) module found in some dimmers."""
from ..iotmodule import IotModule
from ...feature import Feature, FeatureType
from ..iotmodule import IotModule, merge

# TODO create tests and use the config reply there
# [{"hw_id":0,"enable":0,"dark_index":1,"min_adc":0,"max_adc":2450,
Expand All @@ -14,9 +15,27 @@
class AmbientLight(IotModule):
"""Implements ambient light controls for the motion sensor."""

def __init__(self, device, module):
super().__init__(device, module)
self._add_feature(
Feature(
device=device,
container=self,
name="Ambient Light",
icon="mdi:brightness-percent",
attribute_getter="ambientlight_brightness",
type=FeatureType.Sensor,
)
)

def query(self):
"""Request configuration."""
return self.query_for_command("get_config")
req = merge(
self.query_for_command("get_config"),
self.query_for_command("get_current_brt"),
)

return req

@property
def presets(self) -> dict:
Expand All @@ -28,6 +47,11 @@ def enabled(self) -> bool:
"""Return True if the module is enabled."""
return bool(self.data["enable"])

@property
def ambientlight_brightness(self) -> int:
"""Return True if the module is enabled."""
return int(self.data["get_current_brt"]["value"])

async def set_enabled(self, state: bool):
"""Enable/disable LAS."""
return await self.call("set_enable", {"enable": int(state)})
Expand Down
0