Skip to content

Commit 3739e52

Browse files
committed
Add a service to reboot the device
1 parent 48d94a6 commit 3739e52

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ Service | Parameters | Description
198198
`dahua.vto_open_door` | `target`: camera.cam13_main <br /> `door_id`: The door ID to open, e.g.: 1 <br /> Opens a door via a VTO
199199
`dahua.vto_cancel_call` | `target`: camera.cam13_main <br />Cancels a call on a VTO device (Doorbell)
200200
`dahua.set_video_in_day_night_mode` | `target`: camera.cam13_main <br /> `config_type`: The config type: general, day, night <br /> `mode`: The mode: Auto, Color, BlackWhite. Note Auto is also known as Brightness by Dahua|Set the camera's Day/Night Mode. For example, Color, BlackWhite, or Auto
201+
`dahua.reboot` | `target`: camera.cam13_main <br />Reboots the device
201202

202203

203204
## Camera

custom_components/dahua/camera.py

+11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
SERVICE_VTO_OPEN_DOOR = "vto_open_door"
3535
SERVICE_VTO_CANCEL_CALL = "vto_cancel_call"
3636
SERVICE_SET_DAY_NIGHT_MODE = "set_video_in_day_night_mode"
37+
SERVICE_REBOOT = "reboot"
3738

3839

3940
async def async_setup_entry(hass: HomeAssistant, config_entry, async_add_entities):
@@ -177,6 +178,12 @@ async def async_setup_entry(hass: HomeAssistant, config_entry, async_add_entitie
177178
"async_set_video_in_day_night_mode"
178179
)
179180

181+
platform.async_register_entity_service(
182+
SERVICE_REBOOT,
183+
{},
184+
"async_reboot"
185+
)
186+
180187
platform.async_register_entity_service(
181188
SERVICE_SET_RECORD_MODE,
182189
{
@@ -274,6 +281,10 @@ async def async_set_video_in_day_night_mode(self, config_type: str, mode: str):
274281
await self._coordinator.client.async_set_video_in_day_night_mode(channel, config_type, mode)
275282
await self._coordinator.async_refresh()
276283

284+
async def async_reboot(self):
285+
""" Handles the service call from SERVICE_REBOOT to reboot the device """
286+
await self._coordinator.client.reboot()
287+
277288
async def async_set_record_mode(self, mode: str):
278289
""" Handles the service call from SERVICE_SET_RECORD_MODE to set the record mode """
279290
channel = self._coordinator.get_channel()

custom_components/dahua/client.py

+4
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ async def get_vendor(self) -> dict:
104104
""" get_vendor returns the vendor. Example response: vendor=Dahua """
105105
return await self.get("/cgi-bin/magicBox.cgi?action=getVendor")
106106

107+
async def reboot(self) -> dict:
108+
""" Reboots the device """
109+
return await self.get("/cgi-bin/magicBox.cgi?action=reboot")
110+
107111
async def get_max_extra_streams(self) -> int:
108112
""" get_max_extra_streams returns the max number of sub streams supported by the camera """
109113
try:

custom_components/dahua/services.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,14 @@ set_video_in_day_night_mode:
286286
- "Color"
287287
- "BlackWhite"
288288

289+
reboot:
290+
name: Reboots the device
291+
description: "Reboots the device"
292+
target:
293+
entity:
294+
integration: dahua
295+
domain: camera
296+
289297
set_record_mode:
290298
name: Set Record Mode on Dahua Camera
291299
description: Sets the record mode (on/off or auto). On is always on recording. Off is always off. Auto based on motion settings, etc.

0 commit comments

Comments
 (0)