Expose ambient light setting for iot dimmers (#1210)

This PR adds a setting to control the ambient light enabled/disabled.

Also fixes the getters.
This commit is contained in:
Teemu R.
2024-10-31 12:17:18 +01:00
committed by GitHub
parent 9975bbf26a
commit 6c141c3b65
2 changed files with 74 additions and 10 deletions

View File

@@ -1,16 +1,11 @@
"""Implementation of the ambient light (LAS) module found in some dimmers."""
import logging
from ...feature import Feature
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,
# "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}]}]
_LOGGER = logging.getLogger(__name__)
class AmbientLight(IotModule):
@@ -18,6 +13,19 @@ class AmbientLight(IotModule):
def _initialize_features(self):
"""Initialize features after the initial update."""
self._add_feature(
Feature(
device=self._device,
container=self,
id="ambient_light_enabled",
name="Ambient light enabled",
icon="mdi:brightness-percent",
attribute_getter="enabled",
attribute_setter="set_enabled",
type=Feature.Type.Switch,
category=Feature.Category.Config,
)
)
self._add_feature(
Feature(
device=self._device,
@@ -41,15 +49,25 @@ class AmbientLight(IotModule):
return req
@property
def config(self) -> dict:
"""Return current ambient light config."""
config = self.data["get_config"]
devs = config["devs"]
if len(devs) != 1:
_LOGGER.error("Unexpected number of devs in config: %s", config)
return devs[0]
@property
def presets(self) -> dict:
"""Return device-defined presets for brightness setting."""
return self.data["level_array"]
return self.config["level_array"]
@property
def enabled(self) -> bool:
"""Return True if the module is enabled."""
return bool(self.data["enable"])
return bool(self.config["enable"])
@property
def ambientlight_brightness(self) -> int: