mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Use runtime_data in ezviz (#136702)
This commit is contained in:
parent
6ad4dfc070
commit
edac4b83d9
@ -11,7 +11,6 @@ from pyezviz.exceptions import (
|
|||||||
PyEzvizError,
|
PyEzvizError,
|
||||||
)
|
)
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import CONF_TIMEOUT, CONF_TYPE, CONF_URL, Platform
|
from homeassistant.const import CONF_TIMEOUT, CONF_TYPE, CONF_URL, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
@ -22,12 +21,11 @@ from .const import (
|
|||||||
CONF_FFMPEG_ARGUMENTS,
|
CONF_FFMPEG_ARGUMENTS,
|
||||||
CONF_RFSESSION_ID,
|
CONF_RFSESSION_ID,
|
||||||
CONF_SESSION_ID,
|
CONF_SESSION_ID,
|
||||||
DATA_COORDINATOR,
|
|
||||||
DEFAULT_FFMPEG_ARGUMENTS,
|
DEFAULT_FFMPEG_ARGUMENTS,
|
||||||
DEFAULT_TIMEOUT,
|
DEFAULT_TIMEOUT,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
from .coordinator import EzvizDataUpdateCoordinator
|
from .coordinator import EzvizConfigEntry, EzvizDataUpdateCoordinator
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -50,9 +48,8 @@ PLATFORMS_BY_TYPE: dict[str, list] = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: EzvizConfigEntry) -> bool:
|
||||||
"""Set up EZVIZ from a config entry."""
|
"""Set up EZVIZ from a config entry."""
|
||||||
hass.data.setdefault(DOMAIN, {})
|
|
||||||
sensor_type: str = entry.data[CONF_TYPE]
|
sensor_type: str = entry.data[CONF_TYPE]
|
||||||
ezviz_client = None
|
ezviz_client = None
|
||||||
|
|
||||||
@ -90,20 +87,20 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
raise ConfigEntryNotReady from error
|
raise ConfigEntryNotReady from error
|
||||||
|
|
||||||
coordinator = EzvizDataUpdateCoordinator(
|
coordinator = EzvizDataUpdateCoordinator(
|
||||||
hass, api=ezviz_client, api_timeout=entry.options[CONF_TIMEOUT]
|
hass, entry, api=ezviz_client, api_timeout=entry.options[CONF_TIMEOUT]
|
||||||
)
|
)
|
||||||
|
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
hass.data[DOMAIN][entry.entry_id] = {DATA_COORDINATOR: coordinator}
|
entry.runtime_data = coordinator
|
||||||
|
|
||||||
entry.async_on_unload(entry.add_update_listener(_async_update_listener))
|
entry.async_on_unload(entry.add_update_listener(_async_update_listener))
|
||||||
|
|
||||||
# Check EZVIZ cloud account entity is present, reload cloud account entities for camera entity change to take effect.
|
# Check EZVIZ cloud account entity is present, reload cloud account entities for camera entity change to take effect.
|
||||||
# Cameras are accessed via local RTSP stream with unique credentials per camera.
|
# Cameras are accessed via local RTSP stream with unique credentials per camera.
|
||||||
# Separate camera entities allow for credential changes per camera.
|
# Separate camera entities allow for credential changes per camera.
|
||||||
if sensor_type == ATTR_TYPE_CAMERA and hass.data[DOMAIN]:
|
if sensor_type == ATTR_TYPE_CAMERA:
|
||||||
for item in hass.config_entries.async_entries(domain=DOMAIN):
|
for item in hass.config_entries.async_loaded_entries(domain=DOMAIN):
|
||||||
if item.data.get(CONF_TYPE) == ATTR_TYPE_CLOUD:
|
if item.data.get(CONF_TYPE) == ATTR_TYPE_CLOUD:
|
||||||
_LOGGER.debug("Reload Ezviz main account with camera entry")
|
_LOGGER.debug("Reload Ezviz main account with camera entry")
|
||||||
await hass.config_entries.async_reload(item.entry_id)
|
await hass.config_entries.async_reload(item.entry_id)
|
||||||
@ -116,19 +113,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: EzvizConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
sensor_type = entry.data[CONF_TYPE]
|
sensor_type = entry.data[CONF_TYPE]
|
||||||
|
|
||||||
unload_ok = await hass.config_entries.async_unload_platforms(
|
return await hass.config_entries.async_unload_platforms(
|
||||||
entry, PLATFORMS_BY_TYPE[sensor_type]
|
entry, PLATFORMS_BY_TYPE[sensor_type]
|
||||||
)
|
)
|
||||||
if sensor_type == ATTR_TYPE_CLOUD and unload_ok:
|
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
|
||||||
|
|
||||||
|
|
||||||
async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
async def _async_update_listener(hass: HomeAssistant, entry: EzvizConfigEntry) -> None:
|
||||||
"""Handle options update."""
|
"""Handle options update."""
|
||||||
await hass.config_entries.async_reload(entry.entry_id)
|
await hass.config_entries.async_reload(entry.entry_id)
|
||||||
|
@ -15,14 +15,13 @@ from homeassistant.components.alarm_control_panel import (
|
|||||||
AlarmControlPanelEntityFeature,
|
AlarmControlPanelEntityFeature,
|
||||||
AlarmControlPanelState,
|
AlarmControlPanelState,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DATA_COORDINATOR, DOMAIN, MANUFACTURER
|
from .const import DOMAIN, MANUFACTURER
|
||||||
from .coordinator import EzvizDataUpdateCoordinator
|
from .coordinator import EzvizConfigEntry, EzvizDataUpdateCoordinator
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -49,12 +48,12 @@ ALARM_TYPE = EzvizAlarmControlPanelEntityDescription(
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant,
|
||||||
|
entry: EzvizConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up Ezviz alarm control panel."""
|
"""Set up Ezviz alarm control panel."""
|
||||||
coordinator: EzvizDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
coordinator = entry.runtime_data
|
||||||
DATA_COORDINATOR
|
|
||||||
]
|
|
||||||
|
|
||||||
device_info = DeviceInfo(
|
device_info = DeviceInfo(
|
||||||
identifiers={(DOMAIN, entry.unique_id)}, # type: ignore[arg-type]
|
identifiers={(DOMAIN, entry.unique_id)}, # type: ignore[arg-type]
|
||||||
|
@ -7,12 +7,10 @@ from homeassistant.components.binary_sensor import (
|
|||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
BinarySensorEntityDescription,
|
BinarySensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DATA_COORDINATOR, DOMAIN
|
from .coordinator import EzvizConfigEntry, EzvizDataUpdateCoordinator
|
||||||
from .coordinator import EzvizDataUpdateCoordinator
|
|
||||||
from .entity import EzvizEntity
|
from .entity import EzvizEntity
|
||||||
|
|
||||||
PARALLEL_UPDATES = 1
|
PARALLEL_UPDATES = 1
|
||||||
@ -34,12 +32,12 @@ BINARY_SENSOR_TYPES: dict[str, BinarySensorEntityDescription] = {
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant,
|
||||||
|
entry: EzvizConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up EZVIZ sensors based on a config entry."""
|
"""Set up EZVIZ sensors based on a config entry."""
|
||||||
coordinator: EzvizDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
coordinator = entry.runtime_data
|
||||||
DATA_COORDINATOR
|
|
||||||
]
|
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
|
@ -11,13 +11,11 @@ from pyezviz.constants import SupportExt
|
|||||||
from pyezviz.exceptions import HTTPError, PyEzvizError
|
from pyezviz.exceptions import HTTPError, PyEzvizError
|
||||||
|
|
||||||
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
|
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DATA_COORDINATOR, DOMAIN
|
from .coordinator import EzvizConfigEntry, EzvizDataUpdateCoordinator
|
||||||
from .coordinator import EzvizDataUpdateCoordinator
|
|
||||||
from .entity import EzvizEntity
|
from .entity import EzvizEntity
|
||||||
|
|
||||||
PARALLEL_UPDATES = 1
|
PARALLEL_UPDATES = 1
|
||||||
@ -68,12 +66,12 @@ BUTTON_ENTITIES = (
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant,
|
||||||
|
entry: EzvizConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up EZVIZ button based on a config entry."""
|
"""Set up EZVIZ button based on a config entry."""
|
||||||
coordinator: EzvizDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
coordinator = entry.runtime_data
|
||||||
DATA_COORDINATOR
|
|
||||||
]
|
|
||||||
|
|
||||||
# Add button entities if supportExt value indicates PTZ capbility.
|
# Add button entities if supportExt value indicates PTZ capbility.
|
||||||
# Could be missing or "0" for unsupported.
|
# Could be missing or "0" for unsupported.
|
||||||
|
@ -10,11 +10,7 @@ from homeassistant.components import ffmpeg
|
|||||||
from homeassistant.components.camera import Camera, CameraEntityFeature
|
from homeassistant.components.camera import Camera, CameraEntityFeature
|
||||||
from homeassistant.components.ffmpeg import get_ffmpeg_manager
|
from homeassistant.components.ffmpeg import get_ffmpeg_manager
|
||||||
from homeassistant.components.stream import CONF_USE_WALLCLOCK_AS_TIMESTAMPS
|
from homeassistant.components.stream import CONF_USE_WALLCLOCK_AS_TIMESTAMPS
|
||||||
from homeassistant.config_entries import (
|
from homeassistant.config_entries import SOURCE_IGNORE, SOURCE_INTEGRATION_DISCOVERY
|
||||||
SOURCE_IGNORE,
|
|
||||||
SOURCE_INTEGRATION_DISCOVERY,
|
|
||||||
ConfigEntry,
|
|
||||||
)
|
|
||||||
from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import discovery_flow
|
from homeassistant.helpers import discovery_flow
|
||||||
@ -26,26 +22,25 @@ from homeassistant.helpers.entity_platform import (
|
|||||||
from .const import (
|
from .const import (
|
||||||
ATTR_SERIAL,
|
ATTR_SERIAL,
|
||||||
CONF_FFMPEG_ARGUMENTS,
|
CONF_FFMPEG_ARGUMENTS,
|
||||||
DATA_COORDINATOR,
|
|
||||||
DEFAULT_CAMERA_USERNAME,
|
DEFAULT_CAMERA_USERNAME,
|
||||||
DEFAULT_FFMPEG_ARGUMENTS,
|
DEFAULT_FFMPEG_ARGUMENTS,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_WAKE_DEVICE,
|
SERVICE_WAKE_DEVICE,
|
||||||
)
|
)
|
||||||
from .coordinator import EzvizDataUpdateCoordinator
|
from .coordinator import EzvizConfigEntry, EzvizDataUpdateCoordinator
|
||||||
from .entity import EzvizEntity
|
from .entity import EzvizEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant,
|
||||||
|
entry: EzvizConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up EZVIZ cameras based on a config entry."""
|
"""Set up EZVIZ cameras based on a config entry."""
|
||||||
|
|
||||||
coordinator: EzvizDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
coordinator = entry.runtime_data
|
||||||
DATA_COORDINATOR
|
|
||||||
]
|
|
||||||
|
|
||||||
camera_entities = []
|
camera_entities = []
|
||||||
|
|
||||||
|
@ -17,12 +17,7 @@ from pyezviz.exceptions import (
|
|||||||
from pyezviz.test_cam_rtsp import TestRTSPAuth
|
from pyezviz.test_cam_rtsp import TestRTSPAuth
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import (
|
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult, OptionsFlow
|
||||||
ConfigEntry,
|
|
||||||
ConfigFlow,
|
|
||||||
ConfigFlowResult,
|
|
||||||
OptionsFlow,
|
|
||||||
)
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_CUSTOMIZE,
|
CONF_CUSTOMIZE,
|
||||||
CONF_IP_ADDRESS,
|
CONF_IP_ADDRESS,
|
||||||
@ -48,6 +43,7 @@ from .const import (
|
|||||||
EU_URL,
|
EU_URL,
|
||||||
RUSSIA_URL,
|
RUSSIA_URL,
|
||||||
)
|
)
|
||||||
|
from .coordinator import EzvizConfigEntry
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
DEFAULT_OPTIONS = {
|
DEFAULT_OPTIONS = {
|
||||||
@ -148,7 +144,9 @@ class EzvizConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@callback
|
@callback
|
||||||
def async_get_options_flow(config_entry: ConfigEntry) -> EzvizOptionsFlowHandler:
|
def async_get_options_flow(
|
||||||
|
config_entry: EzvizConfigEntry,
|
||||||
|
) -> EzvizOptionsFlowHandler:
|
||||||
"""Get the options flow for this handler."""
|
"""Get the options flow for this handler."""
|
||||||
return EzvizOptionsFlowHandler()
|
return EzvizOptionsFlowHandler()
|
||||||
|
|
||||||
|
@ -33,6 +33,3 @@ RUSSIA_URL = "apirus.ezvizru.com"
|
|||||||
DEFAULT_CAMERA_USERNAME = "admin"
|
DEFAULT_CAMERA_USERNAME = "admin"
|
||||||
DEFAULT_TIMEOUT = 25
|
DEFAULT_TIMEOUT = 25
|
||||||
DEFAULT_FFMPEG_ARGUMENTS = ""
|
DEFAULT_FFMPEG_ARGUMENTS = ""
|
||||||
|
|
||||||
# Data
|
|
||||||
DATA_COORDINATOR = "coordinator"
|
|
||||||
|
@ -13,6 +13,7 @@ from pyezviz.exceptions import (
|
|||||||
PyEzvizError,
|
PyEzvizError,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
@ -21,19 +22,32 @@ from .const import DOMAIN
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
type EzvizConfigEntry = ConfigEntry[EzvizDataUpdateCoordinator]
|
||||||
|
|
||||||
|
|
||||||
class EzvizDataUpdateCoordinator(DataUpdateCoordinator):
|
class EzvizDataUpdateCoordinator(DataUpdateCoordinator):
|
||||||
"""Class to manage fetching EZVIZ data."""
|
"""Class to manage fetching EZVIZ data."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, hass: HomeAssistant, *, api: EzvizClient, api_timeout: int
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entry: EzvizConfigEntry,
|
||||||
|
*,
|
||||||
|
api: EzvizClient,
|
||||||
|
api_timeout: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize global EZVIZ data updater."""
|
"""Initialize global EZVIZ data updater."""
|
||||||
self.ezviz_client = api
|
self.ezviz_client = api
|
||||||
self._api_timeout = api_timeout
|
self._api_timeout = api_timeout
|
||||||
update_interval = timedelta(seconds=30)
|
update_interval = timedelta(seconds=30)
|
||||||
|
|
||||||
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=update_interval)
|
super().__init__(
|
||||||
|
hass,
|
||||||
|
_LOGGER,
|
||||||
|
config_entry=entry,
|
||||||
|
name=DOMAIN,
|
||||||
|
update_interval=update_interval,
|
||||||
|
)
|
||||||
|
|
||||||
async def _async_update_data(self) -> dict:
|
async def _async_update_data(self) -> dict:
|
||||||
"""Fetch data from EZVIZ."""
|
"""Fetch data from EZVIZ."""
|
||||||
|
@ -8,14 +8,14 @@ from pyezviz.exceptions import PyEzvizError
|
|||||||
from pyezviz.utils import decrypt_image
|
from pyezviz.utils import decrypt_image
|
||||||
|
|
||||||
from homeassistant.components.image import Image, ImageEntity, ImageEntityDescription
|
from homeassistant.components.image import Image, ImageEntity, ImageEntityDescription
|
||||||
from homeassistant.config_entries import SOURCE_IGNORE, ConfigEntry
|
from homeassistant.config_entries import SOURCE_IGNORE
|
||||||
from homeassistant.const import CONF_PASSWORD
|
from homeassistant.const import CONF_PASSWORD
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from .const import DATA_COORDINATOR, DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import EzvizDataUpdateCoordinator
|
from .coordinator import EzvizConfigEntry, EzvizDataUpdateCoordinator
|
||||||
from .entity import EzvizEntity
|
from .entity import EzvizEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -27,13 +27,13 @@ IMAGE_TYPE = ImageEntityDescription(
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant,
|
||||||
|
entry: EzvizConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up EZVIZ image entities based on a config entry."""
|
"""Set up EZVIZ image entities based on a config entry."""
|
||||||
|
|
||||||
coordinator: EzvizDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
coordinator = entry.runtime_data
|
||||||
DATA_COORDINATOR
|
|
||||||
]
|
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
EzvizLastMotion(hass, coordinator, camera) for camera in coordinator.data
|
EzvizLastMotion(hass, coordinator, camera) for camera in coordinator.data
|
||||||
|
@ -8,7 +8,6 @@ from pyezviz.constants import DeviceCatagories, DeviceSwitchType, SupportExt
|
|||||||
from pyezviz.exceptions import HTTPError, PyEzvizError
|
from pyezviz.exceptions import HTTPError, PyEzvizError
|
||||||
|
|
||||||
from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity
|
from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@ -17,8 +16,7 @@ from homeassistant.util.percentage import (
|
|||||||
ranged_value_to_percentage,
|
ranged_value_to_percentage,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import DATA_COORDINATOR, DOMAIN
|
from .coordinator import EzvizConfigEntry, EzvizDataUpdateCoordinator
|
||||||
from .coordinator import EzvizDataUpdateCoordinator
|
|
||||||
from .entity import EzvizEntity
|
from .entity import EzvizEntity
|
||||||
|
|
||||||
PARALLEL_UPDATES = 1
|
PARALLEL_UPDATES = 1
|
||||||
@ -26,12 +24,12 @@ BRIGHTNESS_RANGE = (1, 255)
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant,
|
||||||
|
entry: EzvizConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up EZVIZ lights based on a config entry."""
|
"""Set up EZVIZ lights based on a config entry."""
|
||||||
coordinator: EzvizDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
coordinator = entry.runtime_data
|
||||||
DATA_COORDINATOR
|
|
||||||
]
|
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
EzvizLight(coordinator, camera)
|
EzvizLight(coordinator, camera)
|
||||||
|
@ -16,14 +16,12 @@ from pyezviz.exceptions import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from homeassistant.components.number import NumberEntity, NumberEntityDescription
|
from homeassistant.components.number import NumberEntity, NumberEntityDescription
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import EntityCategory
|
from homeassistant.const import EntityCategory
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DATA_COORDINATOR, DOMAIN
|
from .coordinator import EzvizConfigEntry, EzvizDataUpdateCoordinator
|
||||||
from .coordinator import EzvizDataUpdateCoordinator
|
|
||||||
from .entity import EzvizBaseEntity
|
from .entity import EzvizBaseEntity
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=3600)
|
SCAN_INTERVAL = timedelta(seconds=3600)
|
||||||
@ -51,12 +49,12 @@ NUMBER_TYPE = EzvizNumberEntityDescription(
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant,
|
||||||
|
entry: EzvizConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up EZVIZ sensors based on a config entry."""
|
"""Set up EZVIZ sensors based on a config entry."""
|
||||||
coordinator: EzvizDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
coordinator = entry.runtime_data
|
||||||
DATA_COORDINATOR
|
|
||||||
]
|
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
EzvizNumber(coordinator, camera, value, entry.entry_id)
|
EzvizNumber(coordinator, camera, value, entry.entry_id)
|
||||||
|
@ -8,14 +8,12 @@ from pyezviz.constants import DeviceSwitchType, SoundMode
|
|||||||
from pyezviz.exceptions import HTTPError, PyEzvizError
|
from pyezviz.exceptions import HTTPError, PyEzvizError
|
||||||
|
|
||||||
from homeassistant.components.select import SelectEntity, SelectEntityDescription
|
from homeassistant.components.select import SelectEntity, SelectEntityDescription
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import EntityCategory
|
from homeassistant.const import EntityCategory
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DATA_COORDINATOR, DOMAIN
|
from .coordinator import EzvizConfigEntry, EzvizDataUpdateCoordinator
|
||||||
from .coordinator import EzvizDataUpdateCoordinator
|
|
||||||
from .entity import EzvizEntity
|
from .entity import EzvizEntity
|
||||||
|
|
||||||
PARALLEL_UPDATES = 1
|
PARALLEL_UPDATES = 1
|
||||||
@ -38,12 +36,12 @@ SELECT_TYPE = EzvizSelectEntityDescription(
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant,
|
||||||
|
entry: EzvizConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up EZVIZ select entities based on a config entry."""
|
"""Set up EZVIZ select entities based on a config entry."""
|
||||||
coordinator: EzvizDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
coordinator = entry.runtime_data
|
||||||
DATA_COORDINATOR
|
|
||||||
]
|
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
EzvizSelect(coordinator, camera)
|
EzvizSelect(coordinator, camera)
|
||||||
|
@ -7,13 +7,11 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import PERCENTAGE
|
from homeassistant.const import PERCENTAGE
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DATA_COORDINATOR, DOMAIN
|
from .coordinator import EzvizConfigEntry, EzvizDataUpdateCoordinator
|
||||||
from .coordinator import EzvizDataUpdateCoordinator
|
|
||||||
from .entity import EzvizEntity
|
from .entity import EzvizEntity
|
||||||
|
|
||||||
PARALLEL_UPDATES = 1
|
PARALLEL_UPDATES = 1
|
||||||
@ -72,12 +70,12 @@ SENSOR_TYPES: dict[str, SensorEntityDescription] = {
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant,
|
||||||
|
entry: EzvizConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up EZVIZ sensors based on a config entry."""
|
"""Set up EZVIZ sensors based on a config entry."""
|
||||||
coordinator: EzvizDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
coordinator = entry.runtime_data
|
||||||
DATA_COORDINATOR
|
|
||||||
]
|
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
|
@ -13,7 +13,6 @@ from homeassistant.components.siren import (
|
|||||||
SirenEntityDescription,
|
SirenEntityDescription,
|
||||||
SirenEntityFeature,
|
SirenEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import STATE_ON
|
from homeassistant.const import STATE_ON
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
@ -21,8 +20,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
import homeassistant.helpers.event as evt
|
import homeassistant.helpers.event as evt
|
||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
|
|
||||||
from .const import DATA_COORDINATOR, DOMAIN
|
from .coordinator import EzvizConfigEntry, EzvizDataUpdateCoordinator
|
||||||
from .coordinator import EzvizDataUpdateCoordinator
|
|
||||||
from .entity import EzvizBaseEntity
|
from .entity import EzvizBaseEntity
|
||||||
|
|
||||||
PARALLEL_UPDATES = 1
|
PARALLEL_UPDATES = 1
|
||||||
@ -35,12 +33,12 @@ SIREN_ENTITY_TYPE = SirenEntityDescription(
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant,
|
||||||
|
entry: EzvizConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up EZVIZ sensors based on a config entry."""
|
"""Set up EZVIZ sensors based on a config entry."""
|
||||||
coordinator: EzvizDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
coordinator = entry.runtime_data
|
||||||
DATA_COORDINATOR
|
|
||||||
]
|
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
EzvizSirenEntity(coordinator, camera, SIREN_ENTITY_TYPE)
|
EzvizSirenEntity(coordinator, camera, SIREN_ENTITY_TYPE)
|
||||||
|
@ -13,13 +13,11 @@ from homeassistant.components.switch import (
|
|||||||
SwitchEntity,
|
SwitchEntity,
|
||||||
SwitchEntityDescription,
|
SwitchEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DATA_COORDINATOR, DOMAIN
|
from .coordinator import EzvizConfigEntry, EzvizDataUpdateCoordinator
|
||||||
from .coordinator import EzvizDataUpdateCoordinator
|
|
||||||
from .entity import EzvizEntity
|
from .entity import EzvizEntity
|
||||||
|
|
||||||
|
|
||||||
@ -107,12 +105,12 @@ SWITCH_TYPES: dict[int, EzvizSwitchEntityDescription] = {
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant,
|
||||||
|
entry: EzvizConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up EZVIZ switch based on a config entry."""
|
"""Set up EZVIZ switch based on a config entry."""
|
||||||
coordinator: EzvizDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
coordinator = entry.runtime_data
|
||||||
DATA_COORDINATOR
|
|
||||||
]
|
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
EzvizSwitch(coordinator, camera, switch_number)
|
EzvizSwitch(coordinator, camera, switch_number)
|
||||||
|
@ -12,13 +12,11 @@ from homeassistant.components.update import (
|
|||||||
UpdateEntityDescription,
|
UpdateEntityDescription,
|
||||||
UpdateEntityFeature,
|
UpdateEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DATA_COORDINATOR, DOMAIN
|
from .coordinator import EzvizConfigEntry, EzvizDataUpdateCoordinator
|
||||||
from .coordinator import EzvizDataUpdateCoordinator
|
|
||||||
from .entity import EzvizEntity
|
from .entity import EzvizEntity
|
||||||
|
|
||||||
PARALLEL_UPDATES = 1
|
PARALLEL_UPDATES = 1
|
||||||
@ -30,12 +28,12 @@ UPDATE_ENTITY_TYPES = UpdateEntityDescription(
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant,
|
||||||
|
entry: EzvizConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up EZVIZ sensors based on a config entry."""
|
"""Set up EZVIZ sensors based on a config entry."""
|
||||||
coordinator: EzvizDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
coordinator = entry.runtime_data
|
||||||
DATA_COORDINATOR
|
|
||||||
]
|
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
EzvizUpdateEntity(coordinator, camera, sensor, UPDATE_ENTITY_TYPES)
|
EzvizUpdateEntity(coordinator, camera, sensor, UPDATE_ENTITY_TYPES)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user