core: ONVIF - Error while setting up onvif platform for sensor

The problem

Since 2022.5 I have the following error in the log:

2022-05-07 11:11:36 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up onvif platform for sensor … OverflowError: date value out of range

Full log added bellow

What version of Home Assistant Core has the issue?

2022.5.2

What was the last working version of Home Assistant Core?

2022.4.7

What type of installation are you running?

Home Assistant Core

Integration causing the issue

ONVIF

Link to integration documentation on our website

https://www.home-assistant.io/integrations/onvif/

Diagnostics information

config_entry-onvif-085f38e906b9225573ecca8c158bab89.json.txt config_entry-onvif-ce22534bce7366073ccc582b7ec71b9e.json.txt config_entry-onvif-da8a20160be5853bdd02aa028dda216d.json.txt

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2022-05-07 11:11:36 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up onvif platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 257, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 619, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 810, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 533, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 571, in _async_write_ha_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 539, in _stringify_state
    if (state := self.state) is None:
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 404, in state
    value = value.astimezone(timezone.utc)
OverflowError: date value out of range

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Please help by verifying the change in #73600

Did you manage to do it?

I am running 2022.5.5 docker container without any issues, by removing the two lines. Unfortunately I have no clue:

  1. What’s the main reason for these two lines
  2. How to add this as a solution on Github

I can imagine that something like this would repair it more ‘clean’:

if value.tzinfo != timezone.utc:
   try:
      value = value.astimezone(timezone.utc)
   except OverflowError:
      pass