Add device to Wallbox integration ()

pull/63383/head
Erwin Oldenkamp 2022-01-04 15:46:57 +01:00 committed by GitHub
parent 3e51659ba7
commit 39b26e5ff7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 10 deletions
homeassistant/components/wallbox
tests/components/wallbox

View File

@ -13,9 +13,23 @@ 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, HomeAssistantError
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
)
from .const import CONF_DATA_KEY, CONF_MAX_CHARGING_CURRENT_KEY, CONF_STATION, DOMAIN
from ...helpers.entity import DeviceInfo
from .const import (
CONF_CURRENT_VERSION_KEY,
CONF_DATA_KEY,
CONF_MAX_CHARGING_CURRENT_KEY,
CONF_NAME_KEY,
CONF_PART_NUMBER_KEY,
CONF_SERIAL_NUMBER_KEY,
CONF_SOFTWARE_KEY,
CONF_STATION,
DOMAIN,
)
_LOGGER = logging.getLogger(__name__)
@ -132,3 +146,24 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
class InvalidAuth(HomeAssistantError):
"""Error to indicate there is invalid auth."""
class WallboxEntity(CoordinatorEntity):
"""Defines a base Wallbox entity."""
coordinator: WallboxCoordinator
@property
def device_info(self) -> DeviceInfo:
"""Return device information about this Wallbox device."""
return DeviceInfo(
identifiers={
(DOMAIN, self.coordinator.data[CONF_DATA_KEY][CONF_SERIAL_NUMBER_KEY])
},
name=f"Wallbox - {self.coordinator.data[CONF_NAME_KEY]}",
manufacturer="Wallbox",
model=self.coordinator.data[CONF_DATA_KEY][CONF_PART_NUMBER_KEY],
sw_version=self.coordinator.data[CONF_DATA_KEY][CONF_SOFTWARE_KEY][
CONF_CURRENT_VERSION_KEY
],
)

View File

@ -10,10 +10,15 @@ CONF_CHARGING_SPEED_KEY = "charging_speed"
CONF_CHARGING_TIME_KEY = "charging_time"
CONF_COST_KEY = "cost"
CONF_CURRENT_MODE_KEY = "current_mode"
CONF_CURRENT_VERSION_KEY = "currentVersion"
CONF_DATA_KEY = "config_data"
CONF_DEPOT_PRICE_KEY = "depot_price"
CONF_SERIAL_NUMBER_KEY = "serial_number"
CONF_PART_NUMBER_KEY = "part_number"
CONF_SOFTWARE_KEY = "software"
CONF_MAX_AVAILABLE_POWER_KEY = "max_available_power"
CONF_MAX_CHARGING_CURRENT_KEY = "max_charging_current"
CONF_NAME_KEY = "name"
CONF_STATE_OF_CHARGE_KEY = "state_of_charge"
CONF_STATUS_DESCRIPTION_KEY = "status_description"
CONF_CONNECTIONS = "connections"

View File

@ -9,10 +9,15 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DEVICE_CLASS_CURRENT
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from . import InvalidAuth, WallboxCoordinator
from .const import CONF_MAX_AVAILABLE_POWER_KEY, CONF_MAX_CHARGING_CURRENT_KEY, DOMAIN
from . import InvalidAuth, WallboxCoordinator, WallboxEntity
from .const import (
CONF_DATA_KEY,
CONF_MAX_AVAILABLE_POWER_KEY,
CONF_MAX_CHARGING_CURRENT_KEY,
CONF_SERIAL_NUMBER_KEY,
DOMAIN,
)
@dataclass
@ -52,7 +57,7 @@ async def async_setup_entry(
)
class WallboxNumber(CoordinatorEntity, NumberEntity):
class WallboxNumber(WallboxEntity, NumberEntity):
"""Representation of the Wallbox portal."""
entity_description: WallboxNumberEntityDescription
@ -69,6 +74,7 @@ class WallboxNumber(CoordinatorEntity, NumberEntity):
self.entity_description = description
self._coordinator = coordinator
self._attr_name = f"{entry.title} {description.name}"
self._attr_unique_id = f"{description.key}-{coordinator.data[CONF_DATA_KEY][CONF_SERIAL_NUMBER_KEY]}"
@property
def max_value(self) -> float:

View File

@ -22,9 +22,8 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from . import WallboxCoordinator
from . import WallboxCoordinator, WallboxEntity
from .const import (
CONF_ADDED_ENERGY_KEY,
CONF_ADDED_RANGE_KEY,
@ -32,9 +31,11 @@ from .const import (
CONF_CHARGING_SPEED_KEY,
CONF_COST_KEY,
CONF_CURRENT_MODE_KEY,
CONF_DATA_KEY,
CONF_DEPOT_PRICE_KEY,
CONF_MAX_AVAILABLE_POWER_KEY,
CONF_MAX_CHARGING_CURRENT_KEY,
CONF_SERIAL_NUMBER_KEY,
CONF_STATE_OF_CHARGE_KEY,
CONF_STATUS_DESCRIPTION_KEY,
DOMAIN,
@ -147,7 +148,7 @@ async def async_setup_entry(
)
class WallboxSensor(CoordinatorEntity, SensorEntity):
class WallboxSensor(WallboxEntity, SensorEntity):
"""Representation of the Wallbox portal."""
entity_description: WallboxSensorEntityDescription
@ -163,6 +164,7 @@ class WallboxSensor(CoordinatorEntity, SensorEntity):
super().__init__(coordinator)
self.entity_description = description
self._attr_name = f"{entry.title} {description.name}"
self._attr_unique_id = f"{description.key}-{coordinator.data[CONF_DATA_KEY][CONF_SERIAL_NUMBER_KEY]}"
@property
def native_value(self) -> StateType:

View File

@ -10,9 +10,14 @@ from homeassistant.components.wallbox.const import (
CONF_ADDED_RANGE_KEY,
CONF_CHARGING_POWER_KEY,
CONF_CHARGING_SPEED_KEY,
CONF_CURRENT_VERSION_KEY,
CONF_DATA_KEY,
CONF_MAX_AVAILABLE_POWER_KEY,
CONF_MAX_CHARGING_CURRENT_KEY,
CONF_NAME_KEY,
CONF_PART_NUMBER_KEY,
CONF_SERIAL_NUMBER_KEY,
CONF_SOFTWARE_KEY,
CONF_STATION,
DOMAIN,
)
@ -30,7 +35,13 @@ test_response = json.loads(
CONF_CHARGING_SPEED_KEY: 0,
CONF_ADDED_RANGE_KEY: 150,
CONF_ADDED_ENERGY_KEY: 44.697,
CONF_DATA_KEY: {CONF_MAX_CHARGING_CURRENT_KEY: 24},
CONF_NAME_KEY: "WallboxName",
CONF_DATA_KEY: {
CONF_MAX_CHARGING_CURRENT_KEY: 24,
CONF_SERIAL_NUMBER_KEY: "20000",
CONF_PART_NUMBER_KEY: "PLP1-0-2-4-9-002-E",
CONF_SOFTWARE_KEY: {CONF_CURRENT_VERSION_KEY: "5.5.10"},
},
}
)
)