mirror of
https://github.com/Andre0512/hon.git
synced 2025-05-13 06:34:22 -04:00
Rename repo
This commit is contained in:
parent
9d8b17b2cf
commit
03a1e40b6e
14 changed files with 7 additions and 6 deletions
59
custom_components/hon/button.py
Normal file
59
custom_components/hon/button.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
from pyhon import HonConnection
|
||||
from pyhon.device import HonDevice
|
||||
|
||||
from homeassistant.components.button import ButtonEntityDescription, ButtonEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
|
||||
from .const import DOMAIN
|
||||
from .hon import HonCoordinator, HonEntity
|
||||
|
||||
BUTTONS: dict[str, tuple[ButtonEntityDescription, ...]] = {
|
||||
"WM": (
|
||||
ButtonEntityDescription(
|
||||
key="pauseProgram",
|
||||
name="Pause Program",
|
||||
icon="mdi:pause",
|
||||
),
|
||||
ButtonEntityDescription(
|
||||
key="resumeProgram",
|
||||
name="Resume Program",
|
||||
icon="mdi:play-pause",
|
||||
),
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> None:
|
||||
hon: HonConnection = hass.data[DOMAIN][entry.unique_id]
|
||||
coordinators = hass.data[DOMAIN]["coordinators"]
|
||||
appliances = []
|
||||
for device in hon.devices:
|
||||
if device.mac_address in coordinators:
|
||||
coordinator = hass.data[DOMAIN]["coordinators"][device.mac_address]
|
||||
else:
|
||||
coordinator = HonCoordinator(hass, device)
|
||||
hass.data[DOMAIN]["coordinators"][device.mac_address] = coordinator
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
if descriptions := BUTTONS.get(device.appliance_type_name):
|
||||
for description in descriptions:
|
||||
if not device.commands.get(description.key):
|
||||
continue
|
||||
appliances.extend([
|
||||
HonButtonEntity(hass, coordinator, entry, device, description)]
|
||||
)
|
||||
|
||||
async_add_entities(appliances)
|
||||
|
||||
|
||||
class HonButtonEntity(HonEntity, ButtonEntity):
|
||||
def __init__(self, hass, coordinator, entry, device: HonDevice, description) -> None:
|
||||
super().__init__(hass, entry, coordinator, device)
|
||||
|
||||
self._coordinator = coordinator
|
||||
self._device = device
|
||||
self.entity_description = description
|
||||
self._attr_unique_id = f"{super().unique_id}{description.key}"
|
||||
|
||||
async def async_press(self) -> None:
|
||||
await self._device.commands[self.entity_description.key].send()
|
Loading…
Add table
Add a link
Reference in a new issue