Address feedback to Overkiz integration (#62841)
This commit is contained in:
parent
8fd60dbd51
commit
089dcb2b22
4 changed files with 48 additions and 45 deletions
|
@ -57,9 +57,11 @@ async def async_setup_entry(
|
||||||
|
|
||||||
for device in data.coordinator.data.values():
|
for device in data.coordinator.data.values():
|
||||||
if (
|
if (
|
||||||
device.widget not in IGNORED_OVERKIZ_DEVICES
|
device.widget in IGNORED_OVERKIZ_DEVICES
|
||||||
and device.ui_class not in IGNORED_OVERKIZ_DEVICES
|
or device.ui_class in IGNORED_OVERKIZ_DEVICES
|
||||||
):
|
):
|
||||||
|
continue
|
||||||
|
|
||||||
for command in device.definition.commands:
|
for command in device.definition.commands:
|
||||||
if description := supported_commands.get(command.command_name):
|
if description := supported_commands.get(command.command_name):
|
||||||
entities.append(
|
entities.append(
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
"""Parent class for every Overkiz device."""
|
"""Parent class for every Overkiz device."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Callable
|
|
||||||
from dataclasses import dataclass
|
|
||||||
|
|
||||||
from pyoverkiz.enums import OverkizAttribute, OverkizState
|
from pyoverkiz.enums import OverkizAttribute, OverkizState
|
||||||
from pyoverkiz.models import Device
|
from pyoverkiz.models import Device
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntityDescription
|
|
||||||
from homeassistant.helpers.entity import DeviceInfo, EntityDescription
|
from homeassistant.helpers.entity import DeviceInfo, EntityDescription
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
@ -83,15 +79,6 @@ class OverkizEntity(CoordinatorEntity):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class OverkizSensorDescription(SensorEntityDescription):
|
|
||||||
"""Class to describe an Overkiz sensor."""
|
|
||||||
|
|
||||||
native_value: Callable[
|
|
||||||
[str | int | float], str | int | float
|
|
||||||
] | None = lambda val: val
|
|
||||||
|
|
||||||
|
|
||||||
class OverkizDescriptiveEntity(OverkizEntity):
|
class OverkizDescriptiveEntity(OverkizEntity):
|
||||||
"""Representation of a Overkiz device entity based on a description."""
|
"""Representation of a Overkiz device entity based on a description."""
|
||||||
|
|
||||||
|
|
|
@ -24,22 +24,20 @@ async def async_setup_entry(
|
||||||
"""Set up the Overkiz locks from a config entry."""
|
"""Set up the Overkiz locks from a config entry."""
|
||||||
data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
|
data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
|
||||||
entities: list[OverkizLock] = [
|
async_add_entities(
|
||||||
OverkizLock(device.device_url, data.coordinator)
|
OverkizLock(device.device_url, data.coordinator)
|
||||||
for device in data.platforms[Platform.LOCK]
|
for device in data.platforms[Platform.LOCK]
|
||||||
]
|
)
|
||||||
|
|
||||||
async_add_entities(entities)
|
|
||||||
|
|
||||||
|
|
||||||
class OverkizLock(OverkizEntity, LockEntity):
|
class OverkizLock(OverkizEntity, LockEntity):
|
||||||
"""Representation of an Overkiz Lock."""
|
"""Representation of an Overkiz Lock."""
|
||||||
|
|
||||||
async def async_lock(self, **_: Any) -> None:
|
async def async_lock(self, **kwargs: Any) -> None:
|
||||||
"""Lock method."""
|
"""Lock method."""
|
||||||
await self.executor.async_execute_command(OverkizCommand.LOCK)
|
await self.executor.async_execute_command(OverkizCommand.LOCK)
|
||||||
|
|
||||||
async def async_unlock(self, **_: Any) -> None:
|
async def async_unlock(self, **kwargs: Any) -> None:
|
||||||
"""Unlock method."""
|
"""Unlock method."""
|
||||||
await self.executor.async_execute_command(OverkizCommand.UNLOCK)
|
await self.executor.async_execute_command(OverkizCommand.UNLOCK)
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
"""Support for Overkiz sensors."""
|
"""Support for Overkiz sensors."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from pyoverkiz.enums import OverkizAttribute, OverkizState, UIWidget
|
from pyoverkiz.enums import OverkizAttribute, OverkizState, UIWidget
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
|
SensorEntityDescription,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
@ -28,7 +32,15 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from . import HomeAssistantOverkizData
|
from . import HomeAssistantOverkizData
|
||||||
from .const import DOMAIN, IGNORED_OVERKIZ_DEVICES
|
from .const import DOMAIN, IGNORED_OVERKIZ_DEVICES
|
||||||
from .coordinator import OverkizDataUpdateCoordinator
|
from .coordinator import OverkizDataUpdateCoordinator
|
||||||
from .entity import OverkizDescriptiveEntity, OverkizEntity, OverkizSensorDescription
|
from .entity import OverkizDescriptiveEntity, OverkizEntity
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class OverkizSensorDescription(SensorEntityDescription):
|
||||||
|
"""Class to describe an Overkiz sensor."""
|
||||||
|
|
||||||
|
native_value: Callable[[str | int | float], str | int | float] | None = None
|
||||||
|
|
||||||
|
|
||||||
SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
|
SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
|
||||||
OverkizSensorDescription(
|
OverkizSensorDescription(
|
||||||
|
@ -347,10 +359,20 @@ async def async_setup_entry(
|
||||||
}
|
}
|
||||||
|
|
||||||
for device in data.coordinator.data.values():
|
for device in data.coordinator.data.values():
|
||||||
|
if device.widget == UIWidget.HOMEKIT_STACK:
|
||||||
|
entities.append(
|
||||||
|
OverkizHomeKitSetupCodeSensor(
|
||||||
|
device.device_url,
|
||||||
|
data.coordinator,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
device.widget not in IGNORED_OVERKIZ_DEVICES
|
device.widget in IGNORED_OVERKIZ_DEVICES
|
||||||
and device.ui_class not in IGNORED_OVERKIZ_DEVICES
|
or device.ui_class in IGNORED_OVERKIZ_DEVICES
|
||||||
):
|
):
|
||||||
|
continue
|
||||||
|
|
||||||
for state in device.definition.states:
|
for state in device.definition.states:
|
||||||
if description := key_supported_states.get(state.qualified_name):
|
if description := key_supported_states.get(state.qualified_name):
|
||||||
entities.append(
|
entities.append(
|
||||||
|
@ -361,20 +383,14 @@ async def async_setup_entry(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if device.widget == UIWidget.HOMEKIT_STACK:
|
|
||||||
entities.append(
|
|
||||||
OverkizHomeKitSetupCodeSensor(
|
|
||||||
device.device_url,
|
|
||||||
data.coordinator,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
class OverkizStateSensor(OverkizDescriptiveEntity, SensorEntity):
|
class OverkizStateSensor(OverkizDescriptiveEntity, SensorEntity):
|
||||||
"""Representation of an Overkiz Sensor."""
|
"""Representation of an Overkiz Sensor."""
|
||||||
|
|
||||||
|
entity_description: OverkizSensorDescription
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
"""Return the value of the sensor."""
|
"""Return the value of the sensor."""
|
||||||
|
@ -384,7 +400,7 @@ class OverkizStateSensor(OverkizDescriptiveEntity, SensorEntity):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Transform the value with a lambda function
|
# Transform the value with a lambda function
|
||||||
if hasattr(self.entity_description, "native_value"):
|
if self.entity_description.native_value:
|
||||||
return self.entity_description.native_value(state.value)
|
return self.entity_description.native_value(state.value)
|
||||||
|
|
||||||
return state.value
|
return state.value
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue