mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Migrate smappee to use runtime_data (#125529)
This commit is contained in:
parent
26ac8e35cb
commit
8b8083a639
@ -25,6 +25,8 @@ from .const import (
|
|||||||
TOKEN_URL,
|
TOKEN_URL,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type SmappeeConfigEntry = ConfigEntry[SmappeeBase]
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
DOMAIN: vol.Schema(
|
DOMAIN: vol.Schema(
|
||||||
@ -72,7 +74,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: SmappeeConfigEntry) -> bool:
|
||||||
"""Set up Smappee from a zeroconf or config entry."""
|
"""Set up Smappee from a zeroconf or config entry."""
|
||||||
if CONF_IP_ADDRESS in entry.data:
|
if CONF_IP_ADDRESS in entry.data:
|
||||||
if helper.is_smappee_genius(entry.data[CONF_SERIALNUMBER]):
|
if helper.is_smappee_genius(entry.data[CONF_SERIALNUMBER]):
|
||||||
@ -103,31 +105,28 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
smappee = Smappee(api=smappee_api)
|
smappee = Smappee(api=smappee_api)
|
||||||
await hass.async_add_executor_job(smappee.load_service_locations)
|
await hass.async_add_executor_job(smappee.load_service_locations)
|
||||||
|
|
||||||
hass.data[DOMAIN][entry.entry_id] = SmappeeBase(hass, smappee)
|
entry.runtime_data = SmappeeBase(hass, smappee)
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: SmappeeConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
if unload_ok:
|
|
||||||
hass.data[DOMAIN].pop(entry.entry_id, None)
|
|
||||||
return unload_ok
|
|
||||||
|
|
||||||
|
|
||||||
class SmappeeBase:
|
class SmappeeBase:
|
||||||
"""An object to hold the PySmappee instance."""
|
"""An object to hold the PySmappee instance."""
|
||||||
|
|
||||||
def __init__(self, hass, smappee):
|
def __init__(self, hass: HomeAssistant, smappee: Smappee) -> None:
|
||||||
"""Initialize the Smappee API wrapper class."""
|
"""Initialize the Smappee API wrapper class."""
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self.smappee = smappee
|
self.smappee = smappee
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
async def async_update(self):
|
async def async_update(self) -> None:
|
||||||
"""Update all Smappee trends and appliance states."""
|
"""Update all Smappee trends and appliance states."""
|
||||||
await self.hass.async_add_executor_job(
|
await self.hass.async_add_executor_job(
|
||||||
self.smappee.update_trends_and_appliance_states
|
self.smappee.update_trends_and_appliance_states
|
||||||
|
@ -6,11 +6,11 @@ from homeassistant.components.binary_sensor import (
|
|||||||
BinarySensorDeviceClass,
|
BinarySensorDeviceClass,
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
from . import SmappeeConfigEntry
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
BINARY_SENSOR_PREFIX = "Appliance"
|
BINARY_SENSOR_PREFIX = "Appliance"
|
||||||
@ -36,11 +36,11 @@ ICON_MAPPING = {
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: SmappeeConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Smappee binary sensor."""
|
"""Set up the Smappee binary sensor."""
|
||||||
smappee_base = hass.data[DOMAIN][config_entry.entry_id]
|
smappee_base = config_entry.runtime_data
|
||||||
|
|
||||||
entities: list[BinarySensorEntity] = []
|
entities: list[BinarySensorEntity] = []
|
||||||
for service_location in smappee_base.smappee.service_locations.values():
|
for service_location in smappee_base.smappee.service_locations.values():
|
||||||
|
@ -10,12 +10,12 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import UnitOfElectricPotential, UnitOfEnergy, UnitOfPower
|
from homeassistant.const import UnitOfElectricPotential, UnitOfEnergy, UnitOfPower
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
from . import SmappeeConfigEntry
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
@ -188,11 +188,11 @@ VOLTAGE_SENSORS: tuple[SmappeeVoltageSensorEntityDescription, ...] = (
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: SmappeeConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Smappee sensor."""
|
"""Set up the Smappee sensor."""
|
||||||
smappee_base = hass.data[DOMAIN][config_entry.entry_id]
|
smappee_base = config_entry.runtime_data
|
||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
for service_location in smappee_base.smappee.service_locations.values():
|
for service_location in smappee_base.smappee.service_locations.values():
|
||||||
|
@ -3,11 +3,11 @@
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity
|
from homeassistant.components.switch import SwitchEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
from . import SmappeeConfigEntry
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
SWITCH_PREFIX = "Switch"
|
SWITCH_PREFIX = "Switch"
|
||||||
@ -15,11 +15,11 @@ SWITCH_PREFIX = "Switch"
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: SmappeeConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Smappee Comfort Plugs."""
|
"""Set up the Smappee Comfort Plugs."""
|
||||||
smappee_base = hass.data[DOMAIN][config_entry.entry_id]
|
smappee_base = config_entry.runtime_data
|
||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
for service_location in smappee_base.smappee.service_locations.values():
|
for service_location in smappee_base.smappee.service_locations.values():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user