diff --git a/custom_components/localtuya/__init__.py b/custom_components/localtuya/__init__.py index 3f7b0c6..ae2c893 100644 --- a/custom_components/localtuya/__init__.py +++ b/custom_components/localtuya/__init__.py @@ -34,6 +34,8 @@ localtuya: friendly_name: Device Light id: 4 brightness: 20 + brightness_lower: 29 # Optional + brightness_upper: 1000 # Optional color_temp: 21 - platform: sensor diff --git a/custom_components/localtuya/light.py b/custom_components/localtuya/light.py index e8f4b04..2740216 100644 --- a/custom_components/localtuya/light.py +++ b/custom_components/localtuya/light.py @@ -35,7 +35,7 @@ def map_range(value, from_lower, from_upper, to_lower, to_upper): mapped = (value - from_lower) * (to_upper - to_lower) / ( from_upper - from_lower ) + to_lower - return int(min(max(mapped, to_lower), to_upper)) + return round(min(max(mapped, to_lower), to_upper)) def flow_schema(dps): @@ -112,7 +112,7 @@ class LocaltuyaLight(LocalTuyaEntity, LightEntity): async def async_turn_on(self, **kwargs): """Turn on or control the light.""" - self._device.set_dp(True, self._dp_id) + await self._device.set_dp(True, self._dp_id) features = self.supported_features if ATTR_BRIGHTNESS in kwargs and (features & SUPPORT_BRIGHTNESS): @@ -123,7 +123,7 @@ class LocaltuyaLight(LocalTuyaEntity, LightEntity): self._lower_brightness, self._upper_brightness, ) - self._device.set_dp(brightness, self._config.get(CONF_BRIGHTNESS)) + await self._device.set_dp(brightness, self._config.get(CONF_BRIGHTNESS)) if ATTR_HS_COLOR in kwargs: raise ValueError(" TODO implement RGB from HS")