Add Ezviz update entity (#85377)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
c23718d13d
commit
497fa1980b
7 changed files with 114 additions and 7 deletions
|
@ -330,6 +330,7 @@ omit =
|
|||
homeassistant/components/ezviz/entity.py
|
||||
homeassistant/components/ezviz/sensor.py
|
||||
homeassistant/components/ezviz/switch.py
|
||||
homeassistant/components/ezviz/update.py
|
||||
homeassistant/components/faa_delays/__init__.py
|
||||
homeassistant/components/faa_delays/binary_sensor.py
|
||||
homeassistant/components/familyhub/camera.py
|
||||
|
|
|
@ -37,6 +37,7 @@ PLATFORMS_BY_TYPE: dict[str, list] = {
|
|||
Platform.CAMERA,
|
||||
Platform.SENSOR,
|
||||
Platform.SWITCH,
|
||||
Platform.UPDATE,
|
||||
],
|
||||
}
|
||||
|
||||
|
|
|
@ -25,10 +25,6 @@ BINARY_SENSOR_TYPES: dict[str, BinarySensorEntityDescription] = {
|
|||
key="alarm_schedules_enabled"
|
||||
),
|
||||
"encrypted": BinarySensorEntityDescription(key="encrypted"),
|
||||
"upgrade_available": BinarySensorEntityDescription(
|
||||
key="upgrade_available",
|
||||
device_class=BinarySensorDeviceClass.UPDATE,
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
"documentation": "https://www.home-assistant.io/integrations/ezviz",
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["paho_mqtt", "pyezviz"],
|
||||
"requirements": ["pyezviz==0.2.0.9"]
|
||||
"requirements": ["pyezviz==0.2.0.12"]
|
||||
}
|
||||
|
|
109
homeassistant/components/ezviz/update.py
Normal file
109
homeassistant/components/ezviz/update.py
Normal file
|
@ -0,0 +1,109 @@
|
|||
"""Support for EZVIZ sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from pyezviz import HTTPError, PyEzvizError
|
||||
|
||||
from homeassistant.components.update import (
|
||||
UpdateDeviceClass,
|
||||
UpdateEntity,
|
||||
UpdateEntityDescription,
|
||||
UpdateEntityFeature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DATA_COORDINATOR, DOMAIN
|
||||
from .coordinator import EzvizDataUpdateCoordinator
|
||||
from .entity import EzvizEntity
|
||||
|
||||
PARALLEL_UPDATES = 1
|
||||
|
||||
UPDATE_ENTITY_TYPES = UpdateEntityDescription(
|
||||
key="version",
|
||||
name="Firmware update",
|
||||
device_class=UpdateDeviceClass.FIRMWARE,
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up EZVIZ sensors based on a config entry."""
|
||||
coordinator: EzvizDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
||||
DATA_COORDINATOR
|
||||
]
|
||||
|
||||
async_add_entities(
|
||||
EzvizUpdateEntity(coordinator, camera, sensor, UPDATE_ENTITY_TYPES)
|
||||
for camera in coordinator.data
|
||||
for sensor, value in coordinator.data[camera].items()
|
||||
if sensor in UPDATE_ENTITY_TYPES.key
|
||||
if value
|
||||
)
|
||||
|
||||
|
||||
class EzvizUpdateEntity(EzvizEntity, UpdateEntity):
|
||||
"""Representation of a EZVIZ Update entity."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
_attr_supported_features = (
|
||||
UpdateEntityFeature.INSTALL
|
||||
| UpdateEntityFeature.PROGRESS
|
||||
| UpdateEntityFeature.RELEASE_NOTES
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: EzvizDataUpdateCoordinator,
|
||||
serial: str,
|
||||
sensor: str,
|
||||
description: UpdateEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator, serial)
|
||||
self._attr_unique_id = f"{serial}_{sensor}"
|
||||
self.entity_description = description
|
||||
|
||||
@property
|
||||
def installed_version(self) -> str | None:
|
||||
"""Version installed and in use."""
|
||||
return self.data["version"]
|
||||
|
||||
@property
|
||||
def in_progress(self) -> bool | int | None:
|
||||
"""Update installation progress."""
|
||||
if self.data["upgrade_in_progress"]:
|
||||
return self.data["upgrade_percent"]
|
||||
return False
|
||||
|
||||
@property
|
||||
def latest_version(self) -> str | None:
|
||||
"""Latest version available for install."""
|
||||
if self.data["upgrade_available"]:
|
||||
return self.data["latest_firmware_info"]["version"]
|
||||
|
||||
return self.installed_version
|
||||
|
||||
def release_notes(self) -> str | None:
|
||||
"""Return full release notes."""
|
||||
if self.data["latest_firmware_info"]:
|
||||
return self.data["latest_firmware_info"].get("desc")
|
||||
return None
|
||||
|
||||
async def async_install(
|
||||
self, version: str | None, backup: bool, **kwargs: Any
|
||||
) -> None:
|
||||
"""Install an update."""
|
||||
try:
|
||||
await self.hass.async_add_executor_job(
|
||||
self.coordinator.ezviz_client.upgrade_device, self._serial
|
||||
)
|
||||
|
||||
except (HTTPError, PyEzvizError) as err:
|
||||
raise HomeAssistantError(
|
||||
f"Failed to update firmware on {self.name}"
|
||||
) from err
|
|
@ -1626,7 +1626,7 @@ pyeverlights==0.1.0
|
|||
pyevilgenius==2.0.0
|
||||
|
||||
# homeassistant.components.ezviz
|
||||
pyezviz==0.2.0.9
|
||||
pyezviz==0.2.0.12
|
||||
|
||||
# homeassistant.components.fibaro
|
||||
pyfibaro==0.7.1
|
||||
|
|
|
@ -1187,7 +1187,7 @@ pyeverlights==0.1.0
|
|||
pyevilgenius==2.0.0
|
||||
|
||||
# homeassistant.components.ezviz
|
||||
pyezviz==0.2.0.9
|
||||
pyezviz==0.2.0.12
|
||||
|
||||
# homeassistant.components.fibaro
|
||||
pyfibaro==0.7.1
|
||||
|
|
Loading…
Add table
Reference in a new issue