Simplify switchbot config flow (#76272)
This commit is contained in:
parent
54fc17e10d
commit
b1497b0857
13 changed files with 412 additions and 246 deletions
|
@ -7,7 +7,6 @@ from homeassistant.components.binary_sensor import (
|
|||
BinarySensorEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_ADDRESS, CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -53,20 +52,10 @@ async def async_setup_entry(
|
|||
) -> None:
|
||||
"""Set up Switchbot curtain based on a config entry."""
|
||||
coordinator: SwitchbotDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
unique_id = entry.unique_id
|
||||
assert unique_id is not None
|
||||
async_add_entities(
|
||||
[
|
||||
SwitchBotBinarySensor(
|
||||
coordinator,
|
||||
unique_id,
|
||||
binary_sensor,
|
||||
entry.data[CONF_ADDRESS],
|
||||
entry.data[CONF_NAME],
|
||||
)
|
||||
for binary_sensor in coordinator.data["data"]
|
||||
if binary_sensor in BINARY_SENSOR_TYPES
|
||||
]
|
||||
SwitchBotBinarySensor(coordinator, binary_sensor)
|
||||
for binary_sensor in coordinator.data["data"]
|
||||
if binary_sensor in BINARY_SENSOR_TYPES
|
||||
)
|
||||
|
||||
|
||||
|
@ -78,15 +67,12 @@ class SwitchBotBinarySensor(SwitchbotEntity, BinarySensorEntity):
|
|||
def __init__(
|
||||
self,
|
||||
coordinator: SwitchbotDataUpdateCoordinator,
|
||||
unique_id: str,
|
||||
binary_sensor: str,
|
||||
mac: str,
|
||||
switchbot_name: str,
|
||||
) -> None:
|
||||
"""Initialize the Switchbot sensor."""
|
||||
super().__init__(coordinator, unique_id, mac, name=switchbot_name)
|
||||
super().__init__(coordinator)
|
||||
self._sensor = binary_sensor
|
||||
self._attr_unique_id = f"{unique_id}-{binary_sensor}"
|
||||
self._attr_unique_id = f"{coordinator.base_unique_id}-{binary_sensor}"
|
||||
self.entity_description = BINARY_SENSOR_TYPES[binary_sensor]
|
||||
self._attr_name = self.entity_description.name
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue