mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use runtime_data in duotecno (#136444)
This commit is contained in:
parent
2e78ab620f
commit
f3e13f4662
@ -10,8 +10,6 @@ from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
PLATFORMS: list[Platform] = [
|
||||
Platform.BINARY_SENSOR,
|
||||
Platform.CLIMATE,
|
||||
@ -21,7 +19,10 @@ PLATFORMS: list[Platform] = [
|
||||
]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
type DuotecnoConfigEntry = ConfigEntry[PyDuotecno]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: DuotecnoConfigEntry) -> bool:
|
||||
"""Set up duotecno from a config entry."""
|
||||
|
||||
controller = PyDuotecno()
|
||||
@ -31,14 +32,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
)
|
||||
except (OSError, InvalidPassword, LoadFailure) as err:
|
||||
raise ConfigEntryNotReady from err
|
||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = controller
|
||||
|
||||
entry.runtime_data = controller
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: DuotecnoConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
||||
return unload_ok
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
@ -2,28 +2,25 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from duotecno.controller import PyDuotecno
|
||||
from duotecno.unit import ControlUnit, VirtualUnit
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from . import DuotecnoConfigEntry
|
||||
from .entity import DuotecnoEntity
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: DuotecnoConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up Duotecno binary sensor on config_entry."""
|
||||
cntrl: PyDuotecno = hass.data[DOMAIN][entry.entry_id]
|
||||
async_add_entities(
|
||||
DuotecnoBinarySensor(channel)
|
||||
for channel in cntrl.get_units(["ControlUnit", "VirtualUnit"])
|
||||
for channel in entry.runtime_data.get_units(["ControlUnit", "VirtualUnit"])
|
||||
)
|
||||
|
||||
|
||||
|
@ -4,7 +4,6 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Final
|
||||
|
||||
from duotecno.controller import PyDuotecno
|
||||
from duotecno.unit import SensUnit
|
||||
|
||||
from homeassistant.components.climate import (
|
||||
@ -12,12 +11,11 @@ from homeassistant.components.climate import (
|
||||
ClimateEntityFeature,
|
||||
HVACMode,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from . import DuotecnoConfigEntry
|
||||
from .entity import DuotecnoEntity, api_call
|
||||
|
||||
HVACMODE: Final = {
|
||||
@ -33,13 +31,13 @@ PRESETMODES_REVERSE: Final = {value: key for key, value in PRESETMODES.items()}
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: DuotecnoConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up Duotecno climate based on config_entry."""
|
||||
cntrl: PyDuotecno = hass.data[DOMAIN][entry.entry_id]
|
||||
async_add_entities(
|
||||
DuotecnoClimate(channel) for channel in cntrl.get_units(["SensUnit"])
|
||||
DuotecnoClimate(channel)
|
||||
for channel in entry.runtime_data.get_units(["SensUnit"])
|
||||
)
|
||||
|
||||
|
||||
|
@ -4,27 +4,25 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from duotecno.controller import PyDuotecno
|
||||
from duotecno.unit import DuoswitchUnit
|
||||
|
||||
from homeassistant.components.cover import CoverEntity, CoverEntityFeature
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from . import DuotecnoConfigEntry
|
||||
from .entity import DuotecnoEntity, api_call
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: DuotecnoConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the duoswitch endities."""
|
||||
cntrl: PyDuotecno = hass.data[DOMAIN][entry.entry_id]
|
||||
async_add_entities(
|
||||
DuotecnoCover(channel) for channel in cntrl.get_units("DuoswitchUnit")
|
||||
DuotecnoCover(channel)
|
||||
for channel in entry.runtime_data.get_units("DuoswitchUnit")
|
||||
)
|
||||
|
||||
|
||||
|
@ -2,26 +2,25 @@
|
||||
|
||||
from typing import Any
|
||||
|
||||
from duotecno.controller import PyDuotecno
|
||||
from duotecno.unit import DimUnit
|
||||
|
||||
from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from . import DuotecnoConfigEntry
|
||||
from .entity import DuotecnoEntity, api_call
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: DuotecnoConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up Duotecno light based on config_entry."""
|
||||
cntrl: PyDuotecno = hass.data[DOMAIN][entry.entry_id]
|
||||
async_add_entities(DuotecnoLight(channel) for channel in cntrl.get_units("DimUnit"))
|
||||
async_add_entities(
|
||||
DuotecnoLight(channel) for channel in entry.runtime_data.get_units("DimUnit")
|
||||
)
|
||||
|
||||
|
||||
class DuotecnoLight(DuotecnoEntity, LightEntity):
|
||||
|
@ -2,27 +2,25 @@
|
||||
|
||||
from typing import Any
|
||||
|
||||
from duotecno.controller import PyDuotecno
|
||||
from duotecno.unit import SwitchUnit
|
||||
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from . import DuotecnoConfigEntry
|
||||
from .entity import DuotecnoEntity, api_call
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: DuotecnoConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up Velbus switch based on config_entry."""
|
||||
cntrl: PyDuotecno = hass.data[DOMAIN][entry.entry_id]
|
||||
async_add_entities(
|
||||
DuotecnoSwitch(channel) for channel in cntrl.get_units("SwitchUnit")
|
||||
DuotecnoSwitch(channel)
|
||||
for channel in entry.runtime_data.get_units("SwitchUnit")
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user