2022-01-29 16:53:18 +00:00
|
|
|
"""Implementation of the ambient light (LAS) module found in some dimmers."""
|
2024-04-16 18:21:20 +00:00
|
|
|
|
2024-04-24 16:38:52 +00:00
|
|
|
from ...feature import Feature
|
2024-02-22 18:11:30 +00:00
|
|
|
from ..iotmodule import IotModule, merge
|
2022-01-29 16:53:18 +00:00
|
|
|
|
|
|
|
# TODO create tests and use the config reply there
|
|
|
|
# [{"hw_id":0,"enable":0,"dark_index":1,"min_adc":0,"max_adc":2450,
|
|
|
|
# "level_array":[{"name":"cloudy","adc":490,"value":20},
|
|
|
|
# {"name":"overcast","adc":294,"value":12},
|
|
|
|
# {"name":"dawn","adc":222,"value":9},
|
|
|
|
# {"name":"twilight","adc":222,"value":9},
|
|
|
|
# {"name":"total darkness","adc":111,"value":4},
|
|
|
|
# {"name":"custom","adc":2400,"value":97}]}]
|
|
|
|
|
|
|
|
|
2024-02-04 15:20:08 +00:00
|
|
|
class AmbientLight(IotModule):
|
2022-01-29 16:53:18 +00:00
|
|
|
"""Implements ambient light controls for the motion sensor."""
|
|
|
|
|
2024-02-22 18:11:30 +00:00
|
|
|
def __init__(self, device, module):
|
|
|
|
super().__init__(device, module)
|
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
device=device,
|
|
|
|
container=self,
|
2024-05-07 09:13:35 +00:00
|
|
|
id="ambient_light",
|
2024-02-22 18:11:30 +00:00
|
|
|
name="Ambient Light",
|
|
|
|
icon="mdi:brightness-percent",
|
|
|
|
attribute_getter="ambientlight_brightness",
|
2024-04-24 16:38:52 +00:00
|
|
|
type=Feature.Type.Sensor,
|
2024-05-07 09:13:35 +00:00
|
|
|
category=Feature.Category.Primary,
|
|
|
|
unit="%",
|
2024-02-22 18:11:30 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2022-01-29 16:53:18 +00:00
|
|
|
def query(self):
|
|
|
|
"""Request configuration."""
|
2024-02-22 18:11:30 +00:00
|
|
|
req = merge(
|
|
|
|
self.query_for_command("get_config"),
|
|
|
|
self.query_for_command("get_current_brt"),
|
|
|
|
)
|
|
|
|
|
|
|
|
return req
|
2022-01-29 16:53:18 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def presets(self) -> dict:
|
|
|
|
"""Return device-defined presets for brightness setting."""
|
|
|
|
return self.data["level_array"]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def enabled(self) -> bool:
|
|
|
|
"""Return True if the module is enabled."""
|
|
|
|
return bool(self.data["enable"])
|
|
|
|
|
2024-02-22 18:11:30 +00:00
|
|
|
@property
|
|
|
|
def ambientlight_brightness(self) -> int:
|
|
|
|
"""Return True if the module is enabled."""
|
|
|
|
return int(self.data["get_current_brt"]["value"])
|
|
|
|
|
2022-01-29 16:53:18 +00:00
|
|
|
async def set_enabled(self, state: bool):
|
|
|
|
"""Enable/disable LAS."""
|
|
|
|
return await self.call("set_enable", {"enable": int(state)})
|
|
|
|
|
|
|
|
async def current_brightness(self) -> int:
|
|
|
|
"""Return current brightness.
|
|
|
|
|
|
|
|
Return value units.
|
|
|
|
"""
|
|
|
|
return await self.call("get_current_brt")
|
|
|
|
|
|
|
|
async def set_brightness_limit(self, value: int):
|
|
|
|
"""Set the limit when the motion sensor is inactive.
|
|
|
|
|
|
|
|
See `presets` for preset values. Custom values are also likely allowed.
|
|
|
|
"""
|
|
|
|
return await self.call("set_brt_level", {"index": 0, "value": value})
|