Error when Duration Endpoints == 24 Hours
jcgoette opened this issue · comments
Justin Goette commented
Interesting issue when working on #46. Occurs when duration of tummy time (and presumably other duration field endpoints) == 24 hours (the BB maximum value).
2021-11-07 18:03:30 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/home/jcgoette/core/homeassistant/helpers/config_validation.py", line 400, in time_period_str
hour = int(parsed[0])
ValueError: invalid literal for int() with base 10: '1 00'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/jcgoette/core/homeassistant/helpers/update_coordinator.py", line 134, in _handle_refresh_interval
await self._async_refresh(log_failures=True, scheduled=True)
File "/home/jcgoette/core/homeassistant/helpers/update_coordinator.py", line 265, in _async_refresh
update_callback()
File "/home/jcgoette/core/homeassistant/helpers/update_coordinator.py", line 325, in _handle_coordinator_update
self.async_write_ha_state()
File "/home/jcgoette/core/homeassistant/helpers/entity.py", line 480, in async_write_ha_state
self._async_write_ha_state()
File "/home/jcgoette/core/homeassistant/helpers/entity.py", line 513, in _async_write_ha_state
state = self._stringify_state()
File "/home/jcgoette/core/homeassistant/helpers/entity.py", line 486, in _stringify_state
if (state := self.state) is None:
File "/home/jcgoette/core/homeassistant/components/sensor/__init__.py", line 273, in state
value = self.native_value
File "/home/jcgoette/core/config/custom_components/babybuddy/sensor.py", line 340, in native_value
return self.entity_description.state_key(data)
File "/home/jcgoette/core/config/custom_components/babybuddy/const.py", line 122, in <lambda>
time_period_str(value[ATTR_DURATION]).total_seconds() / 60
File "/home/jcgoette/core/homeassistant/helpers/config_validation.py", line 407, in time_period_str
raise vol.Invalid(TIME_PERIOD_ERROR.format(value)) from err
voluptuous.error.Invalid: offset 1 00:00:00 should be format 'HH:MM', 'HH:MM:SS' or 'HH:MM:SS.F'
Not sure yet if should work on homeassistant/helpers/config_validation.py
, account for in BB, or account for in baby_buddy_homeassistant.
Justin Goette commented
See home-assistant/core#73693. Can handle locally if not approved.
Justin Goette commented
Based on discussion in HA PR, quick and easy solution here is to switch to dt_util.parse_duration
.
Justin Goette commented
Closed by be5e0d9.