rroller / dahua

Dahua Camera and Doorbell Home Assistant Integration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No doorbell events since updating to Home Assistant 2024.5.x

hamid-elaosta opened this issue · comments

I'm no longer receiving any events from my Amcrest AD410, the error log appears to suggest the integration is using a feature it shouldn't, but looking at the commit history, this particular issue was resolved some time ago.

I've removed and re-added the integration several times, even being sure to ensure the custom component is removed from the filesystem on HA.

I'll continue digging because the lack of a functioning doorbell is a big problem for us, but I thought I'd raise it here in the meantime.

Debug log:

2024-05-04 18:45:30.838 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.1.9:80/cgi-bin/configManager.cgi?action=getConfig&name=DisableLinkage
2024-05-04 18:45:32.897 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 2.681 seconds (success: True)
2024-05-04 18:45:51.666 DEBUG (Thread-18) [custom_components.dahua] Event data 192.168.1.9: 'b' \x00\x00\x00DHIP\xf2\x1bjQ\x08\x00\x00\x00\xd5\x00\x00\x00\x00\x00\x00\x00\xd5\x00\x00\x00\x00\x00\x00\x00{"id":8,"method":"client.notifyEventStream","params":{"SID":513,"eventList":[{"Action":"Start","Code":"AlarmLocal","Data":{"LocaleTime":"2024-05-04 18:45:51","UTC":1714848351.0},"Index":0}]},"session":1365908466}\n''
2024-05-04 18:45:51.666 DEBUG (Thread-18) [custom_components.dahua] VTO Data received: {'Action': 'Start', 'Code': 'AlarmLocal', 'Data': {'LocaleTime': '2024-05-04 18:45:51', 'UTC': 1714848351.0}, 'Index': 0, 'deviceType': 'AD410', 'serialNumber': 'Z17ABB22EAB0E', 'DeviceName': 'Doorbell'}
2024-05-04 18:45:51.673 ERROR (Thread-18) [custom_components.dahua] Failed to handle event, error: Detected that custom integration 'dahua' calls async_write_ha_state from a thread at custom_components/dahua/__init__.py, line 399: listener(). Please report it to the author of the 'dahua' custom integration., Line: 125
2024-05-04 18:45:51.673 DEBUG (Thread-18) [custom_components.dahua] Event data 192.168.1.9: 'b' \x00\x00\x00DHIP\xf2\x1bjQ\x08\x00\x00\x00\xe6\x00\x00\x00\x00\x00\x00\x00\xe6\x00\x00\x00\x00\x00\x00\x00{"id":8,"method":"client.notifyEventStream","params":{"SID":513,"eventList":[{"Action":"Start","Code":"CallNoAnswered","Data":{"CallID":"1","LocaleTime":"2024-05-04 18:45:51","UTC":1714848351.0},"Index":0}]},"session":1365908466}\n \x00\x00\x00DHIP\xf2\x1bjQ\x08\x00\x00\x00\xda\x00\x00\x00\x00\x00\x00\x00\xda\x00\x00\x00\x00\x00\x00\x00{"id":8,"method":"client.notifyEventStream","params":{"SID":513,"eventList":[{"Action":"Start","Code":"PhoneCallDetect","Data":{"LocaleTime":"2024-05-04 18:45:51","UTC":1714848351.0},"Index":0}]},"session":1365908466}\n''
2024-05-04 18:45:51.673 DEBUG (Thread-18) [custom_components.dahua] VTO Data received: {'Action': 'Start', 'Code': 'CallNoAnswered', 'Data': {'CallID': '1', 'LocaleTime': '2024-05-04 18:45:51', 'UTC': 1714848351.0}, 'Index': 0, 'deviceType': 'AD410', 'serialNumber': 'Z17ABB22EAB0E', 'DeviceName': 'Doorbell'}
2024-05-04 18:45:51.682 ERROR (Thread-18) [custom_components.dahua] Failed to handle event, error: Detected that custom integration 'dahua' calls async_write_ha_state from a thread at custom_components/dahua/__init__.py, line 399: listener(). Please report it to the author of the 'dahua' custom integration., Line: 125
2024-05-04 18:45:51.682 DEBUG (Thread-18) [custom_components.dahua] VTO Data received: {'Action': 'Start', 'Code': 'PhoneCallDetect', 'Data': {'LocaleTime': '2024-05-04 18:45:51', 'UTC': 1714848351.0}, 'Index': 0, 'deviceType': 'AD410', 'serialNumber': 'Z17ABB22EAB0E', 'DeviceName': 'Doorbell'}
2024-05-04 18:45:51.689 ERROR (Thread-18) [custom_components.dahua] Failed to handle event, error: Detected that custom integration 'dahua' calls async_write_ha_state from a thread at custom_components/dahua/__init__.py, line 399: listener(). Please report it to the author of the 'dahua' custom integration., Line: 125
2024-05-04 18:46:01.671 DEBUG (Thread-18) [custom_components.dahua] Event data 192.168.1.9: 'b' \x00\x00\x00DHIP\xf2\x1bjQ\x08\x00\x00\x00\xd4\x00\x00\x00\x00\x00\x00\x00\xd4\x00\x00\x00\x00\x00\x00\x00{"id":8,"method":"client.notifyEventStream","params":{"SID":513,"eventList":[{"Action":"Stop","Code":"AlarmLocal","Data":{"LocaleTime":"2024-05-04 18:46:01","UTC":1714848361.0},"Index":0}]},"session":1365908466}\n''
2024-05-04 18:46:01.671 DEBUG (Thread-18) [custom_components.dahua] VTO Data received: {'Action': 'Stop', 'Code': 'AlarmLocal', 'Data': {'LocaleTime': '2024-05-04 18:46:01', 'UTC': 1714848361.0}, 'Index': 0, 'deviceType': 'AD410', 'serialNumber': 'Z17ABB22EAB0E', 'DeviceName': 'Doorbell'}
2024-05-04 18:46:01.679 ERROR (Thread-18) [custom_components.dahua] Failed to handle event, error: Detected that custom integration 'dahua' calls async_write_ha_state from a thread at custom_components/dahua/__init__.py, line 402: listener(). Please report it to the author of the 'dahua' custom integration., Line: 125
2024-05-04 18:46:01.683 DEBUG (Thread-18) [custom_components.dahua] Event data 192.168.1.9: 'b' \x00\x00\x00DHIP\xf2\x1bjQ\x08\x00\x00\x00\xd8\x00\x00\x00\x00\x00\x00\x00\xd8\x00\x00\x00\x00\x00\x00\x00{"id":8,"method":"client.notifyEventStream","params":{"SID":513,"eventList":[{"Action":"Stop","Code":"CallNoAnswered","Data":{"LocaleTime":"2024-05-04 18:46:01","UTC":1714848361.0},"Index":0}]},"session":1365908466}\n''
2024-05-04 18:46:01.683 DEBUG (Thread-18) [custom_components.dahua] VTO Data received: {'Action': 'Stop', 'Code': 'CallNoAnswered', 'Data': {'LocaleTime': '2024-05-04 18:46:01', 'UTC': 1714848361.0}, 'Index': 0, 'deviceType': 'AD410', 'serialNumber': 'Z17ABB22EAB0E', 'DeviceName': 'Doorbell'}
2024-05-04 18:46:01.690 ERROR (Thread-18) [custom_components.dahua] Failed to handle event, error: Detected that custom integration 'dahua' calls async_write_ha_state from a thread at custom_components/dahua/__init__.py, line 402: listener(). Please report it to the author of the 'dahua' custom integration., Line: 125
2024-05-04 18:46:04.872 DEBUG (MainThread) [custom_components.dahua] ClientError fetching information from http://192.168.1.9:80/cgi-bin/configManager.cgi?action=getConfig&name=DisableLinkage
2024-05-04 18:46:05.410 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 2.194 seconds (success: True)
2024-05-04 18:46:13.017 DEBUG (Thread-24) [custom_components.dahua] Keep alive
2024-05-04 18:46:13.028 DEBUG (Thread-18) [custom_components.dahua] Event data 192.168.1.9: 'b' \x00\x00\x00DHIP\xf2\x1bjQ\x0e\x00\x00\x00E\x00\x00\x00\x00\x00\x00\x00E\x00\x00\x00\x00\x00\x00\x00{"id":14,"params":{"timeout":55},"result":true,"session":1365908466}\n''

Debug log is taken using main branch, but I was previously using the latest release.

Based on some information I found here: https://community.home-assistant.io/t/how-to-fix-custom-integration-brematic-calls-async-write-ha-state/722238

I made the following change, which is working again:

diff --git a/custom_components/dahua/binary_sensor.py b/custom_components/dahua/binary_sensor.py
index 8120758..455d1ce 100755
--- a/custom_components/dahua/binary_sensor.py
+++ b/custom_components/dahua/binary_sensor.py
@@ -125,7 +125,7 @@ class DahuaEventSensor(DahuaBaseEntity, BinarySensorEntity):
 
     async def async_added_to_hass(self):
         """Connect to dispatcher listening for entity data notifications."""
-        self._coordinator.add_dahua_event_listener(self._event_name, self.async_write_ha_state)
+        self._coordinator.add_dahua_event_listener(self._event_name, self.schedule_update_ha_state)
 
     @property
     def should_poll(self) -> bool:

I'm not familiar with HA integration development, so I'm not sure if this is the correct solution, which is why I haven't opened a PR, but my doorbell is working again now with this change.

Fixed by merging adutchak's PR and released in 0.9.52
https://github.com/rroller/dahua/releases/tag/0.9.52

@rroller Thanks, I can confirm that it is working with the update.

Thanks @adutchak for the PR that fixed it.