feat: complete migration to config flow and bugfixes (@38decibel)

* 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)
This commit is contained in:
38decibel
2026-03-31 18:02:14 +02:00
committed by GitHub
parent 50c9b382cc
commit 7009d6ee89
17 changed files with 905 additions and 483 deletions
+49 -80
View File
@@ -1,93 +1,60 @@
"""AirSend switches."""
"""AirSend covers."""
from typing import Any
from .device import Device
from homeassistant.components.cover import CoverEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.const import CONF_DEVICES, CONF_INTERNAL_URL
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_platform(
hass: HomeAssistant, config: ConfigType, async_add_entities, discovery_info=None
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
if discovery_info is None:
return
for name, options in discovery_info[CONF_DEVICES].items():
device = Device(name, options, discovery_info[CONF_INTERNAL_URL])
"""Set up AirSend covers from a config entry."""
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_cover:
entity = AirSendCover(
hass,
device,
)
async_add_entities([entity])
entities.append(AirSendCover(hass, device))
async_add_entities(entities)
class AirSendCover(CoverEntity, RestoreEntity):
class AirSendCover(CoverEntity):
"""Representation of an AirSend Cover."""
def __init__(
self,
hass: HomeAssistant,
device: Device,
) -> None:
"""Initialize a cover device."""
def __init__(self, hass: HomeAssistant, device: Device) -> None:
self._hass = hass
self._device = device
uname = DOMAIN + device.name
self._unique_id = "_".join(x for x in uname)
self._unique_id = DOMAIN + "_" + str(device.unique_channel_name) + "_cover"
self._closed = None
self._available = True
if device.is_cover_with_position:
self._attr_current_cover_position = 50
async def async_added_to_hass(self):
"""Restore last known state when added to hass."""
await super().async_added_to_hass()
# Get the last known state
last_state = await self.async_get_last_state()
if last_state:
# Restore position for covers with position support (type 4099)
if self._device.is_cover_with_position:
# Try to restore position from attributes
if last_state.attributes.get('current_position') is not None:
self._attr_current_cover_position = last_state.attributes['current_position']
# Override position based on state if fully open/closed
if last_state.state == 'closed':
self._attr_current_cover_position = 0
elif last_state.state == 'open':
self._attr_current_cover_position = 100
# Restore closed/open state for all covers
if last_state.state == 'closed':
self._closed = True
elif last_state.state == 'open':
self._closed = False
# If no last_state, keep the defaults (50% for position covers)
@property
def unique_id(self):
"""Return unique identifier of remote device."""
return self._unique_id
@property
def available(self):
return True
return self._available
@property
def should_poll(self):
"""No polling needed."""
return False
@property
def name(self):
"""Return the name of the device if any."""
return self._device.name
@property
@@ -96,55 +63,57 @@ class AirSendCover(CoverEntity, RestoreEntity):
@property
def assumed_state(self):
"""Return true if unable to access real state of entity."""
return True
@property
def device_info(self) -> DeviceInfo:
return self._device.device_info
@property
def is_closed(self):
"""Return if the cover is closed."""
if self._device.is_async and self._hass:
component = self._hass.states.get(self.entity_id)
if component is not None:
if component.state == 'open' or component.state == 'on' or component.state == 'up':
self._closed = False
else:
self._closed = True
self._closed = component.state not in ('open', 'on', 'up')
return self._closed
def open_cover(self, **kwargs: Any) -> None:
"""Open the cover."""
async def _send(self, note: dict) -> bool:
"""Send a command and update availability accordingly."""
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()
return result is not False
async def async_open_cover(self, **kwargs: Any) -> None:
note = {"method": 1, "type": 0, "value": "UP"}
if self._device.transfer(note, self.entity_id) == True:
if await self._send(note):
self._closed = False
if self._device.is_cover_with_position:
self._attr_current_cover_position = 100
self.schedule_update_ha_state()
self.async_write_ha_state()
def close_cover(self, **kwargs: Any) -> None:
"""Close cover."""
async def async_close_cover(self, **kwargs: Any) -> None:
note = {"method": 1, "type": 0, "value": "DOWN"}
if self._device.transfer(note, self.entity_id) == True:
if await self._send(note):
self._closed = True
if self._device.is_cover_with_position:
self._attr_current_cover_position = 0
self.schedule_update_ha_state()
self.async_write_ha_state()
def stop_cover(self, **kwargs):
"""Stop the cover."""
async def async_stop_cover(self, **kwargs: Any) -> None:
note = {"method": 1, "type": 0, "value": "STOP"}
if self._device.transfer(note, self.entity_id) == True:
if await self._send(note):
self._closed = False
if self._device.is_cover_with_position:
self._attr_current_cover_position = 50
self.schedule_update_ha_state()
self.async_write_ha_state()
def set_cover_position(self, **kwargs):
"""Move the cover to a specific position."""
async def async_set_cover_position(self, **kwargs: Any) -> None:
position = int(kwargs["position"])
note = {"method": 1, "type": 9, "value": position}
if self._device.transfer(note, self.entity_id) == True:
if await self._send(note):
self._attr_current_cover_position = position
self._closed = False
if self._attr_current_cover_position == 0:
self._closed = True
self.schedule_update_ha_state()
self._closed = position == 0
self.async_write_ha_state()