mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
Wallbox Integration - Type Config Entry (#148594)
This commit is contained in:
parent
5a4c837328
commit
22828568e2
@ -4,13 +4,17 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from wallbox import Wallbox
|
from wallbox import Wallbox
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||||
|
|
||||||
from .const import UPDATE_INTERVAL
|
from .const import UPDATE_INTERVAL
|
||||||
from .coordinator import InvalidAuth, WallboxCoordinator, async_validate_input
|
from .coordinator import (
|
||||||
|
InvalidAuth,
|
||||||
|
WallboxConfigEntry,
|
||||||
|
WallboxCoordinator,
|
||||||
|
async_validate_input,
|
||||||
|
)
|
||||||
|
|
||||||
PLATFORMS = [
|
PLATFORMS = [
|
||||||
Platform.LOCK,
|
Platform.LOCK,
|
||||||
@ -20,8 +24,6 @@ PLATFORMS = [
|
|||||||
Platform.SWITCH,
|
Platform.SWITCH,
|
||||||
]
|
]
|
||||||
|
|
||||||
type WallboxConfigEntry = ConfigEntry[WallboxCoordinator]
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: WallboxConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: WallboxConfigEntry) -> bool:
|
||||||
"""Set up Wallbox from a config entry."""
|
"""Set up Wallbox from a config entry."""
|
||||||
@ -45,6 +47,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: WallboxConfigEntry) -> b
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: WallboxConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
@ -77,6 +77,8 @@ CHARGER_STATUS: dict[int, ChargerStatus] = {
|
|||||||
210: ChargerStatus.LOCKED_CAR_CONNECTED,
|
210: ChargerStatus.LOCKED_CAR_CONNECTED,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type WallboxConfigEntry = ConfigEntry[WallboxCoordinator]
|
||||||
|
|
||||||
|
|
||||||
def _require_authentication[_WallboxCoordinatorT: WallboxCoordinator, **_P](
|
def _require_authentication[_WallboxCoordinatorT: WallboxCoordinator, **_P](
|
||||||
func: Callable[Concatenate[_WallboxCoordinatorT, _P], Any],
|
func: Callable[Concatenate[_WallboxCoordinatorT, _P], Any],
|
||||||
@ -118,10 +120,10 @@ async def async_validate_input(hass: HomeAssistant, wallbox: Wallbox) -> None:
|
|||||||
class WallboxCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
class WallboxCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||||
"""Wallbox Coordinator class."""
|
"""Wallbox Coordinator class."""
|
||||||
|
|
||||||
config_entry: ConfigEntry
|
config_entry: WallboxConfigEntry
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, hass: HomeAssistant, config_entry: ConfigEntry, wallbox: Wallbox
|
self, hass: HomeAssistant, config_entry: WallboxConfigEntry, wallbox: Wallbox
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
self._station = config_entry.data[CONF_STATION]
|
self._station = config_entry.data[CONF_STATION]
|
||||||
|
@ -5,7 +5,6 @@ from __future__ import annotations
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.lock import LockEntity, LockEntityDescription
|
from homeassistant.components.lock import LockEntity, LockEntityDescription
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
@ -14,7 +13,7 @@ from .const import (
|
|||||||
CHARGER_LOCKED_UNLOCKED_KEY,
|
CHARGER_LOCKED_UNLOCKED_KEY,
|
||||||
CHARGER_SERIAL_NUMBER_KEY,
|
CHARGER_SERIAL_NUMBER_KEY,
|
||||||
)
|
)
|
||||||
from .coordinator import WallboxCoordinator
|
from .coordinator import WallboxConfigEntry, WallboxCoordinator
|
||||||
from .entity import WallboxEntity
|
from .entity import WallboxEntity
|
||||||
|
|
||||||
LOCK_TYPES: dict[str, LockEntityDescription] = {
|
LOCK_TYPES: dict[str, LockEntityDescription] = {
|
||||||
@ -27,7 +26,7 @@ LOCK_TYPES: dict[str, LockEntityDescription] = {
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: WallboxConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Create wallbox lock entities in HASS."""
|
"""Create wallbox lock entities in HASS."""
|
||||||
|
@ -10,7 +10,6 @@ from dataclasses import dataclass
|
|||||||
from typing import cast
|
from typing import cast
|
||||||
|
|
||||||
from homeassistant.components.number import NumberEntity, NumberEntityDescription
|
from homeassistant.components.number import NumberEntity, NumberEntityDescription
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
@ -24,7 +23,7 @@ from .const import (
|
|||||||
CHARGER_PART_NUMBER_KEY,
|
CHARGER_PART_NUMBER_KEY,
|
||||||
CHARGER_SERIAL_NUMBER_KEY,
|
CHARGER_SERIAL_NUMBER_KEY,
|
||||||
)
|
)
|
||||||
from .coordinator import WallboxCoordinator
|
from .coordinator import WallboxConfigEntry, WallboxCoordinator
|
||||||
from .entity import WallboxEntity
|
from .entity import WallboxEntity
|
||||||
|
|
||||||
|
|
||||||
@ -79,7 +78,7 @@ NUMBER_TYPES: dict[str, WallboxNumberEntityDescription] = {
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: WallboxConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Create wallbox number entities in HASS."""
|
"""Create wallbox number entities in HASS."""
|
||||||
@ -103,7 +102,7 @@ class WallboxNumber(WallboxEntity, NumberEntity):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: WallboxCoordinator,
|
coordinator: WallboxCoordinator,
|
||||||
entry: ConfigEntry,
|
entry: WallboxConfigEntry,
|
||||||
description: WallboxNumberEntityDescription,
|
description: WallboxNumberEntityDescription,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize a Wallbox number entity."""
|
"""Initialize a Wallbox number entity."""
|
||||||
|
@ -8,7 +8,6 @@ from dataclasses import dataclass
|
|||||||
from requests import HTTPError
|
from requests import HTTPError
|
||||||
|
|
||||||
from homeassistant.components.select import SelectEntity, SelectEntityDescription
|
from homeassistant.components.select import SelectEntity, SelectEntityDescription
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
@ -23,7 +22,7 @@ from .const import (
|
|||||||
DOMAIN,
|
DOMAIN,
|
||||||
EcoSmartMode,
|
EcoSmartMode,
|
||||||
)
|
)
|
||||||
from .coordinator import WallboxCoordinator
|
from .coordinator import WallboxConfigEntry, WallboxCoordinator
|
||||||
from .entity import WallboxEntity
|
from .entity import WallboxEntity
|
||||||
|
|
||||||
|
|
||||||
@ -58,7 +57,7 @@ SELECT_TYPES: dict[str, WallboxSelectEntityDescription] = {
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: WallboxConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Create wallbox select entities in HASS."""
|
"""Create wallbox select entities in HASS."""
|
||||||
|
@ -11,7 +11,6 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
UnitOfElectricCurrent,
|
UnitOfElectricCurrent,
|
||||||
@ -44,7 +43,7 @@ from .const import (
|
|||||||
CHARGER_STATE_OF_CHARGE_KEY,
|
CHARGER_STATE_OF_CHARGE_KEY,
|
||||||
CHARGER_STATUS_DESCRIPTION_KEY,
|
CHARGER_STATUS_DESCRIPTION_KEY,
|
||||||
)
|
)
|
||||||
from .coordinator import WallboxCoordinator
|
from .coordinator import WallboxConfigEntry, WallboxCoordinator
|
||||||
from .entity import WallboxEntity
|
from .entity import WallboxEntity
|
||||||
|
|
||||||
|
|
||||||
@ -169,7 +168,7 @@ SENSOR_TYPES: dict[str, WallboxSensorEntityDescription] = {
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: WallboxConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Create wallbox sensor entities in HASS."""
|
"""Create wallbox sensor entities in HASS."""
|
||||||
|
@ -5,7 +5,6 @@ from __future__ import annotations
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
|
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
@ -16,7 +15,7 @@ from .const import (
|
|||||||
CHARGER_STATUS_DESCRIPTION_KEY,
|
CHARGER_STATUS_DESCRIPTION_KEY,
|
||||||
ChargerStatus,
|
ChargerStatus,
|
||||||
)
|
)
|
||||||
from .coordinator import WallboxCoordinator
|
from .coordinator import WallboxConfigEntry, WallboxCoordinator
|
||||||
from .entity import WallboxEntity
|
from .entity import WallboxEntity
|
||||||
|
|
||||||
SWITCH_TYPES: dict[str, SwitchEntityDescription] = {
|
SWITCH_TYPES: dict[str, SwitchEntityDescription] = {
|
||||||
@ -29,7 +28,7 @@ SWITCH_TYPES: dict[str, SwitchEntityDescription] = {
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: WallboxConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Create wallbox sensor entities in HASS."""
|
"""Create wallbox sensor entities in HASS."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user