Add Netatmo camera light service (#39354)

* Add camera light service

* Move service to camera

* Review
This commit is contained in:
cgtobi 2020-08-28 23:09:07 +02:00 committed by GitHub
parent d587f134ca
commit 755ddf1a94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 1 deletions

View File

@ -11,9 +11,11 @@ from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from .const import ( from .const import (
ATTR_CAMERA_LIGHT_MODE,
ATTR_PERSON, ATTR_PERSON,
ATTR_PERSONS, ATTR_PERSONS,
ATTR_PSEUDO, ATTR_PSEUDO,
CAMERA_LIGHT_MODES,
DATA_HANDLER, DATA_HANDLER,
DATA_PERSONS, DATA_PERSONS,
DOMAIN, DOMAIN,
@ -21,6 +23,7 @@ from .const import (
EVENT_TYPE_ON, EVENT_TYPE_ON,
MANUFACTURER, MANUFACTURER,
MODELS, MODELS,
SERVICE_SET_CAMERA_LIGHT,
SERVICE_SET_PERSON_AWAY, SERVICE_SET_PERSON_AWAY,
SERVICE_SET_PERSONS_HOME, SERVICE_SET_PERSONS_HOME,
SIGNAL_NAME, SIGNAL_NAME,
@ -101,6 +104,11 @@ async def async_setup_entry(hass, entry, async_add_entities):
{vol.Optional(ATTR_PERSON): cv.string}, {vol.Optional(ATTR_PERSON): cv.string},
"_service_set_person_away", "_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): class NetatmoCamera(NetatmoBase, Camera):
@ -301,3 +309,13 @@ class NetatmoCamera(NetatmoBase, Camera):
home_id=self._home_id, home_id=self._home_id,
) )
_LOGGER.debug("Set home as empty") _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,
)

View File

@ -67,7 +67,9 @@ ATTR_IS_KNOWN = "is_known"
ATTR_FACE_URL = "face_url" ATTR_FACE_URL = "face_url"
ATTR_SCHEDULE_ID = "schedule_id" ATTR_SCHEDULE_ID = "schedule_id"
ATTR_SCHEDULE_NAME = "schedule_name" 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_SCHEDULE = "set_schedule"
SERVICE_SET_PERSONS_HOME = "set_persons_home" SERVICE_SET_PERSONS_HOME = "set_persons_home"
SERVICE_SET_PERSON_AWAY = "set_person_away" SERVICE_SET_PERSON_AWAY = "set_person_away"
@ -78,3 +80,8 @@ EVENT_TYPE_OFF = "off"
EVENT_TYPE_ON = "on" EVENT_TYPE_ON = "on"
EVENT_TYPE_SET_POINT = "set_point" EVENT_TYPE_SET_POINT = "set_point"
EVENT_TYPE_THERM_MODE = "therm_mode" 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]

View File

@ -142,7 +142,7 @@ class NetatmoLight(NetatmoBase, LightEntity):
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
"""Turn camera floodlight into auto mode.""" """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( self._data.set_state(
home_id=self._home_id, home_id=self._home_id,
camera_id=self._id, camera_id=self._id,

View File

@ -1,4 +1,14 @@
# Describes the format for available Netatmo services # 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: set_schedule:
description: Set the heating schedule. description: Set the heating schedule.
fields: fields: