Просмотр исходного кода

Protect against None values when calling upper().

When device is not available, mode can be None. Handle that.
Jason Rumney 3 лет назад
Родитель
Сommit
e67802f4c8
1 измененных файлов с 4 добавлено и 4 удалено
  1. 4 4
      custom_components/tuya_local/generic/light.py

+ 4 - 4
custom_components/tuya_local/generic/light.py

@@ -51,7 +51,7 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
             return [
             return [
                 ColorMode(mode)
                 ColorMode(mode)
                 for mode in self._color_mode_dps.values(self._device)
                 for mode in self._color_mode_dps.values(self._device)
-                if hasattr(ColorMode, mode.upper())
+                if mode and hasattr(ColorMode, mode.upper())
             ]
             ]
         else:
         else:
             try:
             try:
@@ -75,7 +75,7 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
         """Return the color mode of the light"""
         """Return the color mode of the light"""
         if self._color_mode_dps:
         if self._color_mode_dps:
             mode = self._color_mode_dps.get_value(self._device)
             mode = self._color_mode_dps.get_value(self._device)
-            if hasattr(ColorMode, mode.upper()):
+            if mode and hasattr(ColorMode, mode.upper()):
                 return ColorMode(mode)
                 return ColorMode(mode)
 
 
         if self._rgbhsv_dps:
         if self._rgbhsv_dps:
@@ -170,7 +170,7 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
             return [
             return [
                 effect
                 effect
                 for effect in self._color_mode_dps.values(self._device)
                 for effect in self._color_mode_dps.values(self._device)
-                if not hasattr(ColorMode, effect.upper())
+                if effect and not hasattr(ColorMode, effect.upper())
             ]
             ]
 
 
     @property
     @property
@@ -180,7 +180,7 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
             return self._effect_dps.get_value(self._device)
             return self._effect_dps.get_value(self._device)
         elif self._color_mode_dps:
         elif self._color_mode_dps:
             mode = self._color_mode_dps.get_value(self._device)
             mode = self._color_mode_dps.get_value(self._device)
-            if not hasattr(ColorMode, mode.upper()):
+            if mode and not hasattr(ColorMode, mode.upper()):
                 return mode
                 return mode
 
 
     async def async_turn_on(self, **params):
     async def async_turn_on(self, **params):