Skip to content

Commit

Permalink
💡 fix for light state (#2250)
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Jan 2, 2025
1 parent eea843e commit ea1414e
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions custom_components/xiaomi_miot/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,32 +125,31 @@ def get_state(self) -> dict:

def set_state(self, data: dict):
val = data.get(self.attr)
if val != None:
val = bool(val)
self._attr_is_on = val
if val is not None:
self._attr_is_on = bool(val)

if (val := data.get(self._attr_names.get(ATTR_BRIGHTNESS))) != None:
if (val := data.get(self._attr_names.get(ATTR_BRIGHTNESS))) is not None:
self._attr_brightness = val
if self._brightness_for_on != None:
if self._brightness_for_on is not None:
self._attr_is_on = val >= self._brightness_for_on
if (val := data.get(self._attr_names.get(ATTR_COLOR_TEMP_KELVIN))) != None:
if (val := data.get(self._attr_names.get(ATTR_COLOR_TEMP_KELVIN))) is not None:
if val != self._attr_color_temp_kelvin:
self._attr_color_temp_kelvin = val
self._attr_color_mode = ColorMode.COLOR_TEMP
elif (val := data.get(self._attr_names.get(ATTR_COLOR_TEMP))) != None:
elif (val := data.get(self._attr_names.get(ATTR_COLOR_TEMP))) is not None:
if val != self._attr_color_temp:
self._attr_color_temp = val
self._attr_color_mode = ColorMode.COLOR_TEMP
if (val := data.get(self._attr_names.get(ATTR_RGB_COLOR))) != None:
if (val := data.get(self._attr_names.get(ATTR_RGB_COLOR))) is not None:
if val != self._attr_rgb_color:
self._attr_rgb_color = val
self._attr_color_mode = ColorMode.RGB
if (val := data.get(self._attr_names.get(ATTR_EFFECT))) != None:
if (val := data.get(self._attr_names.get(ATTR_EFFECT))) is not None:
self._attr_effect = val

async def async_turn_on(self, **kwargs):
dat = {self.attr: True}
if self._brightness_for_on != None:
if self._brightness_for_on is not None:
dat[self.attr] = self._brightness_for_on
for k, v in kwargs.items():
if attr := self._attr_names.get(k):
Expand All @@ -159,7 +158,7 @@ async def async_turn_on(self, **kwargs):

async def async_turn_off(self, **kwargs):
dat = {self.attr: False}
if self._brightness_for_off != None:
if self._brightness_for_off is not None:
dat[self.attr] = self._brightness_for_off
await self.device.async_write(dat)

Expand Down

1 comment on commit ea1414e

@al-one
Copy link
Owner Author

@al-one al-one commented on ea1414e Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.