From 755ddf1a94ef7bbb3e16b621454784fce17e1792 Mon Sep 17 00:00:00 2001 From: cgtobi Date: Fri, 28 Aug 2020 23:09:07 +0200 Subject: [PATCH] Add Netatmo camera light service (#39354) * Add camera light service * Move service to camera * Review --- homeassistant/components/netatmo/camera.py | 18 ++++++++++++++++++ homeassistant/components/netatmo/const.py | 7 +++++++ homeassistant/components/netatmo/light.py | 2 +- homeassistant/components/netatmo/services.yaml | 10 ++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/netatmo/camera.py b/homeassistant/components/netatmo/camera.py index bb46e25af3f..210c9d92e3c 100644 --- a/homeassistant/components/netatmo/camera.py +++ b/homeassistant/components/netatmo/camera.py @@ -11,9 +11,11 @@ from homeassistant.helpers import config_validation as cv, entity_platform from homeassistant.helpers.dispatcher import async_dispatcher_connect from .const import ( + ATTR_CAMERA_LIGHT_MODE, ATTR_PERSON, ATTR_PERSONS, ATTR_PSEUDO, + CAMERA_LIGHT_MODES, DATA_HANDLER, DATA_PERSONS, DOMAIN, @@ -21,6 +23,7 @@ from .const import ( EVENT_TYPE_ON, MANUFACTURER, MODELS, + SERVICE_SET_CAMERA_LIGHT, SERVICE_SET_PERSON_AWAY, SERVICE_SET_PERSONS_HOME, SIGNAL_NAME, @@ -101,6 +104,11 @@ async def async_setup_entry(hass, entry, async_add_entities): {vol.Optional(ATTR_PERSON): cv.string}, "_service_set_person_away", ) + platform.async_register_entity_service( + SERVICE_SET_CAMERA_LIGHT, + {vol.Required(ATTR_CAMERA_LIGHT_MODE): vol.In(CAMERA_LIGHT_MODES)}, + "_service_set_camera_light", + ) class NetatmoCamera(NetatmoBase, Camera): @@ -301,3 +309,13 @@ class NetatmoCamera(NetatmoBase, Camera): home_id=self._home_id, ) _LOGGER.debug("Set home as empty") + + def _service_set_camera_light(self, **kwargs): + """Service to set light mode.""" + mode = kwargs.get(ATTR_CAMERA_LIGHT_MODE) + _LOGGER.debug("Turn camera '%s' %s", self._name, mode) + self._data.set_state( + home_id=self._home_id, + camera_id=self._id, + floodlight=mode, + ) diff --git a/homeassistant/components/netatmo/const.py b/homeassistant/components/netatmo/const.py index f45fb09f94f..01351723716 100644 --- a/homeassistant/components/netatmo/const.py +++ b/homeassistant/components/netatmo/const.py @@ -67,7 +67,9 @@ ATTR_IS_KNOWN = "is_known" ATTR_FACE_URL = "face_url" ATTR_SCHEDULE_ID = "schedule_id" ATTR_SCHEDULE_NAME = "schedule_name" +ATTR_CAMERA_LIGHT_MODE = "camera_light_mode" +SERVICE_SET_CAMERA_LIGHT = "set_camera_light" SERVICE_SET_SCHEDULE = "set_schedule" SERVICE_SET_PERSONS_HOME = "set_persons_home" SERVICE_SET_PERSON_AWAY = "set_person_away" @@ -78,3 +80,8 @@ EVENT_TYPE_OFF = "off" EVENT_TYPE_ON = "on" EVENT_TYPE_SET_POINT = "set_point" EVENT_TYPE_THERM_MODE = "therm_mode" + +MODE_LIGHT_ON = "on" +MODE_LIGHT_OFF = "off" +MODE_LIGHT_AUTO = "auto" +CAMERA_LIGHT_MODES = [MODE_LIGHT_ON, MODE_LIGHT_OFF, MODE_LIGHT_AUTO] diff --git a/homeassistant/components/netatmo/light.py b/homeassistant/components/netatmo/light.py index a41dae33641..0c9e0c53176 100644 --- a/homeassistant/components/netatmo/light.py +++ b/homeassistant/components/netatmo/light.py @@ -142,7 +142,7 @@ class NetatmoLight(NetatmoBase, LightEntity): def turn_off(self, **kwargs): """Turn camera floodlight into auto mode.""" - _LOGGER.debug("Turn camera '%s' off", self._name) + _LOGGER.debug("Turn camera '%s' to auto mode", self._name) self._data.set_state( home_id=self._home_id, camera_id=self._id, diff --git a/homeassistant/components/netatmo/services.yaml b/homeassistant/components/netatmo/services.yaml index bd8a0cc8f20..459ef23b0e0 100644 --- a/homeassistant/components/netatmo/services.yaml +++ b/homeassistant/components/netatmo/services.yaml @@ -1,4 +1,14 @@ # Describes the format for available Netatmo services +set_camera_light: + description: Set the camera light mode. + fields: + camera_light_mode: + description: Outdoor camera light mode (on/off/auto) + example: auto + entity_id: + description: Entity id of the camera. + example: camera.netatmo_entrance + set_schedule: description: Set the heating schedule. fields: