hass-core/homeassistant/components/ezviz/entity.py
Renier Moorcroft 00c60151d4
Add Ezviz siren entity (#93612)
* Initial commit

* Add siren entity

* Update coveragerc

* Cleanup unused entity description.

* Add restore and fix entity property to standards.

* Schedule turn off to match camera firmware

* Only add siren for devices that support capability

* Removed unused attribute and import.

* Add translation

* Update camera.py

* Update strings.json

* Update camera.py

* Cleanup

* Update homeassistant/components/ezviz/siren.py

Co-authored-by: G Johansson <goran.johansson@shiftit.se>

* use description

* Apply suggestions from code review

Co-authored-by: G Johansson <goran.johansson@shiftit.se>

* Update strings.json

* Dont inherit coordinator class.

* Add assumed state

* Update homeassistant/components/ezviz/siren.py

Co-authored-by: G Johansson <goran.johansson@shiftit.se>

* Reset delay listener if trigered

---------

Co-authored-by: G Johansson <goran.johansson@shiftit.se>
2023-08-13 13:10:53 +02:00

73 lines
2.3 KiB
Python

"""An abstract class common to all EZVIZ entities."""
from __future__ import annotations
from typing import Any
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN, MANUFACTURER
from .coordinator import EzvizDataUpdateCoordinator
class EzvizEntity(CoordinatorEntity[EzvizDataUpdateCoordinator], Entity):
"""Generic entity encapsulating common features of EZVIZ device."""
_attr_has_entity_name = True
def __init__(
self,
coordinator: EzvizDataUpdateCoordinator,
serial: str,
) -> None:
"""Initialize the entity."""
super().__init__(coordinator)
self._serial = serial
self._camera_name = self.data["name"]
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, serial)},
connections={
(CONNECTION_NETWORK_MAC, self.data["mac_address"]),
},
manufacturer=MANUFACTURER,
model=self.data["device_sub_category"],
name=self.data["name"],
sw_version=self.data["version"],
)
@property
def data(self) -> dict[str, Any]:
"""Return coordinator data for this entity."""
return self.coordinator.data[self._serial]
class EzvizBaseEntity(Entity):
"""Generic entity for EZVIZ individual poll entities."""
_attr_has_entity_name = True
def __init__(
self,
coordinator: EzvizDataUpdateCoordinator,
serial: str,
) -> None:
"""Initialize the entity."""
self._serial = serial
self.coordinator = coordinator
self._camera_name = self.data["name"]
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, serial)},
connections={
(CONNECTION_NETWORK_MAC, self.data["mac_address"]),
},
manufacturer=MANUFACTURER,
model=self.data["device_sub_category"],
name=self.data["name"],
sw_version=self.data["version"],
)
@property
def data(self) -> dict[str, Any]:
"""Return coordinator data for this entity."""
return self.coordinator.data[self._serial]