Skip to content

Commit

Permalink
add camera privacy masking control (#307)
Browse files Browse the repository at this point in the history
* add privacy mask control information

* add privacy masking control
  • Loading branch information
patriot1889 authored Oct 2, 2023
1 parent b71573d commit 7b03493
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ Service | Parameters | Description
`dahua.enable_time_overlay` | `target`: camera.cam13_main <br /> `channel`: The camera channel, e.g.: 0 <br /> `enabled`: True to enable, False to disable | Enables or disables the time overlay on the video
`dahua.enable_text_overlay` | `target`: camera.cam13_main <br /> `channel`: The camera channel, e.g.: 0 <br /> `group`: The group, used to apply multiple of text as an overly, e.g.: 0 <br /> `enabled`: True to enable, False to disable | Enables or disables the text overlay on the video
`dahua.enable_custom_overlay` | `target`: camera.cam13_main <br /> `channel`: The camera channel, e.g.: 0 <br /> `group`: The group, used to apply multiple of text as an overly, e.g.: 0 <br /> `enabled`: True to enable, False to disable | Enables or disables the custom overlay on the video
`dahua.set_privacy_masking` | `target`: camera.cam13_main <br /> `index`: The mask index, e.g.: 0 <br /> `enabled`: True to enable, False to disable | Enables or disabled a privacy mask on the camera
`dahua.set_record_mode` | `target`: camera.cam13_main <br /> `mode`: Auto, On, Off | Sets the record mode. On is always on recording. Off is always off. Auto based on motion settings, etc.
`dahua.enable_all_ivs_rules` | `target`: camera.cam13_main <br /> `channel`: The camera channel, e.g.: 0 <br /> `enabled`: True to enable all IVS rules, False to disable all IVS rules | Enables or disables all IVS rules
`dahua.enable_ivs_rule` | `target`: camera.cam13_main <br /> `channel`: The camera channel, e.g.: 0 <br /> `index`: The rule index <br /> enabled`: True to enable the IVS rule, False to disable the IVS rule | Enable or disable an IVS rule
Expand Down
14 changes: 14 additions & 0 deletions custom_components/dahua/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# This service handles setting the video profile mode to day or night
SERVICE_SET_VIDEO_PROFILE_MODE = "set_video_profile_mode"
SERVICE_SET_FOCUS_ZOOM = "set_focus_zoom"
SERVICE_SET_PRIVACY_MASKING = "set_privacy_masking"
SERVICE_SET_CHANNEL_TITLE = "set_channel_title"
SERVICE_SET_TEXT_OVERLAY = "set_text_overlay"
SERVICE_SET_CUSTOM_OVERLAY = "set_custom_overlay"
Expand Down Expand Up @@ -83,6 +84,15 @@ async def async_setup_entry(hass: HomeAssistant, config_entry, async_add_entitie
"async_adjustfocus"
)

platform.async_register_entity_service(
SERVICE_SET_PRIVACY_MASKING,
{
vol.Required("index", default=0): int,
vol.Required("enabled", default=False): bool,
},
"async_set_privacy_masking"
)

platform.async_register_entity_service(
SERVICE_ENABLE_CHANNEL_TITLE,
{
Expand Down Expand Up @@ -315,6 +325,10 @@ async def async_adjustfocus(self, focus: str, zoom: str):
""" Handles the service call from SERVICE_SET_INFRARED_MODE to set zoom and focus """
await self._coordinator.client.async_adjustfocus_v1(focus, zoom)
await self._coordinator.async_refresh()

async def async_set_privacy_masking(self, index: int, enabled: bool):
""" Handles the service call from SERVICE_SET_PRIVACY_MASKING to control the privacy masking """
await self._coordinator.client.async_setprivacymask(index, enabled)

async def async_set_enable_channel_title(self, enabled: bool):
""" Handles the service call from SERVICE_ENABLE_CHANNEL_TITLE """
Expand Down
11 changes: 11 additions & 0 deletions custom_components/dahua/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,17 @@ async def async_adjustfocus_v1(self, focus: str, zoom: str):

url = "/cgi-bin/devVideoInput.cgi?action=adjustFocus&focus={0}&zoom={1}".format(focus, zoom)
return await self.get(url, True)

async def async_setprivacymask(self, index: int, enabled: bool):
"""
async_setprivacymask will enable or disable the privacy mask
"""


url = "/cgi-bin/configManager.cgi?action=setConfig&PrivacyMasking[0][{0}].Enable={1}".format(
index, str(enabled).lower()
)
return await self.get(url, True)

async def async_set_night_switch_mode(self, channel: int, mode: str):
"""
Expand Down
27 changes: 27 additions & 0 deletions custom_components/dahua/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,30 @@ set_focus_zoom:
selector:
text:

set_privacy_masking:
name: Set the Dahua Privacy Masking
description: Enables or disabled the cameras privacy masking
target:
entity:
integration: dahua
domain: camera
fields:
index:
name: Index
description: "The mask index. 0 is the first mask"
example: 0
required: true
default: 0
selector:
number:
mode: box
min: 0
max: 100
enabled:
name: Enabled
description: "If true enables the mask, otherwise disables it"
example: true
required: true
default: true
selector:
boolean:

0 comments on commit 7b03493

Please sign in to comment.