Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetSystemDateAndTime #138579

Closed
dkuzmenko-dsr opened this issue Feb 15, 2025 · 12 comments · Fixed by #138916
Closed

GetSystemDateAndTime #138579

dkuzmenko-dsr opened this issue Feb 15, 2025 · 12 comments · Fixed by #138916
Assignees

Comments

@dkuzmenko-dsr
Copy link

The problem

I'm trying to add my Kojima Onvif camera. It works fine with python Onvif GUI application. But it looks the cam does not implement required because Onvif integration says the following:

Could not connect to camera: Method 'ns0:GetSystemDateAndTime' not implemented: method name or namespace not recognized (code:SOAP-ENV:Sender) (subcodes:)

I understand that the problem is highly likely is on the camera side but since Onvf GUI is able to connect and control the camera, maybe Onvif integration could do it as well by just ignoring system datetime setup step?

What version of Home Assistant Core has the issue?

core-2025.2.2

What was the last working version of Home Assistant Core?

No response

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

home-assistant_onvif_2025-02-15T07-01-01.103Z.log

Example YAML snippet

Anything in the logs that might be useful for us?

2025-02-15 10:00:54.645 DEBUG (MainThread) [zeep.transports] HTTP Response from http://192.168.1.51:5000/onvif/device_service (status: 400):
b'<?xml version="1.0" encoding="UTF-8"?>\n<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:ter="http://www.onvif.org/ver10/error" xmlns:xs="http://www.w3.org/2000/10/XMLSchema"><SOAP-ENV:Body><SOAP-ENV:Fault><SOAP-ENV:Code><SOAP-ENV:Value>SOAP-ENV:Sender</SOAP-ENV:Value></SOAP-ENV:Code><SOAP-ENV:Reason><SOAP-ENV:Text xml:lang="en">Method &apos;ns0:GetSystemDateAndTime&apos; not implemented: method name or namespace not recognized</SOAP-ENV:Text></SOAP-ENV:Reason></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>\r\n'

Additional information

My setup is pretty straightforward. Adding Onvif integration I'm passing the following parameters:
Name: Camera
Host:
Port: 5000
Username: admin
Password:

This configuration works with the mentioned onvif-gui

@home-assistant
Copy link

Hey there @hunterjm, @jterrace, 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.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


onvif documentation
onvif source
(message by IssueLinks)

@jterrace
Copy link
Contributor

@bdraco this looks like it might be another instance of the fix I made in openvideolibs/python-onvif-zeep-async#54 - we are sending this:

<ns0:GetSystemDateAndTime xmlns:ns0="http://www.onvif.org/ver10/device/wsdl"/>

and I suspect the camera might not understand the inline namespace.

@dkuzmenko-dsr not sure what your ha installation looks like, but if you have the ability to edit the code to do a quick test, it would be a single line here:
https://github.com/openvideolibs/python-onvif-zeep-async/blob/async/onvif/client.py#L160

adding:

self.set_ns_prefix("tds", "http://www.onvif.org/ver10/device/wsdl")

@dkuzmenko-dsr
Copy link
Author

@jterrace thank you for the idea.

I've tried that.

My hass is installed as a system-wide AUR package. Hass is working in python venv. So it's easy enough to do the test.

I've updated the /var/lib/private/hass/.venv/lib/python3.13/site-packages/onvif/client.py file as the following:

diff --git a/onvif/client.py b/onvif/client.py
index 5f4f7b3..79e2432 100644
--- a/onvif/client.py
+++ b/onvif/client.py
@@ -158,6 +158,7 @@ class ZeepAsyncClient(BaseZeepAsyncClient):
 
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
+        self.set_ns_prefix("tds", "http://www.onvif.org/ver10/device/wsdl")
         self.set_ns_prefix("wsnt", "http://docs.oasis-open.org/wsn/b-2")
         self.set_ns_prefix("wsa", "http://www.w3.org/2005/08/addressing")

After that I've restarted hass and re-added the camera integration. Unfortunately result is the same:

Could not connect to camera: Method 'tds:GetSystemDateAndTime' not implemented: method name or namespace not recognized (code:SOAP-ENV:Sender) (subcodes:)

@jterrace
Copy link
Contributor

Thanks for checking.

Looking closer, I'm actually a little confused because all of the call sites in https://github.com/home-assistant/core/blob/e767863ea4229ca53d23f0378ad2e29aa153ba37/homeassistant/components/onvif/device.py that call GetSystemDateAndTime check for exceptions and continue. Is the setup not continuing for you? Is there anything else in your log after the 400 error?

@dkuzmenko-dsr
Copy link
Author

You're right. There is nothing.
Agree this looks weird. Let play around logging.

@dkuzmenko-dsr
Copy link
Author

I've tried to change the except block:
https://github.com/home-assistant/core/blob/e767863ea4229ca53d23f0378ad2e29aa153ba37/homeassistant/components/onvif/device.py#L236C1-L242C1

To catch any exception and log it:

        except Exception as err:
            LOGGER.debug("%s: CHECKPOINT 300: Error: %s", self.name, type(err))
            LOGGER.warning(
                "Couldn't get device '%s' date/time. Error: %s", self.name, err
            )
            return

Here's the result:

2025-02-17 11:37:39.325 DEBUG (MainThread) [homeassistant.components.onvif] Onvif Camera: CHECKPOINT 300: Error: <class 'zeep.exceptions.Fault'>
2025-02-17 11:37:39.325 WARNING (MainThread) [homeassistant.components.onvif] Couldn't get device 'Onvif Camera' date/time. Error: Method 'tds:GetSystemDateAndTime' not implemented: method name or namespace not recognized

As a result camera has been added with 4 objects:

  • Onvif Camera profile_0 | camera.onvif_camera_profile_0
  • Onvif Camera profile_1 | camera.onvif_camera_profile_1
  • Onvif Camera Reboot | button.onvif_camera_reboot
  • Onvif Camera Set System Date and Time | button.onvif_camera_set_system_date_and_time

@jterrace
Copy link
Contributor

Thanks, so you're right, the issue is here:

except RequestError as err:

Only the RequestError exception is caught while in other places like here:

except (RequestError, TransportError, IndexError, Fault):

additional exceptions are caught (TransportError, IndexError, Fault)

@bdraco
Copy link
Member

bdraco commented Feb 17, 2025

Thanks, so you're right, the issue is here:

core/homeassistant/components/onvif/device.py

Line 238 in e767863

except RequestError as err:
Only the RequestError exception is caught while in other places like here:

core/homeassistant/components/onvif/device.py

Line 306 in e767863

except (RequestError, TransportError, IndexError, Fault):
additional exceptions are caught (TransportError, IndexError, Fault)

If we want to expand the exception caught in more places, we can make the tuple a constant and change it out where needed so we don't have to keep writing it out.

@jterrace
Copy link
Contributor

If we want to expand the exception caught in more places, we can make the tuple a constant and change it out where needed so we don't have to keep writing it out.

zeep has a base Error that all the others inherit from. I was thinking let's just change to the base one unless you'd prefer not to?

@bdraco
Copy link
Member

bdraco commented Feb 17, 2025

If we want to expand the exception caught in more places, we can make the tuple a constant and change it out where needed so we don't have to keep writing it out.

zeep has a base Error that all the others inherit from. I was thinking let's just change to the base one unless you'd prefer not to?

I'd only include the ones we know are issues so we should keep the exception catch as narrow as possible so we don't hide bugs.

@DmitryKuzmenko
Copy link
Contributor

@jterrace @bdraco I've created a PR for this. Please let me know if I have to do anything more to get it done.

@DmitryKuzmenko
Copy link
Contributor

DmitryKuzmenko commented Feb 21, 2025

Wow! That was extremely fast!
Thanks guys for help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants