فهرست منبع

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 ماه پیش
والد
کامیت
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
     @property
     def native_value(self):
     def native_value(self):
         """Return the current value of the time."""
         """Return the current value of the time."""
-        hours = minutes = seconds = 0
+        hours = minutes = seconds = None
         if self._hour_dps:
         if self._hour_dps:
             hours = self._hour_dps.get_value(self._device)
             hours = self._hour_dps.get_value(self._device)
         if self._minute_dps:
         if self._minute_dps:
@@ -67,6 +67,9 @@ class TuyaLocalTime(TuyaLocalEntity, TimeEntity):
             seconds = self._second_dps.get_value(self._device)
             seconds = self._second_dps.get_value(self._device)
         if hours is None and minutes is None and seconds is None:
         if hours is None and minutes is None and seconds is None:
             return None
             return None
+        hours = hours or 0
+        minutes = minutes or 0
+        seconds = seconds or 0
         delta = timedelta(hours=hours, minutes=minutes, seconds=seconds)
         delta = timedelta(hours=hours, minutes=minutes, seconds=seconds)
         return (MIDNIGHT + delta).time()
         return (MIDNIGHT + delta).time()