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:
@@ -4,73 +4,70 @@ 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.typing import ConfigType
|
||||
|
||||
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])
|
||||
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:
|
||||
entity = AirSendButton(
|
||||
hass,
|
||||
device,
|
||||
)
|
||||
async_add_entities([entity])
|
||||
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:
|
||||
"""Initialize a button."""
|
||||
def __init__(self, hass: HomeAssistant, device: Device) -> None:
|
||||
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) + "_button"
|
||||
self._available = True
|
||||
|
||||
@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
|
||||
def extra_state_attributes(self):
|
||||
"""Return the device state attributes."""
|
||||
return None
|
||||
|
||||
@property
|
||||
def assumed_state(self):
|
||||
"""Return true if unable to access real state of entity."""
|
||||
return True
|
||||
|
||||
def press(self, **kwargs: Any) -> None:
|
||||
"""Handle the button press."""
|
||||
@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"}
|
||||
if self._device.transfer(note, self.entity_id) == True:
|
||||
self.schedule_update_ha_state()
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user