Skip to content

Commit

Permalink
Fix timedelta-based sensors for xiaomi_miio (home-assistant#58995)
Browse files Browse the repository at this point in the history
  • Loading branch information
rytilahti authored and balloob committed Nov 5, 2021
1 parent 5e6cac3 commit af28d92
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 @@ -166,16 +166,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 @@ -191,7 +190,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 af28d92

Please sign in to comment.