2424 CONF_MQTT_PREFIX , CONF_PTZ ,
2525 CONF_TOPIC_MOTION_DETECTION_IMAGE , DEFAULT_BRAND , DOMAIN ,
2626 HTTP_TIMEOUT , LINK_HIGH_RES_STREAM , LINK_LOW_RES_STREAM ,
27- MSTAR , SERVICE_PTZ , SERVICE_SPEAK )
27+ MSTAR , SERVICE_MOVE_TO_PRESET , SERVICE_PTZ ,
28+ SERVICE_REBOOT , SERVICE_SPEAK )
2829
2930_LOGGER = logging .getLogger (__name__ )
3031
@@ -71,7 +72,7 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, async_add_
7172 )
7273
7374 platform .async_register_entity_service (
74- "move_to_preset" ,
75+ SERVICE_MOVE_TO_PRESET ,
7576 {
7677 vol .Required ("preset_id" ): vol .All (int , vol .Range (min = 0 , max = 14 )),
7778 },
@@ -97,6 +98,12 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, async_add_
9798 "async_perform_speak" ,
9899 )
99100
101+ platform .async_register_entity_service (
102+ SERVICE_REBOOT ,
103+ {},
104+ "async_perform_reboot" ,
105+ )
106+
100107 async_add_entities (
101108 [
102109 YiHackCamera (hass , config ),
@@ -383,6 +390,24 @@ async def async_perform_speak(self, language, sentence):
383390
384391 await self .hass .async_add_executor_job (self ._perform_speak , language , sentence )
385392
393+ def _perform_reboot (self ):
394+ auth = None
395+ if self ._user or self ._password :
396+ auth = HTTPBasicAuth (self ._user , self ._password )
397+
398+ try :
399+ response = requests .get (f"http://{ self ._host } :{ self ._port } /cgi-bin/reboot.sh" , timeout = HTTP_TIMEOUT , auth = auth )
400+ if response .status_code >= 300 :
401+ _LOGGER .error (f"Failed to send reboot command to device { self ._host } " )
402+ except requests .exceptions .RequestException as error :
403+ _LOGGER .error (f"Failed to send reboot command to device { self ._host } : error { error } " )
404+
405+ async def async_perform_reboot (self ):
406+ """Reboot the camera."""
407+ _LOGGER .debug (f"Reboot the camera" )
408+
409+ await self .hass .async_add_executor_job (self ._perform_reboot )
410+
386411 @property
387412 def brand (self ):
388413 """Camera brand."""
0 commit comments