2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Netgear Arlo IP cameras."""
|
2021-12-30 17:50:51 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from datetime import datetime, timedelta
|
2019-10-18 00:09:47 +00:00
|
|
|
import logging
|
2017-06-30 06:46:22 +00:00
|
|
|
|
2019-10-18 00:09:47 +00:00
|
|
|
from pyarlo import PyArlo
|
|
|
|
from requests.exceptions import ConnectTimeout, HTTPError
|
2017-05-31 07:25:25 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2022-01-13 07:42:50 +00:00
|
|
|
from homeassistant.components import persistent_notification
|
2019-10-18 00:09:47 +00:00
|
|
|
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
|
2021-12-31 05:17:05 +00:00
|
|
|
from homeassistant.core import HomeAssistant, ServiceCall
|
2017-06-30 06:46:22 +00:00
|
|
|
from homeassistant.helpers import config_validation as cv
|
2018-06-12 06:01:26 +00:00
|
|
|
from homeassistant.helpers.dispatcher import dispatcher_send
|
2019-10-18 00:09:47 +00:00
|
|
|
from homeassistant.helpers.event import track_time_interval
|
2021-12-31 05:17:05 +00:00
|
|
|
from homeassistant.helpers.typing import ConfigType
|
2017-05-31 07:25:25 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2019-02-14 21:09:22 +00:00
|
|
|
ATTRIBUTION = "Data provided by arlo.netgear.com"
|
2017-05-31 07:25:25 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
DATA_ARLO = "data_arlo"
|
|
|
|
DEFAULT_BRAND = "Netgear Arlo"
|
|
|
|
DOMAIN = "arlo"
|
2017-05-31 07:25:25 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
NOTIFICATION_ID = "arlo_notification"
|
|
|
|
NOTIFICATION_TITLE = "Arlo Component Setup"
|
2017-05-31 07:25:25 +00:00
|
|
|
|
2018-06-12 06:01:26 +00:00
|
|
|
SCAN_INTERVAL = timedelta(seconds=60)
|
|
|
|
|
|
|
|
SIGNAL_UPDATE_ARLO = "arlo_update"
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
CONFIG_SCHEMA = vol.Schema(
|
|
|
|
{
|
|
|
|
DOMAIN: vol.Schema(
|
|
|
|
{
|
|
|
|
vol.Required(CONF_USERNAME): cv.string,
|
|
|
|
vol.Required(CONF_PASSWORD): cv.string,
|
|
|
|
vol.Optional(CONF_SCAN_INTERVAL, default=SCAN_INTERVAL): cv.time_period,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
extra=vol.ALLOW_EXTRA,
|
|
|
|
)
|
2017-05-31 07:25:25 +00:00
|
|
|
|
|
|
|
|
2021-12-31 05:17:05 +00:00
|
|
|
def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
2017-05-31 07:25:25 +00:00
|
|
|
"""Set up an Arlo component."""
|
|
|
|
conf = config[DOMAIN]
|
2020-04-07 20:45:56 +00:00
|
|
|
username = conf[CONF_USERNAME]
|
|
|
|
password = conf[CONF_PASSWORD]
|
|
|
|
scan_interval = conf[CONF_SCAN_INTERVAL]
|
2017-05-31 07:25:25 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
arlo = PyArlo(username, password, preload=False)
|
|
|
|
if not arlo.is_connected:
|
|
|
|
return False
|
2018-06-12 06:01:26 +00:00
|
|
|
|
|
|
|
# assign refresh period to base station thread
|
2019-07-31 19:25:30 +00:00
|
|
|
arlo_base_station = next((station for station in arlo.base_stations), None)
|
2018-06-12 06:01:26 +00:00
|
|
|
|
2018-09-11 09:25:38 +00:00
|
|
|
if arlo_base_station is not None:
|
|
|
|
arlo_base_station.refresh_rate = scan_interval.total_seconds()
|
|
|
|
elif not arlo.cameras:
|
2020-07-05 21:04:19 +00:00
|
|
|
_LOGGER.error("No Arlo camera or base station available")
|
2018-06-12 06:01:26 +00:00
|
|
|
return False
|
|
|
|
|
2017-06-30 06:46:22 +00:00
|
|
|
hass.data[DATA_ARLO] = arlo
|
2018-06-12 06:01:26 +00:00
|
|
|
|
2017-05-31 07:25:25 +00:00
|
|
|
except (ConnectTimeout, HTTPError) as ex:
|
2018-01-29 22:37:19 +00:00
|
|
|
_LOGGER.error("Unable to connect to Netgear Arlo: %s", str(ex))
|
2022-01-13 07:42:50 +00:00
|
|
|
persistent_notification.create(
|
|
|
|
hass,
|
2020-02-23 21:38:05 +00:00
|
|
|
f"Error: {ex}<br />You will need to restart hass after fixing.",
|
2017-05-31 07:25:25 +00:00
|
|
|
title=NOTIFICATION_TITLE,
|
2019-07-31 19:25:30 +00:00
|
|
|
notification_id=NOTIFICATION_ID,
|
|
|
|
)
|
2017-05-31 07:25:25 +00:00
|
|
|
return False
|
2018-06-12 06:01:26 +00:00
|
|
|
|
2021-12-30 17:50:51 +00:00
|
|
|
def hub_refresh(_: ServiceCall | datetime) -> None:
|
2018-06-12 06:01:26 +00:00
|
|
|
"""Call ArloHub to refresh information."""
|
2018-10-21 17:54:51 +00:00
|
|
|
_LOGGER.debug("Updating Arlo Hub component")
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.data[DATA_ARLO].update(update_cameras=True, update_base_station=True)
|
2018-06-12 06:01:26 +00:00
|
|
|
dispatcher_send(hass, SIGNAL_UPDATE_ARLO)
|
|
|
|
|
|
|
|
# register service
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.services.register(DOMAIN, "update", hub_refresh)
|
2018-06-12 06:01:26 +00:00
|
|
|
|
|
|
|
# register scan interval for ArloHub
|
|
|
|
track_time_interval(hass, hub_refresh, scan_interval)
|
2017-05-31 07:25:25 +00:00
|
|
|
return True
|