2019-02-14 04:35:12 +00:00
|
|
|
"""Support for the Netatmo cameras."""
|
2021-07-21 21:36:57 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2016-06-10 06:31:36 +00:00
|
|
|
import logging
|
2021-07-21 21:36:57 +00:00
|
|
|
from typing import Any, cast
|
2016-08-26 20:50:32 +00:00
|
|
|
|
2021-05-20 12:59:19 +00:00
|
|
|
import aiohttp
|
2022-09-26 01:55:58 +00:00
|
|
|
from pyatmo import ApiError as NetatmoApiError, modules as NaModules
|
|
|
|
from pyatmo.event import Event as NaEvent
|
2016-08-26 20:50:32 +00:00
|
|
|
import voluptuous as vol
|
2016-06-10 06:31:36 +00:00
|
|
|
|
2022-04-07 07:34:29 +00:00
|
|
|
from homeassistant.components.camera import Camera, CameraEntityFeature
|
2021-07-21 21:36:57 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant, callback
|
2022-09-26 01:55:58 +00:00
|
|
|
from homeassistant.exceptions import HomeAssistantError
|
2020-08-04 18:46:46 +00:00
|
|
|
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
|
2021-07-21 21:36:57 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
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-08-28 21:09:07 +00:00
|
|
|
CAMERA_LIGHT_MODES,
|
2022-09-26 01:55:58 +00:00
|
|
|
CONF_URL_SECURITY,
|
2020-09-04 18:21:42 +00:00
|
|
|
DATA_CAMERAS,
|
|
|
|
DATA_EVENTS,
|
2020-01-11 11:20:00 +00:00
|
|
|
DOMAIN,
|
2020-10-20 19:57:00 +00:00
|
|
|
EVENT_TYPE_LIGHT_MODE,
|
2020-08-07 07:25:59 +00:00
|
|
|
EVENT_TYPE_OFF,
|
|
|
|
EVENT_TYPE_ON,
|
2020-01-11 11:20:00 +00:00
|
|
|
MANUFACTURER,
|
2022-09-26 01:55:58 +00:00
|
|
|
NETATMO_CREATE_CAMERA,
|
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,
|
2021-05-20 17:28:21 +00:00
|
|
|
WEBHOOK_LIGHT_MODE,
|
|
|
|
WEBHOOK_NACAMERA_CONNECTION,
|
|
|
|
WEBHOOK_PUSH_TYPE,
|
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
|
|
|
)
|
2022-09-26 01:55:58 +00:00
|
|
|
from .data_handler import EVENT, HOME, SIGNAL_NAME, NetatmoDevice
|
2020-08-04 18:46:46 +00:00
|
|
|
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
|
|
|
|
2021-07-21 21:36:57 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
|
|
|
) -> None:
|
2020-01-11 11:20:00 +00:00
|
|
|
"""Set up the Netatmo camera platform."""
|
2020-08-04 18:46:46 +00:00
|
|
|
|
2022-09-26 01:55:58 +00:00
|
|
|
@callback
|
|
|
|
def _create_entity(netatmo_device: NetatmoDevice) -> None:
|
|
|
|
entity = NetatmoCamera(netatmo_device)
|
|
|
|
async_add_entities([entity])
|
2020-08-04 18:46:46 +00:00
|
|
|
|
2022-09-26 01:55:58 +00:00
|
|
|
entry.async_on_unload(
|
|
|
|
async_dispatcher_connect(hass, NETATMO_CREATE_CAMERA, _create_entity)
|
|
|
|
)
|
2021-03-05 20:41:55 +00:00
|
|
|
|
2021-05-03 16:34:28 +00:00
|
|
|
platform = entity_platform.async_get_current_platform()
|
2020-08-04 18:46:46 +00:00
|
|
|
|
2021-03-05 20:41:55 +00:00
|
|
|
platform.async_register_entity_service(
|
|
|
|
SERVICE_SET_PERSONS_HOME,
|
|
|
|
{vol.Required(ATTR_PERSONS): vol.All(cv.ensure_list, [cv.string])},
|
|
|
|
"_service_set_persons_home",
|
|
|
|
)
|
|
|
|
platform.async_register_entity_service(
|
|
|
|
SERVICE_SET_PERSON_AWAY,
|
|
|
|
{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",
|
|
|
|
)
|
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
|
|
|
|
2022-07-27 12:17:38 +00:00
|
|
|
_attr_brand = MANUFACTURER
|
|
|
|
_attr_has_entity_name = True
|
2022-04-07 07:34:29 +00:00
|
|
|
_attr_supported_features = CameraEntityFeature.STREAM
|
|
|
|
|
2020-08-04 18:46:46 +00:00
|
|
|
def __init__(
|
2020-08-27 11:56:20 +00:00
|
|
|
self,
|
2022-09-26 01:55:58 +00:00
|
|
|
netatmo_device: NetatmoDevice,
|
2021-07-21 21:36:57 +00:00
|
|
|
) -> None:
|
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)
|
2022-09-26 01:55:58 +00:00
|
|
|
super().__init__(netatmo_device.data_handler)
|
|
|
|
|
|
|
|
self._camera = cast(NaModules.Camera, netatmo_device.device)
|
|
|
|
self._id = self._camera.entity_id
|
|
|
|
self._home_id = self._camera.home.entity_id
|
|
|
|
self._device_name = self._camera.name
|
|
|
|
self._model = self._camera.device_type
|
|
|
|
self._config_url = CONF_URL_SECURITY
|
2021-07-02 09:36:37 +00:00
|
|
|
self._attr_unique_id = f"{self._id}-{self._model}"
|
2022-09-26 01:55:58 +00:00
|
|
|
self._quality = DEFAULT_QUALITY
|
|
|
|
self._monitoring: bool | None = None
|
2020-10-20 19:57:00 +00:00
|
|
|
self._light_state = None
|
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
|
|
|
|
2022-09-26 01:55:58 +00:00
|
|
|
self._publishers.extend(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": HOME,
|
|
|
|
"home_id": self._home_id,
|
|
|
|
SIGNAL_NAME: f"{HOME}-{self._home_id}",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": EVENT,
|
|
|
|
"home_id": self._home_id,
|
|
|
|
SIGNAL_NAME: f"{EVENT}-{self._home_id}",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
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-10-20 19:57:00 +00:00
|
|
|
for event_type in (EVENT_TYPE_LIGHT_MODE, EVENT_TYPE_OFF, EVENT_TYPE_ON):
|
2022-09-26 01:55:58 +00:00
|
|
|
self.async_on_remove(
|
2020-08-07 07:25:59 +00:00
|
|
|
async_dispatcher_connect(
|
|
|
|
self.hass,
|
|
|
|
f"signal-{DOMAIN}-webhook-{event_type}",
|
|
|
|
self.handle_event,
|
|
|
|
)
|
|
|
|
)
|
2020-08-04 18:46:46 +00:00
|
|
|
|
2020-09-04 18:21:42 +00:00
|
|
|
self.hass.data[DOMAIN][DATA_CAMERAS][self._id] = self._device_name
|
|
|
|
|
2020-08-07 07:25:59 +00:00
|
|
|
@callback
|
2021-07-21 21:36:57 +00:00
|
|
|
def handle_event(self, event: dict) -> None:
|
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:
|
2021-07-29 23:20:03 +00:00
|
|
|
if data[WEBHOOK_PUSH_TYPE] in ("NACamera-off", "NACamera-disconnection"):
|
2021-11-25 15:03:53 +00:00
|
|
|
self._attr_is_streaming = False
|
2022-09-26 01:55:58 +00:00
|
|
|
self._monitoring = False
|
2021-07-29 23:20:03 +00:00
|
|
|
elif data[WEBHOOK_PUSH_TYPE] in (
|
2021-05-20 17:28:21 +00:00
|
|
|
"NACamera-on",
|
|
|
|
WEBHOOK_NACAMERA_CONNECTION,
|
2021-07-29 23:20:03 +00:00
|
|
|
):
|
2021-11-25 15:03:53 +00:00
|
|
|
self._attr_is_streaming = True
|
2022-09-26 01:55:58 +00:00
|
|
|
self._monitoring = True
|
2021-05-20 17:28:21 +00:00
|
|
|
elif data[WEBHOOK_PUSH_TYPE] == WEBHOOK_LIGHT_MODE:
|
2020-10-20 19:57:00 +00:00
|
|
|
self._light_state = data["sub_type"]
|
2021-07-02 09:36:37 +00:00
|
|
|
self._attr_extra_state_attributes.update(
|
|
|
|
{"light_state": self._light_state}
|
|
|
|
)
|
2020-08-04 18:46:46 +00:00
|
|
|
|
|
|
|
self.async_write_ha_state()
|
|
|
|
return
|
|
|
|
|
2021-08-11 00:33:06 +00:00
|
|
|
async def async_camera_image(
|
|
|
|
self, width: int | None = None, height: int | None = None
|
|
|
|
) -> bytes | None:
|
2016-06-10 06:31:36 +00:00
|
|
|
"""Return a still image response from the camera."""
|
|
|
|
try:
|
2022-09-26 01:55:58 +00:00
|
|
|
return cast(bytes, await self._camera.async_get_live_snapshot())
|
2021-05-20 12:59:19 +00:00
|
|
|
except (
|
|
|
|
aiohttp.ClientPayloadError,
|
|
|
|
aiohttp.ContentTypeError,
|
2021-05-20 17:28:21 +00:00
|
|
|
aiohttp.ServerDisconnectedError,
|
|
|
|
aiohttp.ClientConnectorError,
|
2022-09-26 01:55:58 +00:00
|
|
|
NetatmoApiError,
|
2021-05-20 12:59:19 +00:00
|
|
|
) as err:
|
|
|
|
_LOGGER.debug("Could not fetch live camera image (%s)", err)
|
|
|
|
return None
|
2020-01-11 11:20:00 +00:00
|
|
|
|
2017-01-17 07:10:18 +00:00
|
|
|
@property
|
2022-11-16 13:44:08 +00:00
|
|
|
def supported_features(self) -> CameraEntityFeature:
|
2022-09-26 01:55:58 +00:00
|
|
|
"""Return supported features."""
|
2022-11-16 13:44:08 +00:00
|
|
|
supported_features = CameraEntityFeature.ON_OFF
|
2022-09-26 01:55:58 +00:00
|
|
|
if self._model != "NDB":
|
|
|
|
supported_features |= CameraEntityFeature.STREAM
|
|
|
|
return supported_features
|
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
|
|
|
|
2021-07-21 21:36:57 +00:00
|
|
|
async def async_turn_off(self) -> None:
|
2020-08-04 18:46:46 +00:00
|
|
|
"""Turn off camera."""
|
2022-09-26 01:55:58 +00:00
|
|
|
await self._camera.async_monitoring_off()
|
2020-08-04 18:46:46 +00:00
|
|
|
|
2021-07-21 21:36:57 +00:00
|
|
|
async def async_turn_on(self) -> None:
|
2020-08-04 18:46:46 +00:00
|
|
|
"""Turn on camera."""
|
2022-09-26 01:55:58 +00:00
|
|
|
await self._camera.async_monitoring_on()
|
2020-08-04 18:46:46 +00:00
|
|
|
|
2021-07-21 21:36:57 +00:00
|
|
|
async def stream_source(self) -> str:
|
2019-04-10 23:10:14 +00:00
|
|
|
"""Return the stream source."""
|
2022-09-26 01:55:58 +00:00
|
|
|
if self._camera.is_local:
|
|
|
|
await self._camera.async_update_camera_urls()
|
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
|
|
|
|
2022-09-26 01:55:58 +00:00
|
|
|
if self._camera.local_url:
|
2023-07-23 20:00:26 +00:00
|
|
|
return f"{self._camera.local_url}/live/files/{self._quality}/index.m3u8"
|
2022-09-26 01:55:58 +00:00
|
|
|
return f"{self._camera.vpn_url}/live/files/{self._quality}/index.m3u8"
|
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
|
2021-07-21 21:36:57 +00:00
|
|
|
def async_update_callback(self) -> None:
|
2020-08-04 18:46:46 +00:00
|
|
|
"""Update the entity's state."""
|
2022-09-26 01:55:58 +00:00
|
|
|
self._attr_is_on = self._camera.alim_status is not None
|
|
|
|
self._attr_available = self._camera.alim_status is not None
|
|
|
|
|
|
|
|
if self._camera.monitoring is not None:
|
|
|
|
self._attr_is_streaming = self._camera.monitoring
|
|
|
|
self._attr_motion_detection_enabled = self._camera.monitoring
|
|
|
|
|
|
|
|
self.hass.data[DOMAIN][DATA_EVENTS][self._id] = self.process_events(
|
|
|
|
self._camera.events
|
|
|
|
)
|
2020-09-04 18:21:42 +00:00
|
|
|
|
2021-07-02 09:36:37 +00:00
|
|
|
self._attr_extra_state_attributes.update(
|
|
|
|
{
|
|
|
|
"id": self._id,
|
2022-09-26 01:55:58 +00:00
|
|
|
"monitoring": self._monitoring,
|
|
|
|
"sd_status": self._camera.sd_status,
|
|
|
|
"alim_status": self._camera.alim_status,
|
|
|
|
"is_local": self._camera.is_local,
|
|
|
|
"vpn_url": self._camera.vpn_url,
|
|
|
|
"local_url": self._camera.local_url,
|
2021-07-02 09:36:37 +00:00
|
|
|
"light_state": self._light_state,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2022-09-26 01:55:58 +00:00
|
|
|
def process_events(self, event_list: list[NaEvent]) -> dict:
|
2020-09-04 18:21:42 +00:00
|
|
|
"""Add meta data to events."""
|
2022-09-26 01:55:58 +00:00
|
|
|
events = {}
|
|
|
|
for event in event_list:
|
|
|
|
if not (video_id := event.video_id):
|
2020-09-04 18:21:42 +00:00
|
|
|
continue
|
2022-09-26 01:55:58 +00:00
|
|
|
event_data = event.__dict__
|
|
|
|
event_data["subevents"] = [
|
|
|
|
event.__dict__
|
|
|
|
for event in event_data.get("subevents", [])
|
|
|
|
if not isinstance(event, dict)
|
|
|
|
]
|
|
|
|
event_data["media_url"] = self.get_video_url(video_id)
|
|
|
|
events[event.event_time] = event_data
|
2020-09-04 18:21:42 +00:00
|
|
|
return events
|
|
|
|
|
2022-09-26 01:55:58 +00:00
|
|
|
def get_video_url(self, video_id: str) -> str:
|
|
|
|
"""Get video url."""
|
|
|
|
if self._camera.is_local:
|
|
|
|
return f"{self._camera.local_url}/vod/{video_id}/files/{self._quality}/index.m3u8"
|
|
|
|
return f"{self._camera.vpn_url}/vod/{video_id}/files/{self._quality}/index.m3u8"
|
|
|
|
|
2021-09-22 12:32:30 +00:00
|
|
|
def fetch_person_ids(self, persons: list[str | None]) -> list[str]:
|
2022-09-26 01:55:58 +00:00
|
|
|
"""Fetch matching person ids for given list of persons."""
|
2020-08-04 18:46:46 +00:00
|
|
|
person_ids = []
|
2021-09-22 12:32:30 +00:00
|
|
|
person_id_errors = []
|
|
|
|
|
2020-08-04 18:46:46 +00:00
|
|
|
for person in persons:
|
2021-09-22 12:32:30 +00:00
|
|
|
person_id = None
|
2022-09-26 01:55:58 +00:00
|
|
|
for pid, data in self._camera.home.persons.items():
|
|
|
|
if data.pseudo == person:
|
2020-08-04 18:46:46 +00:00
|
|
|
person_ids.append(pid)
|
2021-09-22 12:32:30 +00:00
|
|
|
person_id = pid
|
|
|
|
break
|
|
|
|
|
|
|
|
if person_id is None:
|
|
|
|
person_id_errors.append(person)
|
|
|
|
|
|
|
|
if person_id_errors:
|
|
|
|
raise HomeAssistantError(f"Person(s) not registered {person_id_errors}")
|
|
|
|
|
|
|
|
return person_ids
|
|
|
|
|
|
|
|
async def _service_set_persons_home(self, **kwargs: Any) -> None:
|
|
|
|
"""Service to change current home schedule."""
|
|
|
|
persons = kwargs.get(ATTR_PERSONS, [])
|
|
|
|
person_ids = self.fetch_person_ids(persons)
|
2020-08-04 18:46:46 +00:00
|
|
|
|
2022-09-26 01:55:58 +00:00
|
|
|
await self._camera.home.async_set_persons_home(person_ids=person_ids)
|
2020-08-07 07:25:59 +00:00
|
|
|
_LOGGER.debug("Set %s as at home", persons)
|
2020-08-04 18:46:46 +00:00
|
|
|
|
2021-07-21 21:36:57 +00:00
|
|
|
async def _service_set_person_away(self, **kwargs: Any) -> None:
|
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)
|
2021-09-22 12:32:30 +00:00
|
|
|
person_ids = self.fetch_person_ids([person] if person else [])
|
|
|
|
person_id = next(iter(person_ids), None)
|
2020-08-04 18:46:46 +00:00
|
|
|
|
2022-09-26 01:55:58 +00:00
|
|
|
await self._camera.home.async_set_persons_away(
|
2021-09-22 12:32:30 +00:00
|
|
|
person_id=person_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
|
|
|
|
2021-09-22 12:32:30 +00:00
|
|
|
if person_id:
|
|
|
|
_LOGGER.debug("Set %s as away %s", person, person_id)
|
2020-08-04 18:46:46 +00:00
|
|
|
else:
|
2020-08-07 07:25:59 +00:00
|
|
|
_LOGGER.debug("Set home as empty")
|
2020-08-28 21:09:07 +00:00
|
|
|
|
2021-07-21 21:36:57 +00:00
|
|
|
async def _service_set_camera_light(self, **kwargs: Any) -> None:
|
2020-08-28 21:09:07 +00:00
|
|
|
"""Service to set light mode."""
|
2022-09-26 01:55:58 +00:00
|
|
|
if not isinstance(self._camera, NaModules.netatmo.NOC):
|
|
|
|
raise HomeAssistantError(
|
|
|
|
f"{self._model} <{self._device_name}> does not have a floodlight"
|
|
|
|
)
|
|
|
|
|
2021-07-21 21:36:57 +00:00
|
|
|
mode = str(kwargs.get(ATTR_CAMERA_LIGHT_MODE))
|
|
|
|
_LOGGER.debug("Turn %s camera light for '%s'", mode, self._attr_name)
|
2022-09-26 01:55:58 +00:00
|
|
|
await self._camera.async_set_floodlight_state(mode)
|