rroller / dahua

Dahua Camera and Doorbell Home Assistant Integration
MIT License
398 stars 80 forks source link

Core 2022.7 breaks intgration. Cannot log in after update. #203

Open Mikefila opened 2 years ago

Mikefila commented 2 years ago

Version of the custom_component

0.9.40

Configuration

configured through UI

Describe the bug

All cameras on integration page show "Retrying setup: Dahua device at 192.168.0.108 isn't fully initialized yet"

All cameras worked prior to update to 2022.7 and works if I roll back to core 2022.6.7

Dahua XVR A72A3A

Debug log

This error originated from a custom integration.

Logger: custom_components.dahua
Source: custom_components/dahua/__init__.py:270
Integration: Dahua (documentation, issues)
First occurred: 2:51:55 PM (40 occurrences)
Last logged: 2:53:19 PM

Unexpected error fetching dahua data: Dahua device at 192.168.0.108 isn't fully initialized yet
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 986, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1089, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1119, in _create_connection_transport
    await waiter
  File "/usr/local/lib/python3.10/asyncio/sslproto.py", line 534, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "/usr/local/lib/python3.10/asyncio/sslproto.py", line 188, in feed_ssldata
    self._sslobj.do_handshake()
  File "/usr/local/lib/python3.10/ssl.py", line 975, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:997)

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

Traceback (most recent call last):
  File "/config/custom_components/dahua/__init__.py", line 182, in _async_update_data
    self._max_streams = await self.client.get_max_extra_streams() + 1
  File "/config/custom_components/dahua/client.py", line 141, in get_max_extra_streams
    result = await self.get("/cgi-bin/magicBox.cgi?action=getProductDefinition&name=MaxExtraStream")
  File "/config/custom_components/dahua/client.py", line 755, in get
    raise exception
  File "/config/custom_components/dahua/client.py", line 737, in get
    response = await auth.request("GET", url)
  File "/config/custom_components/dahua/digest.py", line 46, in request
    response = await self.session.request(method, url, headers=headers, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 535, in _request
    conn = await self._connector.connect(
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 542, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 907, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1206, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1175, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 990, in _wrap_create_connection
    raise ClientConnectorSSLError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorSSLError: Cannot connect to host 192.168.0.108:443 ssl:default [[SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:997)]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 205, in _async_refresh
    self.data = await self._async_update_data()
  File "/config/custom_components/dahua/__init__.py", line 270, in _async_update_data
    raise PlatformNotReady("Dahua device at " + self._address + " isn't fully initialized yet")
homeassistant.exceptions.PlatformNotReady: Dahua device at 192.168.0.108 isn't fully initialized yet
This error originated from a custom integration.

Logger: custom_components.dahua
Source: custom_components/dahua/digest.py:46
Integration: Dahua (documentation, issues)
First occurred: 2:51:55 PM (40 occurrences)
Last logged: 2:53:19 PM

Failed to initialize device at 192.168.0.108
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 986, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1089, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1119, in _create_connection_transport
    await waiter
  File "/usr/local/lib/python3.10/asyncio/sslproto.py", line 534, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "/usr/local/lib/python3.10/asyncio/sslproto.py", line 188, in feed_ssldata
    self._sslobj.do_handshake()
  File "/usr/local/lib/python3.10/ssl.py", line 975, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:997)

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

Traceback (most recent call last):
  File "/config/custom_components/dahua/__init__.py", line 182, in _async_update_data
    self._max_streams = await self.client.get_max_extra_streams() + 1
  File "/config/custom_components/dahua/client.py", line 141, in get_max_extra_streams
    result = await self.get("/cgi-bin/magicBox.cgi?action=getProductDefinition&name=MaxExtraStream")
  File "/config/custom_components/dahua/client.py", line 755, in get
    raise exception
  File "/config/custom_components/dahua/client.py", line 737, in get
    response = await auth.request("GET", url)
  File "/config/custom_components/dahua/digest.py", line 46, in request
    response = await self.session.request(method, url, headers=headers, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 535, in _request
    conn = await self._connector.connect(
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 542, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 907, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1206, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1175, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 990, in _wrap_create_connection
    raise ClientConnectorSSLError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorSSLError: Cannot connect to host 192.168.0.108:443 ssl:default [[SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:997)]
lino-silva commented 2 years ago

Same error for me.

dracon80 commented 2 years ago

Same for me as well

rroller commented 2 years ago

Sorry guys been very busy. I'll try to look at this asap.

JimGermany commented 2 years ago

Great - Thanks! :-)

jjscarafia commented 2 years ago

If it helps, this seems to be a similar fix on sonof integration https://github.com/AlexxIT/SonoffLAN/commit/381fd0dd02fc10a02f5344c989e6197411e11169

JimGermany commented 2 years ago

I haven't installed version 2022.7.x yet. Now I have installed the version 2022.7.6 on my test system (Oracle VM) and I don't get any errors? No isn't fully initialized yet error.

All of my four Dahua cameras seem to be working fine. Now I'm confused. :-)

HolmHomeAssistant commented 2 years ago

Is it maybe because 2022.7 ships with Python 3.10 which behaves differently?

jdvorecky commented 2 years ago

Hi guys, any word from rroller about the fix of the Dahua integration? i reset my NVR, redrew all new Intrusion and tripwire lines and still cant get it to communicate with HA. i uninstalled the previous Dahua integration, reincluded the cameras again and now they wont even show a feed or any activity. just shows that the cam became unavailable for some time. But no motion detection or the Crossline or cross region detection is available :( any ideas where the bug can be??? help pleaseeee.

Home Assistant 2022.8.0 Supervisor 2022.07.0 Operating System 8.4 Frontend 20220802.0 - latest

MosheTzvi commented 2 years ago

@rroller any update?

rroller commented 2 years ago

I should have time to work on this next week

idekker commented 2 years ago

Created pull request #213 to patch the issue.

rroller commented 2 years ago

@idekker thanks! Merged and released in https://github.com/rroller/dahua/releases/tag/0.9.41

jjscarafia commented 2 years ago

thanks @rroller and @idekker working now!

Nortonko commented 2 years ago

Hi, is this solved? I have still problem login to my Dahua VTO 2211G. Debug:

Logger: custom_components.dahua
Source: custom_components/dahua/digest.py:46
Integration: Dahua (documentation, issues)
First occurred: 18:19:52 (1 occurrences)
Last logged: 18:19:52

Could not connect to Dahua device. For iMou devices see https://github.com/rroller/dahua/issues/6
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 986, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1089, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1119, in _create_connection_transport
    await waiter
  File "/usr/local/lib/python3.10/asyncio/sslproto.py", line 534, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "/usr/local/lib/python3.10/asyncio/sslproto.py", line 188, in feed_ssldata
    self._sslobj.do_handshake()
  File "/usr/local/lib/python3.10/ssl.py", line 975, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:997)

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

Traceback (most recent call last):
  File "/config/custom_components/dahua/config_flow.py", line 179, in _test_credentials
    data = await client.get_machine_name()
  File "/config/custom_components/dahua/client.py", line 121, in get_machine_name
    return await self.get("/cgi-bin/magicBox.cgi?action=getMachineName")
  File "/config/custom_components/dahua/client.py", line 755, in get
    raise exception
  File "/config/custom_components/dahua/client.py", line 737, in get
    response = await auth.request("GET", url)
  File "/config/custom_components/dahua/digest.py", line 46, in request
    response = await self.session.request(method, url, headers=headers, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 535, in _request
    conn = await self._connector.connect(
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 542, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 907, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1206, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1175, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 990, in _wrap_create_connection
    raise ClientConnectorSSLError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorSSLError: Cannot connect to host 172.23.23.40:443 ssl:default [[SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:997)]
Home Assistant 2022.8.7
Supervisor 2022.08.5
Operating System 8.5
Version of the custom_component
0.9.43
idekker commented 2 years ago

@Nortonko It seems I only fixed it for 1 of the 2 locations. Created another pull request #218 to patch the 2nd location

Nortonko commented 2 years ago

@idekker I manually edited the file "config_flow.py" according to your PR. It works fine now. Thanks.