Skip to content

Commit

Permalink
Attempt to fix #414
Browse files Browse the repository at this point in the history
  • Loading branch information
brianegge committed Nov 10, 2024
1 parent 21a2732 commit 0876599
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions custom_components/dahua/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def __init__(self, hass: HomeAssistant, events: list, address: str, port: int, r
self.events: list = events
self._supports_coaxial_control = False
self._supports_disarming_linkage = False
self._supports_event_notifications = False
self._supports_smart_motion_detection = False
self._supports_lighting = False
self._supports_floodlightmode = False
Expand Down Expand Up @@ -247,6 +248,13 @@ async def _async_update_data(self):
self._supports_disarming_linkage = False
_LOGGER.info("Device supports disarming linkage=%s", self._supports_disarming_linkage)

try:
await self.client.async_get_event_notifications()
self._supports_event_notifications = True
except ClientError:
self._supports_event_notifications = False
_LOGGER.info("Device supports event notifications=%s", self._supports_event_notifications)

# Smart motion detection is enabled/disabled/fetched differently on Dahua devices compared to Amcrest
# The following lines are for Dahua devices
try:
Expand All @@ -261,7 +269,7 @@ async def _async_update_data(self):

is_flood_light = self.is_flood_light()
_LOGGER.info("Device is a floodlight=%s", is_flood_light)

self._supports_floodlightmode = self.supports_floodlightmode()

try:
Expand Down Expand Up @@ -320,6 +328,7 @@ async def _async_update_data(self):
asyncio.ensure_future(self.client.async_get_config_lighting(self._channel, self._profile_mode)))
if self._supports_disarming_linkage:
coros.append(asyncio.ensure_future(self.client.async_get_disarming_linkage()))
if self._supports_event_notifications:
coros.append(asyncio.ensure_future(self.client.async_get_event_notifications()))
if self._supports_coaxial_control:
coros.append(asyncio.ensure_future(self.client.async_get_coaxial_control_io_status()))
Expand Down Expand Up @@ -545,7 +554,7 @@ def is_doorbell(self) -> bool:
""" Returns true if this is a doorbell (VTO) """
m = self.model.upper()
return m.startswith("VTO") or m.startswith("DH-VTO") or (
"NVR" not in m and m.startswith("DHI")) or self.is_amcrest_doorbell() or self.is_empiretech_doorbell() or self.is_avaloidgoliath_doorbell()
"NVR" not in m and m.startswith("DHI")) or self.is_amcrest_doorbell() or self.is_empiretech_doorbell() or self.is_avaloidgoliath_doorbell()

def is_amcrest_doorbell(self) -> bool:
""" Returns true if this is an Amcrest doorbell """
Expand Down Expand Up @@ -583,7 +592,7 @@ def supports_illuminator(self) -> bool:
IPC-HDW3849HP-AS-PV does
"""
return not (
self.is_amcrest_doorbell() or self.is_flood_light()) and "table.Lighting_V2[{0}][0][0].Mode".format(
self.is_amcrest_doorbell() or self.is_flood_light()) and "table.Lighting_V2[{0}][0][0].Mode".format(
self._channel) in self.data

def is_motion_detection_enabled(self) -> bool:
Expand Down Expand Up @@ -659,7 +668,7 @@ def is_illuminator_on(self) -> bool:
def is_flood_light_on(self) -> bool:

if self._supports_floodlightmode:
#'coaxialControlIO.cgi?action=getStatus&channel=1'
# 'coaxialControlIO.cgi?action=getStatus&channel=1'
return self.data.get("status.status.WhiteLight", "") == "On"
else:
"""Return true if the amcrest flood light light is on"""
Expand Down

0 comments on commit 0876599

Please sign in to comment.