Procházet zdrojové kódy

Unixtime should not need a mapping to convert to datetime

Previously HA also accepted unix timestamps for timestamp class
sensors, so this went unnoticed. But now it blindly tries to get the
timezone, which causes an error if the sensor is reporting an integer
value rather than a DateTime object.

Discussion #2080
Jason Rumney před 1 rokem
rodič
revize
4e25f86383
1 změnil soubory, kde provedl 14 přidání a 14 odebrání
  1. 14 14
      custom_components/tuya_local/helpers/device_config.py

+ 14 - 14
custom_components/tuya_local/helpers/device_config.py

@@ -716,21 +716,21 @@ class TuyaDpsConfig:
                 result = result / scale
                 result = result / scale
                 replaced = True
                 replaced = True
 
 
-            if self.rawtype == "unixtime" and isinstance(result, int):
-                try:
-                    result = datetime.fromtimestamp(result)
-                    replaced = True
-                except Exception:
-                    _LOGGER.warning("Invalid timestamp %d", result)
+        if self.rawtype == "unixtime" and isinstance(result, int):
+            try:
+                result = datetime.fromtimestamp(result)
+                replaced = True
+            except Exception:
+                _LOGGER.warning("Invalid timestamp %d", result)
 
 
-            if replaced:
-                _LOGGER.debug(
-                    "%s: Mapped dps %s value from %s to %s",
-                    self._entity._device.name,
-                    self.id,
-                    val,
-                    result,
-                )
+        if replaced:
+            _LOGGER.debug(
+                "%s: Mapped dps %s value from %s to %s",
+                self._entity._device.name,
+                self.id,
+                val,
+                result,
+            )
 
 
         return result
         return result