vinteo/hass-opensprinkler

Error adding entities for domain time with platform opensprinkler when using sunrise/sunset offsets

Closed this issue · 3 comments

aav7fl commented

If my water programs use sunrise/sunset offsets like in the screenshot below, the hass-opensprinkler component is unable to create program sensors. This blocks my integration from loading and working.

image

with this log error:

2023-09-22 23:06:33.006 ERROR (MainThread) [homeassistant.components.time] Error adding entities for domain time with platform opensprinkler
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 507, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 752, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1002, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 730, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 830, in _async_write_ha_state
state, attr = self._async_generate_attributes()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 771, in _async_generate_attributes
state = self._stringify_state(available)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 736, in _stringify_state
if (state := self.state) is None:
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/time/__init__.py", line 94, in state
if self.native_value is None:
^^^^^^^^^^^^^^^^^
File "/config/custom_components/opensprinkler/time.py", line 72, in native_value
the_time = datetime.time(round(minutes / 60), minutes % 60, 0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: hour must be in 0..23

Calling out this line: https://github.com/vinteo/hass-opensprinkler/blob/master/custom_components/opensprinkler/time.py#L72

Currently running:

  • OpenSprinkler Firmware: 2.2.0 (1)
  • hass-opensprinkler v1.2.1
  • Home Assistant 2023.9.1

I'm guessing the value returned by OpenSprinkler isn't compatible with whatever time operation is being run there.

If I switch my programs to a precise time, this error in Home Assistant goes away, allowing the integration to run.

Thanks for reporting this. See PR #253 for possible fix.

aav7fl commented

Thanks for reporting this. See PR #253 for possible fix.

Thanks! That should help alleviate problems until full support is added like you mentioned.

Release v1.2.2 should fix this Issue. Please let me know if you find any further issues.