2019-02-14 04:35:12 +00:00
|
|
|
"""Support for the Netatmo cameras."""
|
2016-06-10 06:31:36 +00:00
|
|
|
import logging
|
2016-08-26 20:50:32 +00:00
|
|
|
|
2020-01-11 11:20:00 +00:00
|
|
|
import pyatmo
|
2016-06-10 06:31:36 +00:00
|
|
|
import requests
|
2016-08-26 20:50:32 +00:00
|
|
|
import voluptuous as vol
|
2016-06-10 06:31:36 +00:00
|
|
|
|
2020-08-07 07:25:59 +00:00
|
|
|
from homeassistant.components.camera import SUPPORT_STREAM, Camera
|
2020-08-04 18:46:46 +00:00
|
|
|
from homeassistant.core import callback
|
|
|
|
from homeassistant.helpers import config_validation as cv, entity_platform
|
2020-08-07 07:25:59 +00:00
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
2020-01-11 11:20:00 +00:00
|
|
|
|
|
|
|
from .const import (
|
2020-08-28 21:09:07 +00:00
|
|
|
ATTR_CAMERA_LIGHT_MODE,
|
2020-08-04 18:46:46 +00:00
|
|
|
ATTR_PERSON,
|
|
|
|
ATTR_PERSONS,
|
2020-01-11 11:20:00 +00:00
|
|
|
ATTR_PSEUDO,
|
2020-08-28 21:09:07 +00:00
|
|
|
CAMERA_LIGHT_MODES,
|
2020-08-04 18:46:46 +00:00
|
|
|
DATA_HANDLER,
|
2020-01-11 11:20:00 +00:00
|
|
|
DATA_PERSONS,
|
|
|
|
DOMAIN,
|
2020-08-07 07:25:59 +00:00
|
|
|
EVENT_TYPE_OFF,
|
|
|
|
EVENT_TYPE_ON,
|
2020-01-11 11:20:00 +00:00
|
|
|
MANUFACTURER,
|
2020-03-11 16:25:19 +00:00
|
|
|
MODELS,
|
2020-08-28 21:09:07 +00:00
|
|
|
SERVICE_SET_CAMERA_LIGHT,
|
2020-08-07 07:25:59 +00:00
|
|
|
SERVICE_SET_PERSON_AWAY,
|
|
|
|
SERVICE_SET_PERSONS_HOME,
|
2020-08-04 18:46:46 +00:00
|
|
|
SIGNAL_NAME,
|
Add Netatmo camera services (#27970)
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Netatmo camera : Use new style string formatting.
* Make the file compliant with flake8 linter.
* Make the file compliant with flake8 linter.
* Make it compliant with black formatter.
* Make it compliant with black formatter.
* Bug fix : Flood light control was not working with VPN url.
2019-11-06 12:52:59 +00:00
|
|
|
)
|
2020-08-04 18:46:46 +00:00
|
|
|
from .data_handler import CAMERA_DATA_CLASS_NAME
|
|
|
|
from .netatmo_entity_base import NetatmoBase
|
2016-06-10 06:31:36 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
DEFAULT_QUALITY = "high"
|
2019-04-10 23:10:14 +00:00
|
|
|
|
Add Netatmo camera services (#27970)
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Netatmo camera : Use new style string formatting.
* Make the file compliant with flake8 linter.
* Make the file compliant with flake8 linter.
* Make it compliant with black formatter.
* Make it compliant with black formatter.
* Bug fix : Flood light control was not working with VPN url.
2019-11-06 12:52:59 +00:00
|
|
|
|
2020-01-11 11:20:00 +00:00
|
|
|
async def async_setup_entry(hass, entry, async_add_entities):
|
|
|
|
"""Set up the Netatmo camera platform."""
|
2020-08-04 18:46:46 +00:00
|
|
|
if "access_camera" not in entry.data["token"]["scope"]:
|
|
|
|
_LOGGER.info(
|
|
|
|
"Cameras are currently not supported with this authentication method"
|
|
|
|
)
|
|
|
|
return
|
2016-06-10 06:31:36 +00:00
|
|
|
|
2020-08-04 18:46:46 +00:00
|
|
|
data_handler = hass.data[DOMAIN][entry.entry_id][DATA_HANDLER]
|
|
|
|
|
|
|
|
async def get_entities():
|
2020-01-11 11:20:00 +00:00
|
|
|
"""Retrieve Netatmo entities."""
|
2020-08-04 18:46:46 +00:00
|
|
|
await data_handler.register_data_class(
|
|
|
|
CAMERA_DATA_CLASS_NAME, CAMERA_DATA_CLASS_NAME, None
|
|
|
|
)
|
|
|
|
|
|
|
|
data = data_handler.data
|
|
|
|
|
|
|
|
if not data.get(CAMERA_DATA_CLASS_NAME):
|
|
|
|
return []
|
|
|
|
|
|
|
|
data_class = data_handler.data[CAMERA_DATA_CLASS_NAME]
|
|
|
|
|
2020-01-11 11:20:00 +00:00
|
|
|
entities = []
|
|
|
|
try:
|
2020-08-04 18:46:46 +00:00
|
|
|
all_cameras = []
|
|
|
|
for home in data_class.cameras.values():
|
|
|
|
for camera in home.values():
|
|
|
|
all_cameras.append(camera)
|
|
|
|
|
|
|
|
for camera in all_cameras:
|
|
|
|
_LOGGER.debug("Adding camera %s %s", camera["id"], camera["name"])
|
2020-01-11 11:20:00 +00:00
|
|
|
entities.append(
|
2019-07-31 19:25:30 +00:00
|
|
|
NetatmoCamera(
|
2020-08-04 18:46:46 +00:00
|
|
|
data_handler,
|
|
|
|
camera["id"],
|
|
|
|
camera["type"],
|
|
|
|
camera["home_id"],
|
|
|
|
DEFAULT_QUALITY,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2020-01-11 11:20:00 +00:00
|
|
|
)
|
2020-08-04 18:46:46 +00:00
|
|
|
|
|
|
|
for person_id, person_data in data_handler.data[
|
|
|
|
CAMERA_DATA_CLASS_NAME
|
|
|
|
].persons.items():
|
|
|
|
hass.data[DOMAIN][DATA_PERSONS][person_id] = person_data.get(
|
|
|
|
ATTR_PSEUDO
|
|
|
|
)
|
2020-01-11 11:20:00 +00:00
|
|
|
except pyatmo.NoDevice:
|
|
|
|
_LOGGER.debug("No cameras found")
|
2020-08-04 18:46:46 +00:00
|
|
|
|
2020-01-11 11:20:00 +00:00
|
|
|
return entities
|
|
|
|
|
2020-08-04 18:46:46 +00:00
|
|
|
async_add_entities(await get_entities(), True)
|
|
|
|
|
|
|
|
platform = entity_platform.current_platform.get()
|
|
|
|
|
|
|
|
if data_handler.data[CAMERA_DATA_CLASS_NAME] is not None:
|
|
|
|
platform.async_register_entity_service(
|
2020-08-07 07:25:59 +00:00
|
|
|
SERVICE_SET_PERSONS_HOME,
|
|
|
|
{vol.Required(ATTR_PERSONS): vol.All(cv.ensure_list, [cv.string])},
|
|
|
|
"_service_set_persons_home",
|
2020-08-04 18:46:46 +00:00
|
|
|
)
|
|
|
|
platform.async_register_entity_service(
|
2020-08-07 07:25:59 +00:00
|
|
|
SERVICE_SET_PERSON_AWAY,
|
|
|
|
{vol.Optional(ATTR_PERSON): cv.string},
|
|
|
|
"_service_set_person_away",
|
2020-08-04 18:46:46 +00:00
|
|
|
)
|
2020-08-28 21:09:07 +00:00
|
|
|
platform.async_register_entity_service(
|
|
|
|
SERVICE_SET_CAMERA_LIGHT,
|
|
|
|
{vol.Required(ATTR_CAMERA_LIGHT_MODE): vol.In(CAMERA_LIGHT_MODES)},
|
|
|
|
"_service_set_camera_light",
|
|
|
|
)
|
2016-06-10 06:31:36 +00:00
|
|
|
|
Add Netatmo camera services (#27970)
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Netatmo camera : Use new style string formatting.
* Make the file compliant with flake8 linter.
* Make the file compliant with flake8 linter.
* Make it compliant with black formatter.
* Make it compliant with black formatter.
* Bug fix : Flood light control was not working with VPN url.
2019-11-06 12:52:59 +00:00
|
|
|
|
2020-08-04 18:46:46 +00:00
|
|
|
class NetatmoCamera(NetatmoBase, Camera):
|
2020-01-11 11:20:00 +00:00
|
|
|
"""Representation of a Netatmo camera."""
|
2016-06-10 06:31:36 +00:00
|
|
|
|
2020-08-04 18:46:46 +00:00
|
|
|
def __init__(
|
2020-08-27 11:56:20 +00:00
|
|
|
self,
|
|
|
|
data_handler,
|
|
|
|
camera_id,
|
|
|
|
camera_type,
|
|
|
|
home_id,
|
|
|
|
quality,
|
2020-08-04 18:46:46 +00:00
|
|
|
):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Set up for access to the Netatmo camera images."""
|
2020-08-04 18:46:46 +00:00
|
|
|
Camera.__init__(self)
|
|
|
|
super().__init__(data_handler)
|
|
|
|
|
|
|
|
self._data_classes.append(
|
|
|
|
{"name": CAMERA_DATA_CLASS_NAME, SIGNAL_NAME: CAMERA_DATA_CLASS_NAME}
|
|
|
|
)
|
|
|
|
|
|
|
|
self._id = camera_id
|
|
|
|
self._home_id = home_id
|
|
|
|
self._device_name = self._data.get_camera(camera_id=camera_id).get("name")
|
|
|
|
self._name = f"{MANUFACTURER} {self._device_name}"
|
|
|
|
self._model = camera_type
|
|
|
|
self._unique_id = f"{self._id}-{self._model}"
|
Add Netatmo camera services (#27970)
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Netatmo camera : Use new style string formatting.
* Make the file compliant with flake8 linter.
* Make the file compliant with flake8 linter.
* Make it compliant with black formatter.
* Make it compliant with black formatter.
* Bug fix : Flood light control was not working with VPN url.
2019-11-06 12:52:59 +00:00
|
|
|
self._quality = quality
|
|
|
|
self._vpnurl = None
|
|
|
|
self._localurl = None
|
|
|
|
self._status = None
|
|
|
|
self._sd_status = None
|
|
|
|
self._alim_status = None
|
|
|
|
self._is_local = None
|
|
|
|
|
2020-08-04 18:46:46 +00:00
|
|
|
async def async_added_to_hass(self) -> None:
|
|
|
|
"""Entity created."""
|
|
|
|
await super().async_added_to_hass()
|
|
|
|
|
2020-08-07 07:25:59 +00:00
|
|
|
for event_type in (EVENT_TYPE_OFF, EVENT_TYPE_ON):
|
|
|
|
self._listeners.append(
|
|
|
|
async_dispatcher_connect(
|
|
|
|
self.hass,
|
|
|
|
f"signal-{DOMAIN}-webhook-{event_type}",
|
|
|
|
self.handle_event,
|
|
|
|
)
|
|
|
|
)
|
2020-08-04 18:46:46 +00:00
|
|
|
|
2020-08-07 07:25:59 +00:00
|
|
|
@callback
|
|
|
|
def handle_event(self, event):
|
2020-08-04 18:46:46 +00:00
|
|
|
"""Handle webhook events."""
|
2020-08-07 07:25:59 +00:00
|
|
|
data = event["data"]
|
2020-08-04 18:46:46 +00:00
|
|
|
|
|
|
|
if not data.get("camera_id"):
|
|
|
|
return
|
|
|
|
|
|
|
|
if data["home_id"] == self._home_id and data["camera_id"] == self._id:
|
|
|
|
if data["push_type"] in ["NACamera-off", "NACamera-disconnection"]:
|
|
|
|
self.is_streaming = False
|
|
|
|
self._status = "off"
|
|
|
|
elif data["push_type"] in ["NACamera-on", "NACamera-connection"]:
|
|
|
|
self.is_streaming = True
|
|
|
|
self._status = "on"
|
|
|
|
|
|
|
|
self.async_write_ha_state()
|
|
|
|
return
|
|
|
|
|
2016-06-10 06:31:36 +00:00
|
|
|
def camera_image(self):
|
|
|
|
"""Return a still image response from the camera."""
|
|
|
|
try:
|
|
|
|
if self._localurl:
|
2019-07-31 19:25:30 +00:00
|
|
|
response = requests.get(
|
2019-09-03 18:35:00 +00:00
|
|
|
f"{self._localurl}/live/snapshot_720.jpg", timeout=10
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2017-02-01 16:33:32 +00:00
|
|
|
elif self._vpnurl:
|
2019-07-31 19:25:30 +00:00
|
|
|
response = requests.get(
|
2020-08-27 11:56:20 +00:00
|
|
|
f"{self._vpnurl}/live/snapshot_720.jpg",
|
|
|
|
timeout=10,
|
|
|
|
verify=True,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2017-02-01 16:33:32 +00:00
|
|
|
else:
|
2020-01-11 11:20:00 +00:00
|
|
|
_LOGGER.error("Welcome/Presence VPN URL is None")
|
2020-08-04 18:46:46 +00:00
|
|
|
(self._vpnurl, self._localurl) = self._data.camera_urls(
|
|
|
|
camera_id=self._id
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2017-02-01 16:33:32 +00:00
|
|
|
return None
|
2020-08-04 18:46:46 +00:00
|
|
|
|
2016-06-10 06:31:36 +00:00
|
|
|
except requests.exceptions.RequestException as error:
|
2020-01-11 11:20:00 +00:00
|
|
|
_LOGGER.info("Welcome/Presence URL changed: %s", error)
|
2020-08-04 18:46:46 +00:00
|
|
|
self._data.update_camera_urls(camera_id=self._id)
|
|
|
|
(self._vpnurl, self._localurl) = self._data.camera_urls(camera_id=self._id)
|
2016-06-10 06:31:36 +00:00
|
|
|
return None
|
|
|
|
|
2020-08-04 18:46:46 +00:00
|
|
|
return response.content
|
2020-01-11 11:20:00 +00:00
|
|
|
|
2017-01-17 07:10:18 +00:00
|
|
|
@property
|
Add Netatmo camera services (#27970)
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Netatmo camera : Use new style string formatting.
* Make the file compliant with flake8 linter.
* Make the file compliant with flake8 linter.
* Make it compliant with black formatter.
* Make it compliant with black formatter.
* Bug fix : Flood light control was not working with VPN url.
2019-11-06 12:52:59 +00:00
|
|
|
def device_state_attributes(self):
|
|
|
|
"""Return the Netatmo-specific camera state attributes."""
|
2020-08-04 18:46:46 +00:00
|
|
|
return {
|
|
|
|
"id": self._id,
|
|
|
|
"status": self._status,
|
|
|
|
"sd_status": self._sd_status,
|
|
|
|
"alim_status": self._alim_status,
|
|
|
|
"is_local": self._is_local,
|
|
|
|
"vpn_url": self._vpnurl,
|
|
|
|
"local_url": self._localurl,
|
|
|
|
}
|
2017-01-17 07:10:18 +00:00
|
|
|
|
|
|
|
@property
|
Add Netatmo camera services (#27970)
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Netatmo camera : Use new style string formatting.
* Make the file compliant with flake8 linter.
* Make the file compliant with flake8 linter.
* Make it compliant with black formatter.
* Make it compliant with black formatter.
* Bug fix : Flood light control was not working with VPN url.
2019-11-06 12:52:59 +00:00
|
|
|
def available(self):
|
|
|
|
"""Return True if entity is available."""
|
2020-08-04 18:46:46 +00:00
|
|
|
return bool(self._alim_status == "on" or self._status == "disconnected")
|
2019-04-10 23:10:14 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def supported_features(self):
|
|
|
|
"""Return supported features."""
|
|
|
|
return SUPPORT_STREAM
|
|
|
|
|
Add Netatmo camera services (#27970)
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Netatmo camera : Use new style string formatting.
* Make the file compliant with flake8 linter.
* Make the file compliant with flake8 linter.
* Make it compliant with black formatter.
* Make it compliant with black formatter.
* Bug fix : Flood light control was not working with VPN url.
2019-11-06 12:52:59 +00:00
|
|
|
@property
|
|
|
|
def brand(self):
|
|
|
|
"""Return the camera brand."""
|
2020-01-11 11:20:00 +00:00
|
|
|
return MANUFACTURER
|
Add Netatmo camera services (#27970)
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Netatmo camera : Use new style string formatting.
* Make the file compliant with flake8 linter.
* Make the file compliant with flake8 linter.
* Make it compliant with black formatter.
* Make it compliant with black formatter.
* Bug fix : Flood light control was not working with VPN url.
2019-11-06 12:52:59 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def motion_detection_enabled(self):
|
|
|
|
"""Return the camera motion detection status."""
|
|
|
|
return bool(self._status == "on")
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return true if on."""
|
|
|
|
return self.is_streaming
|
|
|
|
|
2020-08-04 18:46:46 +00:00
|
|
|
def turn_off(self):
|
|
|
|
"""Turn off camera."""
|
|
|
|
self._data.set_state(
|
|
|
|
home_id=self._home_id, camera_id=self._id, monitoring="off"
|
|
|
|
)
|
|
|
|
|
|
|
|
def turn_on(self):
|
|
|
|
"""Turn on camera."""
|
|
|
|
self._data.set_state(home_id=self._home_id, camera_id=self._id, monitoring="on")
|
|
|
|
|
2019-05-23 16:45:30 +00:00
|
|
|
async def stream_source(self):
|
2019-04-10 23:10:14 +00:00
|
|
|
"""Return the stream source."""
|
2019-07-31 19:25:30 +00:00
|
|
|
url = "{0}/live/files/{1}/index.m3u8"
|
2019-04-10 23:10:14 +00:00
|
|
|
if self._localurl:
|
|
|
|
return url.format(self._localurl, self._quality)
|
|
|
|
return url.format(self._vpnurl, self._quality)
|
Add Netatmo camera services (#27970)
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Netatmo camera : Use new style string formatting.
* Make the file compliant with flake8 linter.
* Make the file compliant with flake8 linter.
* Make it compliant with black formatter.
* Make it compliant with black formatter.
* Bug fix : Flood light control was not working with VPN url.
2019-11-06 12:52:59 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def model(self):
|
|
|
|
"""Return the camera model."""
|
2020-08-04 18:46:46 +00:00
|
|
|
return MODELS[self._model]
|
Add Netatmo camera services (#27970)
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Netatmo camera : Use new style string formatting.
* Make the file compliant with flake8 linter.
* Make the file compliant with flake8 linter.
* Make it compliant with black formatter.
* Make it compliant with black formatter.
* Bug fix : Flood light control was not working with VPN url.
2019-11-06 12:52:59 +00:00
|
|
|
|
2020-08-04 18:46:46 +00:00
|
|
|
@callback
|
|
|
|
def async_update_callback(self):
|
|
|
|
"""Update the entity's state."""
|
|
|
|
camera = self._data.get_camera(self._id)
|
|
|
|
self._vpnurl, self._localurl = self._data.camera_urls(self._id)
|
2020-01-11 11:20:00 +00:00
|
|
|
self._status = camera.get("status")
|
|
|
|
self._sd_status = camera.get("sd_status")
|
|
|
|
self._alim_status = camera.get("alim_status")
|
|
|
|
self._is_local = camera.get("is_local")
|
2020-08-04 18:46:46 +00:00
|
|
|
self.is_streaming = bool(self._status == "on")
|
|
|
|
|
2020-08-07 07:25:59 +00:00
|
|
|
def _service_set_persons_home(self, **kwargs):
|
2020-08-04 18:46:46 +00:00
|
|
|
"""Service to change current home schedule."""
|
|
|
|
persons = kwargs.get(ATTR_PERSONS)
|
|
|
|
person_ids = []
|
|
|
|
for person in persons:
|
|
|
|
for pid, data in self._data.persons.items():
|
|
|
|
if data.get("pseudo") == person:
|
|
|
|
person_ids.append(pid)
|
|
|
|
|
|
|
|
self._data.set_persons_home(person_ids=person_ids, home_id=self._home_id)
|
2020-08-07 07:25:59 +00:00
|
|
|
_LOGGER.debug("Set %s as at home", persons)
|
2020-08-04 18:46:46 +00:00
|
|
|
|
2020-08-07 07:25:59 +00:00
|
|
|
def _service_set_person_away(self, **kwargs):
|
2020-08-04 18:46:46 +00:00
|
|
|
"""Service to mark a person as away or set the home as empty."""
|
|
|
|
person = kwargs.get(ATTR_PERSON)
|
|
|
|
person_id = None
|
|
|
|
if person:
|
|
|
|
for pid, data in self._data.persons.items():
|
|
|
|
if data.get("pseudo") == person:
|
|
|
|
person_id = pid
|
|
|
|
|
|
|
|
if person_id is not None:
|
|
|
|
self._data.set_persons_away(
|
2020-08-27 11:56:20 +00:00
|
|
|
person_id=person_id,
|
|
|
|
home_id=self._home_id,
|
Add Netatmo camera services (#27970)
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Netatmo camera : Use new style string formatting.
* Make the file compliant with flake8 linter.
* Make the file compliant with flake8 linter.
* Make it compliant with black formatter.
* Make it compliant with black formatter.
* Bug fix : Flood light control was not working with VPN url.
2019-11-06 12:52:59 +00:00
|
|
|
)
|
2020-08-07 07:25:59 +00:00
|
|
|
_LOGGER.debug("Set %s as away", person)
|
Add Netatmo camera services (#27970)
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement turn_on and turn_off methods.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Netatmo camera : Implement enable_motion_detection(), disable_motion_detection() operations.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Add Presence Netatmo Camera services (set_light_auto, set_light_on, set_light_off) to control its internal flood light status.
* Netatmo camera : Use new style string formatting.
* Make the file compliant with flake8 linter.
* Make the file compliant with flake8 linter.
* Make it compliant with black formatter.
* Make it compliant with black formatter.
* Bug fix : Flood light control was not working with VPN url.
2019-11-06 12:52:59 +00:00
|
|
|
|
2020-08-04 18:46:46 +00:00
|
|
|
else:
|
|
|
|
self._data.set_persons_away(
|
2020-08-27 11:56:20 +00:00
|
|
|
person_id=person_id,
|
|
|
|
home_id=self._home_id,
|
2020-08-04 18:46:46 +00:00
|
|
|
)
|
2020-08-07 07:25:59 +00:00
|
|
|
_LOGGER.debug("Set home as empty")
|
2020-08-28 21:09:07 +00:00
|
|
|
|
|
|
|
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,
|
|
|
|
)
|