* feat: migrate to config flow with device registry and brand icons - Migrate all platforms to async_setup_entry (config flow) - Each device now appears as a real HA device in the device registry - Add device_info to all entities (cover, switch, button, sensor, binary_sensor) - Add config_flow.py with airsend.yaml + !secret resolution - Add strings.json for UI labels - Fix unique_id bug (was splitting each character of the name) - Split binary_sensor.py from sensor.py - Bump version to 4.0 * Add icon for local brand * Revise installation steps for AirSend integration * Correction du crash websocket raise Exception remplacé par return False * Update README with AirSend configuration steps Added instructions for configuring AirSend in Home Assistant. * Update README with clearer instructions for YAML Clarified instructions for editing the airsend.yaml file. * Add files via upload * Add English translation for AirSend configuration * Add fr translations * Update screenshot following latest version * Fixe unavailable and new type light Corrections de bugs 500 avec wait: true non fatal Nouveau type light.py — lumière dimmable (type 4100)
74 lines
2.0 KiB
Python
74 lines
2.0 KiB
Python
"""AirSend buttons."""
|
|
from typing import Any
|
|
|
|
from .device import Device
|
|
|
|
from homeassistant.components.button import ButtonEntity
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity import DeviceInfo
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
from homeassistant.const import CONF_INTERNAL_URL
|
|
|
|
from . import DOMAIN
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
entry: ConfigEntry,
|
|
async_add_entities: AddEntitiesCallback,
|
|
) -> None:
|
|
internal_url = entry.data.get(CONF_INTERNAL_URL, "")
|
|
devices_config = entry.data.get("devices", {})
|
|
entities = []
|
|
for name, options in devices_config.items():
|
|
device = Device(name, options, internal_url)
|
|
if device.is_button:
|
|
entities.append(AirSendButton(hass, device))
|
|
async_add_entities(entities)
|
|
|
|
|
|
class AirSendButton(ButtonEntity):
|
|
"""Representation of an AirSend Button."""
|
|
|
|
def __init__(self, hass: HomeAssistant, device: Device) -> None:
|
|
self._device = device
|
|
self._unique_id = DOMAIN + "_" + str(device.unique_channel_name) + "_button"
|
|
self._available = True
|
|
|
|
@property
|
|
def unique_id(self):
|
|
return self._unique_id
|
|
|
|
@property
|
|
def available(self):
|
|
return self._available
|
|
|
|
@property
|
|
def should_poll(self):
|
|
return False
|
|
|
|
@property
|
|
def name(self):
|
|
return self._device.name
|
|
|
|
@property
|
|
def extra_state_attributes(self):
|
|
return None
|
|
|
|
@property
|
|
def assumed_state(self):
|
|
return True
|
|
|
|
@property
|
|
def device_info(self) -> DeviceInfo:
|
|
return self._device.device_info
|
|
|
|
async def async_press(self, **kwargs: Any) -> None:
|
|
note = {"method": 1, "type": 0, "value": "TOGGLE"}
|
|
result = await self._device.async_transfer(note, self.entity_id)
|
|
available = result is not False
|
|
if self._available != available:
|
|
self._available = available
|
|
self.async_write_ha_state()
|