Skip to content

Commit 0f4b49d

Browse files
authored
Attempt to fix #414 (#419)
1 parent fb69efa commit 0f4b49d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

custom_components/dahua/__init__.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def __init__(self, hass: HomeAssistant, events: list, address: str, port: int, r
120120
self.events: list = events
121121
self._supports_coaxial_control = False
122122
self._supports_disarming_linkage = False
123+
self._supports_event_notifications = False
123124
self._supports_smart_motion_detection = False
124125
self._supports_lighting = False
125126
self._supports_floodlightmode = False
@@ -247,6 +248,13 @@ async def _async_update_data(self):
247248
self._supports_disarming_linkage = False
248249
_LOGGER.info("Device supports disarming linkage=%s", self._supports_disarming_linkage)
249250

251+
try:
252+
await self.client.async_get_event_notifications()
253+
self._supports_event_notifications = True
254+
except ClientError:
255+
self._supports_event_notifications = False
256+
_LOGGER.info("Device supports event notifications=%s", self._supports_event_notifications)
257+
250258
# Smart motion detection is enabled/disabled/fetched differently on Dahua devices compared to Amcrest
251259
# The following lines are for Dahua devices
252260
try:
@@ -261,7 +269,7 @@ async def _async_update_data(self):
261269

262270
is_flood_light = self.is_flood_light()
263271
_LOGGER.info("Device is a floodlight=%s", is_flood_light)
264-
272+
265273
self._supports_floodlightmode = self.supports_floodlightmode()
266274

267275
try:
@@ -320,6 +328,7 @@ async def _async_update_data(self):
320328
asyncio.ensure_future(self.client.async_get_config_lighting(self._channel, self._profile_mode)))
321329
if self._supports_disarming_linkage:
322330
coros.append(asyncio.ensure_future(self.client.async_get_disarming_linkage()))
331+
if self._supports_event_notifications:
323332
coros.append(asyncio.ensure_future(self.client.async_get_event_notifications()))
324333
if self._supports_coaxial_control:
325334
coros.append(asyncio.ensure_future(self.client.async_get_coaxial_control_io_status()))
@@ -546,7 +555,7 @@ def is_doorbell(self) -> bool:
546555
""" Returns true if this is a doorbell (VTO) """
547556
m = self.model.upper()
548557
return m.startswith("VTO") or m.startswith("DH-VTO") or (
549-
"NVR" not in m and m.startswith("DHI")) or self.is_amcrest_doorbell() or self.is_empiretech_doorbell() or self.is_avaloidgoliath_doorbell()
558+
"NVR" not in m and m.startswith("DHI")) or self.is_amcrest_doorbell() or self.is_empiretech_doorbell() or self.is_avaloidgoliath_doorbell()
550559

551560
def is_amcrest_doorbell(self) -> bool:
552561
""" Returns true if this is an Amcrest doorbell """
@@ -584,7 +593,7 @@ def supports_illuminator(self) -> bool:
584593
IPC-HDW3849HP-AS-PV does
585594
"""
586595
return not (
587-
self.is_amcrest_doorbell() or self.is_flood_light()) and "table.Lighting_V2[{0}][0][0].Mode".format(
596+
self.is_amcrest_doorbell() or self.is_flood_light()) and "table.Lighting_V2[{0}][0][0].Mode".format(
588597
self._channel) in self.data
589598

590599
def is_motion_detection_enabled(self) -> bool:
@@ -660,7 +669,7 @@ def is_illuminator_on(self) -> bool:
660669
def is_flood_light_on(self) -> bool:
661670

662671
if self._supports_floodlightmode:
663-
#'coaxialControlIO.cgi?action=getStatus&channel=1'
672+
# 'coaxialControlIO.cgi?action=getStatus&channel=1'
664673
return self.data.get("status.status.WhiteLight", "") == "On"
665674
else:
666675
"""Return true if the amcrest flood light light is on"""

0 commit comments

Comments
 (0)