Address feedback to Overkiz integration (#62841)
parent
8fd60dbd51
commit
089dcb2b22
|
@ -57,18 +57,20 @@ async def async_setup_entry(
|
|||
|
||||
for device in data.coordinator.data.values():
|
||||
if (
|
||||
device.widget not in IGNORED_OVERKIZ_DEVICES
|
||||
and device.ui_class not in IGNORED_OVERKIZ_DEVICES
|
||||
device.widget in IGNORED_OVERKIZ_DEVICES
|
||||
or device.ui_class in IGNORED_OVERKIZ_DEVICES
|
||||
):
|
||||
for command in device.definition.commands:
|
||||
if description := supported_commands.get(command.command_name):
|
||||
entities.append(
|
||||
OverkizButton(
|
||||
device.device_url,
|
||||
data.coordinator,
|
||||
description,
|
||||
)
|
||||
continue
|
||||
|
||||
for command in device.definition.commands:
|
||||
if description := supported_commands.get(command.command_name):
|
||||
entities.append(
|
||||
OverkizButton(
|
||||
device.device_url,
|
||||
data.coordinator,
|
||||
description,
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
"""Parent class for every Overkiz device."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
|
||||
from pyoverkiz.enums import OverkizAttribute, OverkizState
|
||||
from pyoverkiz.models import Device
|
||||
|
||||
from homeassistant.components.sensor import SensorEntityDescription
|
||||
from homeassistant.helpers.entity import DeviceInfo, EntityDescription
|
||||
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):
|
||||
"""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."""
|
||||
data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
entities: list[OverkizLock] = [
|
||||
async_add_entities(
|
||||
OverkizLock(device.device_url, data.coordinator)
|
||||
for device in data.platforms[Platform.LOCK]
|
||||
]
|
||||
|
||||
async_add_entities(entities)
|
||||
)
|
||||
|
||||
|
||||
class OverkizLock(OverkizEntity, LockEntity):
|
||||
"""Representation of an Overkiz Lock."""
|
||||
|
||||
async def async_lock(self, **_: Any) -> None:
|
||||
async def async_lock(self, **kwargs: Any) -> None:
|
||||
"""Lock method."""
|
||||
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."""
|
||||
await self.executor.async_execute_command(OverkizCommand.UNLOCK)
|
||||
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
"""Support for Overkiz sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
|
||||
from pyoverkiz.enums import OverkizAttribute, OverkizState, UIWidget
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
|
@ -28,7 +32,15 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||
from . import HomeAssistantOverkizData
|
||||
from .const import DOMAIN, IGNORED_OVERKIZ_DEVICES
|
||||
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] = [
|
||||
OverkizSensorDescription(
|
||||
|
@ -347,20 +359,6 @@ async def async_setup_entry(
|
|||
}
|
||||
|
||||
for device in data.coordinator.data.values():
|
||||
if (
|
||||
device.widget not in IGNORED_OVERKIZ_DEVICES
|
||||
and device.ui_class not in IGNORED_OVERKIZ_DEVICES
|
||||
):
|
||||
for state in device.definition.states:
|
||||
if description := key_supported_states.get(state.qualified_name):
|
||||
entities.append(
|
||||
OverkizStateSensor(
|
||||
device.device_url,
|
||||
data.coordinator,
|
||||
description,
|
||||
)
|
||||
)
|
||||
|
||||
if device.widget == UIWidget.HOMEKIT_STACK:
|
||||
entities.append(
|
||||
OverkizHomeKitSetupCodeSensor(
|
||||
|
@ -369,12 +367,30 @@ async def async_setup_entry(
|
|||
)
|
||||
)
|
||||
|
||||
if (
|
||||
device.widget in IGNORED_OVERKIZ_DEVICES
|
||||
or device.ui_class in IGNORED_OVERKIZ_DEVICES
|
||||
):
|
||||
continue
|
||||
|
||||
for state in device.definition.states:
|
||||
if description := key_supported_states.get(state.qualified_name):
|
||||
entities.append(
|
||||
OverkizStateSensor(
|
||||
device.device_url,
|
||||
data.coordinator,
|
||||
description,
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class OverkizStateSensor(OverkizDescriptiveEntity, SensorEntity):
|
||||
"""Representation of an Overkiz Sensor."""
|
||||
|
||||
entity_description: OverkizSensorDescription
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
"""Return the value of the sensor."""
|
||||
|
@ -384,7 +400,7 @@ class OverkizStateSensor(OverkizDescriptiveEntity, SensorEntity):
|
|||
return None
|
||||
|
||||
# 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 state.value
|
||||
|
|
Loading…
Reference in New Issue