Wallbox Integration - Type Config Entry (#148594)

This commit is contained in:
Hessel 2025-07-11 11:37:24 +02:00 committed by GitHub
parent 5a4c837328
commit 22828568e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 22 additions and 23 deletions

View File

@ -4,13 +4,17 @@ from __future__ import annotations
from wallbox import Wallbox
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed
from .const import UPDATE_INTERVAL
from .coordinator import InvalidAuth, WallboxCoordinator, async_validate_input
from .coordinator import (
InvalidAuth,
WallboxConfigEntry,
WallboxCoordinator,
async_validate_input,
)
PLATFORMS = [
Platform.LOCK,
@ -20,8 +24,6 @@ PLATFORMS = [
Platform.SWITCH,
]
type WallboxConfigEntry = ConfigEntry[WallboxCoordinator]
async def async_setup_entry(hass: HomeAssistant, entry: WallboxConfigEntry) -> bool:
"""Set up Wallbox from a config entry."""
@ -45,6 +47,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: WallboxConfigEntry) -> b
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."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)

View File

@ -77,6 +77,8 @@ CHARGER_STATUS: dict[int, ChargerStatus] = {
210: ChargerStatus.LOCKED_CAR_CONNECTED,
}
type WallboxConfigEntry = ConfigEntry[WallboxCoordinator]
def _require_authentication[_WallboxCoordinatorT: WallboxCoordinator, **_P](
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]]):
"""Wallbox Coordinator class."""
config_entry: ConfigEntry
config_entry: WallboxConfigEntry
def __init__(
self, hass: HomeAssistant, config_entry: ConfigEntry, wallbox: Wallbox
self, hass: HomeAssistant, config_entry: WallboxConfigEntry, wallbox: Wallbox
) -> None:
"""Initialize."""
self._station = config_entry.data[CONF_STATION]

View File

@ -5,7 +5,6 @@ from __future__ import annotations
from typing import Any
from homeassistant.components.lock import LockEntity, LockEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
@ -14,7 +13,7 @@ from .const import (
CHARGER_LOCKED_UNLOCKED_KEY,
CHARGER_SERIAL_NUMBER_KEY,
)
from .coordinator import WallboxCoordinator
from .coordinator import WallboxConfigEntry, WallboxCoordinator
from .entity import WallboxEntity
LOCK_TYPES: dict[str, LockEntityDescription] = {
@ -27,7 +26,7 @@ LOCK_TYPES: dict[str, LockEntityDescription] = {
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
entry: WallboxConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Create wallbox lock entities in HASS."""

View File

@ -10,7 +10,6 @@ from dataclasses import dataclass
from typing import cast
from homeassistant.components.number import NumberEntity, NumberEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
@ -24,7 +23,7 @@ from .const import (
CHARGER_PART_NUMBER_KEY,
CHARGER_SERIAL_NUMBER_KEY,
)
from .coordinator import WallboxCoordinator
from .coordinator import WallboxConfigEntry, WallboxCoordinator
from .entity import WallboxEntity
@ -79,7 +78,7 @@ NUMBER_TYPES: dict[str, WallboxNumberEntityDescription] = {
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
entry: WallboxConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Create wallbox number entities in HASS."""
@ -103,7 +102,7 @@ class WallboxNumber(WallboxEntity, NumberEntity):
def __init__(
self,
coordinator: WallboxCoordinator,
entry: ConfigEntry,
entry: WallboxConfigEntry,
description: WallboxNumberEntityDescription,
) -> None:
"""Initialize a Wallbox number entity."""

View File

@ -8,7 +8,6 @@ from dataclasses import dataclass
from requests import HTTPError
from homeassistant.components.select import SelectEntity, SelectEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
@ -23,7 +22,7 @@ from .const import (
DOMAIN,
EcoSmartMode,
)
from .coordinator import WallboxCoordinator
from .coordinator import WallboxConfigEntry, WallboxCoordinator
from .entity import WallboxEntity
@ -58,7 +57,7 @@ SELECT_TYPES: dict[str, WallboxSelectEntityDescription] = {
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
entry: WallboxConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Create wallbox select entities in HASS."""

View File

@ -11,7 +11,6 @@ from homeassistant.components.sensor import (
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
PERCENTAGE,
UnitOfElectricCurrent,
@ -44,7 +43,7 @@ from .const import (
CHARGER_STATE_OF_CHARGE_KEY,
CHARGER_STATUS_DESCRIPTION_KEY,
)
from .coordinator import WallboxCoordinator
from .coordinator import WallboxConfigEntry, WallboxCoordinator
from .entity import WallboxEntity
@ -169,7 +168,7 @@ SENSOR_TYPES: dict[str, WallboxSensorEntityDescription] = {
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
entry: WallboxConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Create wallbox sensor entities in HASS."""

View File

@ -5,7 +5,6 @@ from __future__ import annotations
from typing import Any
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
@ -16,7 +15,7 @@ from .const import (
CHARGER_STATUS_DESCRIPTION_KEY,
ChargerStatus,
)
from .coordinator import WallboxCoordinator
from .coordinator import WallboxConfigEntry, WallboxCoordinator
from .entity import WallboxEntity
SWITCH_TYPES: dict[str, SwitchEntityDescription] = {
@ -29,7 +28,7 @@ SWITCH_TYPES: dict[str, SwitchEntityDescription] = {
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
entry: WallboxConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Create wallbox sensor entities in HASS."""