1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-08 07:15:09 +01:00
Files
core/homeassistant/components/wmspro/button.py
T
2026-06-22 20:51:13 +02:00

60 lines
2.3 KiB
Python

"""Identify support for WMS WebControl pro."""
from typing import override
from wmspro.const import WMS_WebControl_pro_API_actionDescription
from homeassistant.components.button import ButtonDeviceClass, ButtonEntity
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from . import WebControlProConfigEntry
from .entity import WebControlProGenericEntity
async def async_setup_entry(
hass: HomeAssistant,
config_entry: WebControlProConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the WMS based identify buttons from a config entry."""
hub = config_entry.runtime_data
entities: list[WebControlProGenericEntity] = []
for d in hub.dests.values():
if d.hasAction(WMS_WebControl_pro_API_actionDescription.Identify):
entities.append(WebControlProIdentifyButton(config_entry.entry_id, d))
if d.hasAction(WMS_WebControl_pro_API_actionDescription.SlatRotate):
entities.append(WebControlProRotationResetButton(config_entry.entry_id, d))
async_add_entities(entities)
class WebControlProIdentifyButton(WebControlProGenericEntity, ButtonEntity):
"""Representation of a WMS based identify button."""
_attr_device_class = ButtonDeviceClass.IDENTIFY
@override
async def async_press(self) -> None:
"""Handle the button press to identify the device."""
action = self._dest.action(WMS_WebControl_pro_API_actionDescription.Identify)
await action()
class WebControlProRotationResetButton(WebControlProGenericEntity, ButtonEntity):
"""Representation of a WMS based reset rotation button."""
_attr_entity_category = EntityCategory.CONFIG
_attr_translation_key = "rotation-reset"
@override
async def async_press(self) -> None:
"""Handle the button press to reset the rotation range to the default."""
action = self._dest.action(WMS_WebControl_pro_API_actionDescription.SlatRotate)
# Delete the min and max override values to reset the rotation range to the default
del action["minValue"]
del action["maxValue"]
# The library will take care of the update and persistence on the next poll refresh