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

fix(time): timedelta does not like None arguments

When the device is not sending optional dps, components can be set to None
The last change attempted to detect this condition and return None rather
than trying to construct a timedelta, but since we initialise the unused
components to 0, the detection failed. It could also fail if there are two
components of time and only one is missing, so change the logic to cover all
cases.

Discussion #3588
Jason Rumney 6 месяцев назад
Родитель
Сommit
96fc98daf6
1 измененных файлов с 4 добавлено и 1 удалено
  1. 4 1
      custom_components/tuya_local/time.py

+ 4 - 1
custom_components/tuya_local/time.py

@@ -58,7 +58,7 @@ class TuyaLocalTime(TuyaLocalEntity, TimeEntity):
     @property
     def native_value(self):
         """Return the current value of the time."""
-        hours = minutes = seconds = 0
+        hours = minutes = seconds = None
         if self._hour_dps:
             hours = self._hour_dps.get_value(self._device)
         if self._minute_dps:
@@ -67,6 +67,9 @@ class TuyaLocalTime(TuyaLocalEntity, TimeEntity):
             seconds = self._second_dps.get_value(self._device)
         if hours is None and minutes is None and seconds is None:
             return None
+        hours = hours or 0
+        minutes = minutes or 0
+        seconds = seconds or 0
         delta = timedelta(hours=hours, minutes=minutes, seconds=seconds)
         return (MIDNIGHT + delta).time()