Skip to content

Commit

Permalink
Unixtime should not need a mapping to convert to datetime
Browse files Browse the repository at this point in the history
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
  • Loading branch information
make-all committed Jul 7, 2024
1 parent 7b72eaa commit 4e25f86
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions custom_components/tuya_local/helpers/device_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,21 +716,21 @@ def _map_from_dps(self, val, device):
result = result / scale
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

Expand Down

0 comments on commit 4e25f86

Please sign in to comment.