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.72k stars 30.45k forks source link

Adding an ONVIF camera #70838

Closed dredwater closed 2 years ago

dredwater commented 2 years ago

The problem

Adding an ONVIF camera complete successfully via the integration, but then reports "failed to setup" in ONVIF integration image

What version of Home Assistant Core has the issue?

core-2022.4.5

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

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: aiohttp.server
Source: custom_components/onvif/zeeep/transports.py:215
Integration: ONVIF
First occurred: 9:35:56 PM (4 occurrences)
Last logged: 9:36:16 PM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
    yield
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 208, in handle_async_request
    raise UnsupportedProtocol(
httpcore.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 219, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 137, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 206, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 62, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 260, in async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 335, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/config/custom_components/onvif/config_flow.py", line 170, in async_step_auth
    return await self.async_step_profiles()
  File "/config/custom_components/onvif/config_flow.py", line 203, in async_step_profiles
    await device.update_xaddrs()
  File "/config/custom_components/onvif/onwif/client.py", line 276, in update_xaddrs
    capabilities = await devicemgmt.GetCapabilities({"Category": "All"})
  File "/config/custom_components/onvif/zeeep/proxy.py", line 64, in __call__
    return await self._proxy._binding.send_async(
  File "/config/custom_components/onvif/zeeep/wsdl/bindings/soap.py", line 156, in send_async
    response = await client.transport.post_xml(
  File "/config/custom_components/onvif/zeeep/transports.py", line 230, in post_xml
    response = await self.post(address, message, headers)
  File "/config/custom_components/onvif/zeeep/transports.py", line 215, in post
    response = await self.client.post(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1820, in post
    return await self.request(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1506, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1593, in send
    response = await self._send_handling_auth(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1621, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1658, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1695, in _send_single_request
    response = await transport.handle_async_request(request)
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "/usr/local/lib/python3.9/contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

Additional information

No response

probot-home-assistant[bot] commented 2 years ago

onvif documentation onvif source (message by IssueLinks)

probot-home-assistant[bot] commented 2 years 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! (message by CodeOwnersMention)

hunterjm commented 2 years ago

The logs you sent show that ONVIF is being loaded from a custom component and not the official integration: /config/custom_components/onvif/config_flow.py

Do you get the same error if you delete the folder out of custom components and restart? From the error, it looks like your camera is not returning a valid URL when we make the XAddrs request so it fails when we try to retrieve its capabilities. This is likely due to the camera not being truly ONVIF compliant.

dredwater commented 2 years ago

Thanks for your quick reply @hunterjm

I have several ONVIF cameras. Not sure if the changes you asked will create an issue with the existing one, Would you happen to know?

Also, not sure if this help, but using ONVIF Device Manager, I have no issue with the camera. It shows ONVIF version 20.06. Here are the settings:

image

Here is an additional log: This error originated from a custom integration.

Logger: homeassistant.config_entries Source: custom_components/onvif/zeeep/wsdl/messages/soap.py:439 Integration: ONVIF First occurred: April 26, 2022, 9:36:57 PM (1 occurrences) Last logged: April 26, 2022, 9:36:57 PM

Error setting up entry CA2 - 68:76:27:2B:D4:0B for onvif Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 335, in async_setup result = await component.async_setup_entry(hass, self) File "/config/custom_components/onvif/init.py", line 80, in async_setup_entry if not await device.async_setup(): File "/config/custom_components/onvif/device.py", line 106, in async_setup self.profiles = await self.async_get_profiles() File "/config/custom_components/onvif/device.py", line 308, in async_get_profiles presets = await ptz_service.GetPresets(profile.token) File "/config/custom_components/onvif/zeeep/proxy.py", line 64, in call return await self._proxy._binding.send_async( File "/config/custom_components/onvif/zeeep/wsdl/bindings/soap.py", line 164, in send_async return self.process_reply(client, operation_obj, response) File "/config/custom_components/onvif/zeeep/wsdl/bindings/soap.py", line 231, in process_reply result = operation.process_reply(doc) File "/config/custom_components/onvif/zeeep/wsdl/bindings/soap.py", line 430, in process_reply return self.output.deserialize(envelope) File "/config/custom_components/onvif/zeeep/wsdl/messages/soap.py", line 101, in deserialize body_result = self._deserialize_body(body) File "/config/custom_components/onvif/zeeep/wsdl/messages/soap.py", line 439, in _deserialize_body xmlelement = list(xmlelement)[0] IndexError: list index out of range

LMK what else I can provide (Need Step by step) to help.

dredwater commented 2 years ago

Furthermore, in using AgentDVR (for testing to discover the URLs associated with the camera IP), when I do a discovery, Connections list comeback with ~100 URLs (Don't know the exact numbers, but it is a couple page down as shown here) only 2 of 'Type' ONVIF, 1 of "MJPEG" and the rest are all "IP Camera"

image
dredwater commented 2 years ago

Not fixed, returned the camera.