* 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)
62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
"""AirSend binary sensors — state monitoring for AirSend boxes (type 0)."""
|
|
import logging
|
|
|
|
from homeassistant.components.binary_sensor import BinarySensorEntity, BinarySensorDeviceClass
|
|
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.helpers.update_coordinator import CoordinatorEntity
|
|
|
|
from .coordinator import AirSendCoordinator
|
|
from . import DOMAIN
|
|
|
|
_LOGGER = logging.getLogger(DOMAIN)
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
entry: ConfigEntry,
|
|
async_add_entities: AddEntitiesCallback,
|
|
) -> None:
|
|
coordinators: dict[str, AirSendCoordinator] = (
|
|
hass.data[DOMAIN][entry.entry_id]["coordinators"]
|
|
)
|
|
entities = []
|
|
for name, coordinator in coordinators.items():
|
|
if coordinator.device.is_airsend:
|
|
entities.append(AirSendStateSensor(coordinator))
|
|
async_add_entities(entities)
|
|
|
|
|
|
class AirSendStateSensor(CoordinatorEntity, BinarySensorEntity):
|
|
"""Binary sensor representing the running state of an AirSend box."""
|
|
|
|
def __init__(self, coordinator: AirSendCoordinator) -> None:
|
|
super().__init__(coordinator)
|
|
self._unique_id = DOMAIN + "_" + str(coordinator.device.unique_channel_name) + "_state"
|
|
|
|
@property
|
|
def unique_id(self):
|
|
return self._unique_id
|
|
|
|
@property
|
|
def name(self):
|
|
return self.coordinator.device.name + "_state"
|
|
|
|
@property
|
|
def device_class(self) -> BinarySensorDeviceClass:
|
|
return BinarySensorDeviceClass.RUNNING
|
|
|
|
@property
|
|
def available(self) -> bool:
|
|
return self.coordinator.data.get("available", True)
|
|
|
|
@property
|
|
def is_on(self) -> bool | None:
|
|
return self.coordinator.data.get("available", True)
|
|
|
|
@property
|
|
def device_info(self) -> DeviceInfo:
|
|
return self.coordinator.device.device_info
|