Add number entity to Overkiz integration (#62732)
This commit is contained in:
parent
9dbba6b7f2
commit
c37077aa9b
4 changed files with 107 additions and 3 deletions
|
@ -808,6 +808,7 @@ omit =
|
|||
homeassistant/components/overkiz/entity.py
|
||||
homeassistant/components/overkiz/executor.py
|
||||
homeassistant/components/overkiz/lock.py
|
||||
homeassistant/components/overkiz/number.py
|
||||
homeassistant/components/overkiz/sensor.py
|
||||
homeassistant/components/ovo_energy/__init__.py
|
||||
homeassistant/components/ovo_energy/const.py
|
||||
|
|
|
@ -20,6 +20,7 @@ UPDATE_INTERVAL_ALL_ASSUMED_STATE: Final = timedelta(minutes=60)
|
|||
PLATFORMS: list[Platform] = [
|
||||
Platform.BUTTON,
|
||||
Platform.LOCK,
|
||||
Platform.NUMBER,
|
||||
Platform.SENSOR,
|
||||
]
|
||||
|
||||
|
|
|
@ -7,9 +7,8 @@ from dataclasses import dataclass
|
|||
from pyoverkiz.enums import OverkizAttribute, OverkizState
|
||||
from pyoverkiz.models import Device
|
||||
|
||||
from homeassistant.components.button import ButtonEntityDescription
|
||||
from homeassistant.components.sensor import SensorEntityDescription
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity import DeviceInfo, EntityDescription
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN
|
||||
|
@ -100,7 +99,7 @@ class OverkizDescriptiveEntity(OverkizEntity):
|
|||
self,
|
||||
device_url: str,
|
||||
coordinator: OverkizDataUpdateCoordinator,
|
||||
description: OverkizSensorDescription | ButtonEntityDescription,
|
||||
description: EntityDescription,
|
||||
) -> None:
|
||||
"""Initialize the device."""
|
||||
super().__init__(device_url, coordinator)
|
||||
|
|
103
homeassistant/components/overkiz/number.py
Normal file
103
homeassistant/components/overkiz/number.py
Normal file
|
@ -0,0 +1,103 @@
|
|||
"""Support for Overkiz (virtual) numbers."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from pyoverkiz.enums import OverkizCommand, OverkizState
|
||||
|
||||
from homeassistant.components.number import NumberEntity, NumberEntityDescription
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import HomeAssistantOverkizData
|
||||
from .const import DOMAIN, IGNORED_OVERKIZ_DEVICES
|
||||
from .entity import OverkizDescriptiveEntity
|
||||
|
||||
|
||||
@dataclass
|
||||
class OverkizNumberDescriptionMixin:
|
||||
"""Define an entity description mixin for number entities."""
|
||||
|
||||
command: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class OverkizNumberDescription(NumberEntityDescription, OverkizNumberDescriptionMixin):
|
||||
"""Class to describe an Overkiz number."""
|
||||
|
||||
|
||||
NUMBER_DESCRIPTIONS: list[OverkizNumberDescription] = [
|
||||
# Cover: My Position (0 - 100)
|
||||
OverkizNumberDescription(
|
||||
key=OverkizState.CORE_MEMORIZED_1_POSITION,
|
||||
name="My Position",
|
||||
icon="mdi:content-save-cog",
|
||||
command=OverkizCommand.SET_MEMORIZED_1_POSITION,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
# WaterHeater: Expected Number Of Shower (2 - 4)
|
||||
OverkizNumberDescription(
|
||||
key=OverkizState.CORE_EXPECTED_NUMBER_OF_SHOWER,
|
||||
name="Expected Number Of Shower",
|
||||
icon="mdi:shower-head",
|
||||
command=OverkizCommand.SET_EXPECTED_NUMBER_OF_SHOWER,
|
||||
min_value=2,
|
||||
max_value=4,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
):
|
||||
"""Set up the Overkiz number from a config entry."""
|
||||
data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
|
||||
entities: list[OverkizNumber] = []
|
||||
|
||||
key_supported_states = {
|
||||
description.key: description for description in NUMBER_DESCRIPTIONS
|
||||
}
|
||||
|
||||
for device in data.coordinator.data.values():
|
||||
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(
|
||||
OverkizNumber(
|
||||
device.device_url,
|
||||
data.coordinator,
|
||||
description,
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class OverkizNumber(OverkizDescriptiveEntity, NumberEntity):
|
||||
"""Representation of an Overkiz Number."""
|
||||
|
||||
entity_description: OverkizNumberDescription
|
||||
|
||||
@property
|
||||
def value(self) -> float:
|
||||
"""Return the entity value to represent the entity state."""
|
||||
if state := self.device.states.get(self.entity_description.key):
|
||||
return state.value
|
||||
|
||||
return 0
|
||||
|
||||
async def async_set_value(self, value: float) -> None:
|
||||
"""Set new value."""
|
||||
await self.executor.async_execute_command(
|
||||
self.entity_description.command, value
|
||||
)
|
Loading…
Add table
Reference in a new issue