Skip to content

Commit

Permalink
Fix timedelta-based sensors for xiaomi_miio (#58995)
Browse files Browse the repository at this point in the history
  • Loading branch information
rytilahti authored Nov 3, 2021
1 parent 1af621e commit 96c03ae
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions homeassistant/components/xiaomi_miio/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,15 @@ def _extract_value_from_attribute(cls, state, attribute):
return cls._parse_datetime_time(value)
if isinstance(value, datetime.datetime):
return cls._parse_datetime_datetime(value)
if isinstance(value, datetime.timedelta):
return cls._parse_time_delta(value)

if value is None:
_LOGGER.debug("Attribute %s is None, this is unexpected", attribute)

return value

@staticmethod
def _parse_time_delta(timedelta: datetime.timedelta) -> int:
return timedelta.seconds
return int(timedelta.total_seconds())

@staticmethod
def _parse_datetime_time(time: datetime.time) -> str:
Expand All @@ -192,7 +191,3 @@ def _parse_datetime_time(time: datetime.time) -> str:
@staticmethod
def _parse_datetime_datetime(time: datetime.datetime) -> str:
return time.isoformat()

@staticmethod
def _parse_datetime_timedelta(time: datetime.timedelta) -> int:
return time.seconds

0 comments on commit 96c03ae

Please sign in to comment.