Add button entity to Overkiz integration (#62719)
parent
f07030c425
commit
fb04b19960
|
@ -803,6 +803,7 @@ omit =
|
|||
homeassistant/components/osramlightify/light.py
|
||||
homeassistant/components/otp/sensor.py
|
||||
homeassistant/components/overkiz/__init__.py
|
||||
homeassistant/components/overkiz/button.py
|
||||
homeassistant/components/overkiz/coordinator.py
|
||||
homeassistant/components/overkiz/entity.py
|
||||
homeassistant/components/overkiz/executor.py
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
"""Support for Overkiz (virtual) buttons."""
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import HomeAssistantOverkizData
|
||||
from .const import DOMAIN, IGNORED_OVERKIZ_DEVICES
|
||||
from .entity import OverkizDescriptiveEntity
|
||||
|
||||
BUTTON_DESCRIPTIONS: list[ButtonEntityDescription] = [
|
||||
# My Position (cover, light)
|
||||
ButtonEntityDescription(
|
||||
key="my",
|
||||
name="My Position",
|
||||
icon="mdi:star",
|
||||
),
|
||||
# Identify
|
||||
ButtonEntityDescription(
|
||||
key="identify", # startIdentify and identify are reversed... Swap this when fixed in API.
|
||||
name="Start Identify",
|
||||
icon="mdi:human-greeting-variant",
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
ButtonEntityDescription(
|
||||
key="stopIdentify",
|
||||
name="Stop Identify",
|
||||
icon="mdi:human-greeting-variant",
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
ButtonEntityDescription(
|
||||
key="startIdentify", # startIdentify and identify are reversed... Swap this when fixed in API.
|
||||
name="Identify",
|
||||
icon="mdi:human-greeting-variant",
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
):
|
||||
"""Set up the Overkiz button from a config entry."""
|
||||
data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
|
||||
entities: list[ButtonEntity] = []
|
||||
|
||||
supported_commands = {
|
||||
description.key: description for description in BUTTON_DESCRIPTIONS
|
||||
}
|
||||
|
||||
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 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)
|
||||
|
||||
|
||||
class OverkizButton(OverkizDescriptiveEntity, ButtonEntity):
|
||||
"""Representation of an Overkiz Button."""
|
||||
|
||||
async def async_press(self) -> None:
|
||||
"""Handle the button press."""
|
||||
await self.executor.async_execute_command(self.entity_description.key)
|
|
@ -18,6 +18,7 @@ UPDATE_INTERVAL: Final = timedelta(seconds=30)
|
|||
UPDATE_INTERVAL_ALL_ASSUMED_STATE: Final = timedelta(minutes=60)
|
||||
|
||||
PLATFORMS: list[Platform] = [
|
||||
Platform.BUTTON,
|
||||
Platform.LOCK,
|
||||
Platform.SENSOR,
|
||||
]
|
||||
|
|
|
@ -7,6 +7,7 @@ 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.update_coordinator import CoordinatorEntity
|
||||
|
@ -99,7 +100,7 @@ class OverkizDescriptiveEntity(OverkizEntity):
|
|||
self,
|
||||
device_url: str,
|
||||
coordinator: OverkizDataUpdateCoordinator,
|
||||
description: OverkizSensorDescription,
|
||||
description: OverkizSensorDescription | ButtonEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize the device."""
|
||||
super().__init__(device_url, coordinator)
|
||||
|
|
Loading…
Reference in New Issue