home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.68k stars 30.43k forks source link

ONVIF: Attempting to update time for Hikvision camera with daylight savings timezone causes `ter:InvalidTimeZone Invalid data` #90820

Closed jarrodsfarrell closed 1 year ago

jarrodsfarrell commented 1 year ago

The problem

Clicking the provided button to update the date and time causes an exception. See provided logs. Screenshot_20230405_021532 Maybe something's up with how HA's sending the date/time that's causing Zeep to panic. Nope turns out it's because of my camera not having daylight savings timezones.

What version of Home Assistant Core has the issue?

core-2023.3.6

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

ONVIF

Link to integration documentation on our website

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

Diagnostics information

config_entry-onvif-c8b47ded00b2935b18071ed09d1c4d5a.json.txt

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Stacktrace from the logs:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 199, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1808, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1845, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 686, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 961, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 726, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/button/__init__.py", line 116, in _async_press_action
    await self.async_press()
  File "/usr/src/homeassistant/homeassistant/components/onvif/button.py", line 54, in async_press
    await self.device.async_manually_set_date_and_time()
  File "/usr/src/homeassistant/homeassistant/components/onvif/device.py", line 179, in async_manually_set_date_and_time
    await device_mgmt.SetSystemDateAndTime(dt_param)
  File "/usr/local/lib/python3.10/site-packages/zeep/proxy.py", line 64, in __call__
    return await self._proxy._binding.send_async(
  File "/usr/local/lib/python3.10/site-packages/zeep/wsdl/bindings/soap.py", line 164, in send_async
    return self.process_reply(client, operation_obj, response)
  File "/usr/local/lib/python3.10/site-packages/zeep/wsdl/bindings/soap.py", line 229, in process_reply
    return self.process_error(doc, operation)
  File "/usr/local/lib/python3.10/site-packages/zeep/wsdl/bindings/soap.py", line 391, in process_error
    raise Fault(
zeep.exceptions.Fault: Invalid data


### Additional information

_No response_
home-assistant[bot] commented 1 year ago

Hey there @hunterjm, mind taking a look at this issue as it has been labeled with an integration (onvif) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `onvif` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign onvif` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


onvif documentation onvif source (message by IssueLinks)

jarrodsfarrell commented 1 year ago

For convenience, the relevant files and lines: https://github.com/home-assistant/core/blob/83704f03342741611d8c2dba20b4ca88309c960a/homeassistant/components/onvif/button.py#L41-L54 https://github.com/home-assistant/core/blob/83704f03342741611d8c2dba20b4ca88309c960a/homeassistant/components/onvif/device.py#L155-L179 Looks like there's a debug logging here. And enabling debug...

2023-04-05 02:22:32.956 DEBUG (MainThread) [homeassistant.components.onvif] System date (UTC): 2023-04-05 06:22:32.956536+00:00
2023-04-05 02:22:32.965 DEBUG (MainThread) [homeassistant.components.onvif] SetSystemDateAndTime: {
    'DateTimeType': 'Manual',
    'DaylightSavings': True,
    'TimeZone': 'EDT',
    'UTCDateTime': {
        'Time': {
            'Hour': 6,
            'Minute': 22,
            'Second': 32
        },
        'Date': {
            'Year': 2023,
            'Month': 4,
            'Day': 5
        }
    }
}
2023-04-05 02:22:32.969 DEBUG (MainThread) [zeep.transports] HTTP Post to http://192.168.254.18:80/onvif/device_service:
b'\nadminC9VJHaOB4O9wAAfslFOpQGFKdQM=dTYipPzOpfnkiECkwvlZfA==2023-04-05T06:22:32+00:00ManualtrueEDT62232202345'
2023-04-05 02:22:33.017 DEBUG (MainThread) [zeep.transports] HTTP Response from http://192.168.254.18:80/onvif/device_service (status: 500):
b'\r\nenv:Sender\r\nter:InvalidArgVal\r\nter:InvalidTimeZone\r\n\r\n\r\n\r\nInvalid data\r\n\r\n\r\n\r\n\r\n'

There's our smoking gun. env:Sender ter:InvalidArgVal ter:InvalidTimeZone Invalid data' Looks like my camera doesn't understand EDT, and I sort-of recall the timezones being jank on these cameras when working with them before.

So I might need a toggle to switch between giving the timezone, supplying a fake one, or just send the time sans timezone.

jarrodsfarrell commented 1 year ago

And the specification: https://github.com/quatanium/python-onvif/blob/09ffc65b8cd9d141b6a386804e7af7028755034e/wsdl/devicemgmt.wsdl#L351-L376 Okay, time is being sent in UTC. If I could instead just send local time and kludge it by saying the camera is now in UTC.

Or run a purposefully misconfigured NTP server.

jarrodsfarrell commented 1 year ago

I went across my cameras and it seems like they do not have an option for a daylight savings timezone; only EST.

Instead it's set as a separate option that has to be configured.

Screenshot_20230406_045815

Unfortunately not only is our cameras EOL, our state will probably permanently change to EDT due to the Sunshine Protection Act.

jarrodsfarrell commented 1 year ago

For anyone else that should come here, I'm using Chrony, a NTP server, that's available to the cameras. Then the cameras are configured to use it to sync and configured the cameras with correct daylight savings settings.

Artekbed commented 1 year ago

For anyone else that should come here, I'm using Chrony, a NTP server, that's available to the cameras. Then the cameras are configured to use it to sync and configured the cameras with correct daylight savings settings.

Hi, How to configure cameras with this Chrony add-on??

jarrodsfarrell commented 1 year ago

@Artekbed I'm using the default configuration for the Chrony addon, though I have the luxury of a VM with a server connected to the Camera network. So I needed to add a bridge for the interface with NetPlan on the host and add another interface to the HA VM with it connected to the new bridge.