Add feature for ambient light sensor (#787)

This commit is contained in:
Benjamin Ness 2024-02-22 12:11:30 -06:00 committed by GitHub
parent a87fc3b766
commit f965b14021
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 6 deletions

View File

@ -168,7 +168,7 @@ class SmartRequest:
@staticmethod @staticmethod
def get_wireless_scan_info( def get_wireless_scan_info(
params: Optional[GetRulesParams] = None params: Optional[GetRulesParams] = None,
) -> "SmartRequest": ) -> "SmartRequest":
"""Get wireless scan info.""" """Get wireless scan info."""
return SmartRequest( return SmartRequest(
@ -273,7 +273,7 @@ class SmartRequest:
@staticmethod @staticmethod
def get_dynamic_light_effect_rules( def get_dynamic_light_effect_rules(
params: Optional[GetRulesParams] = None params: Optional[GetRulesParams] = None,
) -> "SmartRequest": ) -> "SmartRequest":
"""Get dynamic light effect rules.""" """Get dynamic light effect rules."""
return SmartRequest( return SmartRequest(
@ -292,7 +292,7 @@ class SmartRequest:
@staticmethod @staticmethod
def set_dynamic_light_effect_rule_enable( def set_dynamic_light_effect_rule_enable(
params: DynamicLightEffectParams params: DynamicLightEffectParams,
) -> "SmartRequest": ) -> "SmartRequest":
"""Enable dynamic light effect rule.""" """Enable dynamic light effect rule."""
return SmartRequest("set_dynamic_light_effect_rule_enable", params) return SmartRequest("set_dynamic_light_effect_rule_enable", params)
@ -312,7 +312,7 @@ class SmartRequest:
@staticmethod @staticmethod
def _create_request_dict( def _create_request_dict(
smart_request: Union["SmartRequest", List["SmartRequest"]] smart_request: Union["SmartRequest", List["SmartRequest"]],
) -> dict: ) -> dict:
"""Create request dict to be passed to SmartProtocol.query().""" """Create request dict to be passed to SmartProtocol.query()."""
if isinstance(smart_request, list): if isinstance(smart_request, list):

View File

@ -1,5 +1,6 @@
"""Implementation of the ambient light (LAS) module found in some dimmers.""" """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 # TODO create tests and use the config reply there
# [{"hw_id":0,"enable":0,"dark_index":1,"min_adc":0,"max_adc":2450, # [{"hw_id":0,"enable":0,"dark_index":1,"min_adc":0,"max_adc":2450,
@ -14,9 +15,27 @@ from ..iotmodule import IotModule
class AmbientLight(IotModule): class AmbientLight(IotModule):
"""Implements ambient light controls for the motion sensor.""" """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): def query(self):
"""Request configuration.""" """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 @property
def presets(self) -> dict: def presets(self) -> dict:
@ -28,6 +47,11 @@ class AmbientLight(IotModule):
"""Return True if the module is enabled.""" """Return True if the module is enabled."""
return bool(self.data["enable"]) 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): async def set_enabled(self, state: bool):
"""Enable/disable LAS.""" """Enable/disable LAS."""
return await self.call("set_enable", {"enable": int(state)}) return await self.call("set_enable", {"enable": int(state)})