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
def get_wireless_scan_info(
params: Optional[GetRulesParams] = None
params: Optional[GetRulesParams] = None,
) -> "SmartRequest":
"""Get wireless scan info."""
return SmartRequest(
@ -273,7 +273,7 @@ class SmartRequest:
@staticmethod
def get_dynamic_light_effect_rules(
params: Optional[GetRulesParams] = None
params: Optional[GetRulesParams] = None,
) -> "SmartRequest":
"""Get dynamic light effect rules."""
return SmartRequest(
@ -292,7 +292,7 @@ class 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)
@ -312,7 +312,7 @@ class 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):

View File

@ -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,
@ -14,9 +15,27 @@ from ..iotmodule import IotModule
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:
@ -28,6 +47,11 @@ class AmbientLight(IotModule):
"""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)})