mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 02:37:08 +00:00
Move wallbox base entity to its own file (#101576)
This commit is contained in:
parent
ba5aa7759d
commit
5ae45e398e
@ -13,24 +13,14 @@ 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, HomeAssistantError
|
from homeassistant.exceptions import ConfigEntryAuthFailed, HomeAssistantError
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
from homeassistant.helpers.update_coordinator import (
|
|
||||||
CoordinatorEntity,
|
|
||||||
DataUpdateCoordinator,
|
|
||||||
UpdateFailed,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CHARGER_CURRENCY_KEY,
|
CHARGER_CURRENCY_KEY,
|
||||||
CHARGER_CURRENT_VERSION_KEY,
|
|
||||||
CHARGER_DATA_KEY,
|
CHARGER_DATA_KEY,
|
||||||
CHARGER_ENERGY_PRICE_KEY,
|
CHARGER_ENERGY_PRICE_KEY,
|
||||||
CHARGER_LOCKED_UNLOCKED_KEY,
|
CHARGER_LOCKED_UNLOCKED_KEY,
|
||||||
CHARGER_MAX_CHARGING_CURRENT_KEY,
|
CHARGER_MAX_CHARGING_CURRENT_KEY,
|
||||||
CHARGER_NAME_KEY,
|
|
||||||
CHARGER_PART_NUMBER_KEY,
|
|
||||||
CHARGER_SERIAL_NUMBER_KEY,
|
|
||||||
CHARGER_SOFTWARE_KEY,
|
|
||||||
CHARGER_STATUS_DESCRIPTION_KEY,
|
CHARGER_STATUS_DESCRIPTION_KEY,
|
||||||
CHARGER_STATUS_ID_KEY,
|
CHARGER_STATUS_ID_KEY,
|
||||||
CODE_KEY,
|
CODE_KEY,
|
||||||
@ -241,27 +231,3 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
class InvalidAuth(HomeAssistantError):
|
class InvalidAuth(HomeAssistantError):
|
||||||
"""Error to indicate there is invalid auth."""
|
"""Error to indicate there is invalid auth."""
|
||||||
|
|
||||||
|
|
||||||
class WallboxEntity(CoordinatorEntity[WallboxCoordinator]):
|
|
||||||
"""Defines a base Wallbox entity."""
|
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
"""Return device information about this Wallbox device."""
|
|
||||||
return DeviceInfo(
|
|
||||||
identifiers={
|
|
||||||
(
|
|
||||||
DOMAIN,
|
|
||||||
self.coordinator.data[CHARGER_DATA_KEY][CHARGER_SERIAL_NUMBER_KEY],
|
|
||||||
)
|
|
||||||
},
|
|
||||||
name=f"Wallbox {self.coordinator.data[CHARGER_NAME_KEY]}",
|
|
||||||
manufacturer="Wallbox",
|
|
||||||
model=self.coordinator.data[CHARGER_DATA_KEY][CHARGER_PART_NUMBER_KEY],
|
|
||||||
sw_version=self.coordinator.data[CHARGER_DATA_KEY][CHARGER_SOFTWARE_KEY][
|
|
||||||
CHARGER_CURRENT_VERSION_KEY
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
40
homeassistant/components/wallbox/entity.py
Normal file
40
homeassistant/components/wallbox/entity.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
"""Base entity for the wallbox integration."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
from . import WallboxCoordinator
|
||||||
|
from .const import (
|
||||||
|
CHARGER_CURRENT_VERSION_KEY,
|
||||||
|
CHARGER_DATA_KEY,
|
||||||
|
CHARGER_NAME_KEY,
|
||||||
|
CHARGER_PART_NUMBER_KEY,
|
||||||
|
CHARGER_SERIAL_NUMBER_KEY,
|
||||||
|
CHARGER_SOFTWARE_KEY,
|
||||||
|
DOMAIN,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class WallboxEntity(CoordinatorEntity[WallboxCoordinator]):
|
||||||
|
"""Defines a base Wallbox entity."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_info(self) -> DeviceInfo:
|
||||||
|
"""Return device information about this Wallbox device."""
|
||||||
|
return DeviceInfo(
|
||||||
|
identifiers={
|
||||||
|
(
|
||||||
|
DOMAIN,
|
||||||
|
self.coordinator.data[CHARGER_DATA_KEY][CHARGER_SERIAL_NUMBER_KEY],
|
||||||
|
)
|
||||||
|
},
|
||||||
|
name=f"Wallbox {self.coordinator.data[CHARGER_NAME_KEY]}",
|
||||||
|
manufacturer="Wallbox",
|
||||||
|
model=self.coordinator.data[CHARGER_DATA_KEY][CHARGER_PART_NUMBER_KEY],
|
||||||
|
sw_version=self.coordinator.data[CHARGER_DATA_KEY][CHARGER_SOFTWARE_KEY][
|
||||||
|
CHARGER_CURRENT_VERSION_KEY
|
||||||
|
],
|
||||||
|
)
|
@ -9,13 +9,14 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.exceptions import PlatformNotReady
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import InvalidAuth, WallboxCoordinator, WallboxEntity
|
from . import InvalidAuth, WallboxCoordinator
|
||||||
from .const import (
|
from .const import (
|
||||||
CHARGER_DATA_KEY,
|
CHARGER_DATA_KEY,
|
||||||
CHARGER_LOCKED_UNLOCKED_KEY,
|
CHARGER_LOCKED_UNLOCKED_KEY,
|
||||||
CHARGER_SERIAL_NUMBER_KEY,
|
CHARGER_SERIAL_NUMBER_KEY,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
|
from .entity import WallboxEntity
|
||||||
|
|
||||||
LOCK_TYPES: dict[str, LockEntityDescription] = {
|
LOCK_TYPES: dict[str, LockEntityDescription] = {
|
||||||
CHARGER_LOCKED_UNLOCKED_KEY: LockEntityDescription(
|
CHARGER_LOCKED_UNLOCKED_KEY: LockEntityDescription(
|
||||||
|
@ -13,7 +13,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.exceptions import PlatformNotReady
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import InvalidAuth, WallboxCoordinator, WallboxEntity
|
from . import InvalidAuth, WallboxCoordinator
|
||||||
from .const import (
|
from .const import (
|
||||||
BIDIRECTIONAL_MODEL_PREFIXES,
|
BIDIRECTIONAL_MODEL_PREFIXES,
|
||||||
CHARGER_DATA_KEY,
|
CHARGER_DATA_KEY,
|
||||||
@ -23,6 +23,7 @@ from .const import (
|
|||||||
CHARGER_SERIAL_NUMBER_KEY,
|
CHARGER_SERIAL_NUMBER_KEY,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
|
from .entity import WallboxEntity
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -23,7 +23,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from . import WallboxCoordinator, WallboxEntity
|
from . import WallboxCoordinator
|
||||||
from .const import (
|
from .const import (
|
||||||
CHARGER_ADDED_DISCHARGED_ENERGY_KEY,
|
CHARGER_ADDED_DISCHARGED_ENERGY_KEY,
|
||||||
CHARGER_ADDED_ENERGY_KEY,
|
CHARGER_ADDED_ENERGY_KEY,
|
||||||
@ -43,6 +43,7 @@ from .const import (
|
|||||||
CHARGER_STATUS_DESCRIPTION_KEY,
|
CHARGER_STATUS_DESCRIPTION_KEY,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
|
from .entity import WallboxEntity
|
||||||
|
|
||||||
CHARGER_STATION = "station"
|
CHARGER_STATION = "station"
|
||||||
UPDATE_INTERVAL = 30
|
UPDATE_INTERVAL = 30
|
||||||
|
@ -8,7 +8,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import WallboxCoordinator, WallboxEntity
|
from . import WallboxCoordinator
|
||||||
from .const import (
|
from .const import (
|
||||||
CHARGER_DATA_KEY,
|
CHARGER_DATA_KEY,
|
||||||
CHARGER_PAUSE_RESUME_KEY,
|
CHARGER_PAUSE_RESUME_KEY,
|
||||||
@ -17,6 +17,7 @@ from .const import (
|
|||||||
DOMAIN,
|
DOMAIN,
|
||||||
ChargerStatus,
|
ChargerStatus,
|
||||||
)
|
)
|
||||||
|
from .entity import WallboxEntity
|
||||||
|
|
||||||
SWITCH_TYPES: dict[str, SwitchEntityDescription] = {
|
SWITCH_TYPES: dict[str, SwitchEntityDescription] = {
|
||||||
CHARGER_PAUSE_RESUME_KEY: SwitchEntityDescription(
|
CHARGER_PAUSE_RESUME_KEY: SwitchEntityDescription(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user