mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Use runtime_data in blue_current (#129084)
This commit is contained in:
parent
86c37ce192
commit
f63332a7aa
@ -22,6 +22,8 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send
|
|||||||
|
|
||||||
from .const import DOMAIN, EVSE_ID, LOGGER, MODEL_TYPE
|
from .const import DOMAIN, EVSE_ID, LOGGER, MODEL_TYPE
|
||||||
|
|
||||||
|
type BlueCurrentConfigEntry = ConfigEntry[Connector]
|
||||||
|
|
||||||
PLATFORMS = [Platform.SENSOR]
|
PLATFORMS = [Platform.SENSOR]
|
||||||
CHARGE_POINTS = "CHARGE_POINTS"
|
CHARGE_POINTS = "CHARGE_POINTS"
|
||||||
DATA = "data"
|
DATA = "data"
|
||||||
@ -32,9 +34,10 @@ OBJECT = "object"
|
|||||||
VALUE_TYPES = ["CH_STATUS"]
|
VALUE_TYPES = ["CH_STATUS"]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant, config_entry: BlueCurrentConfigEntry
|
||||||
|
) -> bool:
|
||||||
"""Set up Blue Current as a config entry."""
|
"""Set up Blue Current as a config entry."""
|
||||||
hass.data.setdefault(DOMAIN, {})
|
|
||||||
client = Client()
|
client = Client()
|
||||||
api_token = config_entry.data[CONF_API_TOKEN]
|
api_token = config_entry.data[CONF_API_TOKEN]
|
||||||
connector = Connector(hass, config_entry, client)
|
connector = Connector(hass, config_entry, client)
|
||||||
@ -50,29 +53,25 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||||||
)
|
)
|
||||||
|
|
||||||
await client.wait_for_charge_points()
|
await client.wait_for_charge_points()
|
||||||
hass.data[DOMAIN][config_entry.entry_id] = connector
|
config_entry.runtime_data = connector
|
||||||
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
async def async_unload_entry(
|
||||||
|
hass: HomeAssistant, config_entry: BlueCurrentConfigEntry
|
||||||
|
) -> bool:
|
||||||
"""Unload the Blue Current config entry."""
|
"""Unload the Blue Current config entry."""
|
||||||
|
|
||||||
unload_ok = await hass.config_entries.async_unload_platforms(
|
return await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)
|
||||||
config_entry, PLATFORMS
|
|
||||||
)
|
|
||||||
if unload_ok:
|
|
||||||
hass.data[DOMAIN].pop(config_entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
|
||||||
|
|
||||||
|
|
||||||
class Connector:
|
class Connector:
|
||||||
"""Define a class that connects to the Blue Current websocket API."""
|
"""Define a class that connects to the Blue Current websocket API."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, hass: HomeAssistant, config: ConfigEntry, client: Client
|
self, hass: HomeAssistant, config: BlueCurrentConfigEntry, client: Client
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
self.config = config
|
self.config = config
|
||||||
|
@ -8,7 +8,6 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CURRENCY_EURO,
|
CURRENCY_EURO,
|
||||||
UnitOfElectricCurrent,
|
UnitOfElectricCurrent,
|
||||||
@ -19,7 +18,7 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import Connector
|
from . import BlueCurrentConfigEntry, Connector
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .entity import BlueCurrentEntity, ChargepointEntity
|
from .entity import BlueCurrentEntity, ChargepointEntity
|
||||||
|
|
||||||
@ -211,10 +210,12 @@ PARALLEL_UPDATES = 1
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant,
|
||||||
|
entry: BlueCurrentConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up Blue Current sensors."""
|
"""Set up Blue Current sensors."""
|
||||||
connector: Connector = hass.data[DOMAIN][entry.entry_id]
|
connector = entry.runtime_data
|
||||||
sensor_list: list[SensorEntity] = [
|
sensor_list: list[SensorEntity] = [
|
||||||
ChargePointSensor(connector, sensor, evse_id)
|
ChargePointSensor(connector, sensor, evse_id)
|
||||||
for evse_id in connector.charge_points
|
for evse_id in connector.charge_points
|
||||||
|
Loading…
x
Reference in New Issue
Block a user