1 """Home Assistant component for accessing the Wallbox Portal API.
3 The number component allows control of charging current.
6 from __future__
import annotations
8 from collections.abc
import Awaitable, Callable
9 from dataclasses
import dataclass
10 from typing
import cast
19 BIDIRECTIONAL_MODEL_PREFIXES,
21 CHARGER_ENERGY_PRICE_KEY,
22 CHARGER_MAX_AVAILABLE_POWER_KEY,
23 CHARGER_MAX_CHARGING_CURRENT_KEY,
24 CHARGER_MAX_ICP_CURRENT_KEY,
25 CHARGER_PART_NUMBER_KEY,
26 CHARGER_SERIAL_NUMBER_KEY,
29 from .coordinator
import InvalidAuth, WallboxCoordinator
30 from .entity
import WallboxEntity
34 """Return the minimum available value for charging current."""
36 coordinator.data[CHARGER_DATA_KEY][CHARGER_PART_NUMBER_KEY][0:2]
37 in BIDIRECTIONAL_MODEL_PREFIXES
39 return cast(float, (coordinator.data[CHARGER_MAX_AVAILABLE_POWER_KEY] * -1))
43 @dataclass(frozen=True, kw_only=True)
45 """Describes Wallbox number entity."""
47 max_value_fn: Callable[[WallboxCoordinator], float]
48 min_value_fn: Callable[[WallboxCoordinator], float]
49 set_value_fn: Callable[[WallboxCoordinator], Callable[[float], Awaitable[
None]]]
52 NUMBER_TYPES: dict[str, WallboxNumberEntityDescription] = {
54 key=CHARGER_MAX_CHARGING_CURRENT_KEY,
55 translation_key=
"maximum_charging_current",
56 max_value_fn=
lambda coordinator: cast(
57 float, coordinator.data[CHARGER_MAX_AVAILABLE_POWER_KEY]
59 min_value_fn=min_charging_current_value,
60 set_value_fn=
lambda coordinator: coordinator.async_set_charging_current,
64 key=CHARGER_ENERGY_PRICE_KEY,
65 translation_key=
"energy_price",
66 max_value_fn=
lambda _: 5,
67 min_value_fn=
lambda _: -5,
68 set_value_fn=
lambda coordinator: coordinator.async_set_energy_cost,
72 key=CHARGER_MAX_ICP_CURRENT_KEY,
73 translation_key=
"maximum_icp_current",
74 max_value_fn=
lambda coordinator: cast(
75 float, coordinator.data[CHARGER_MAX_AVAILABLE_POWER_KEY]
77 min_value_fn=
lambda _: 6,
78 set_value_fn=
lambda coordinator: coordinator.async_set_icp_current,
85 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
87 """Create wallbox number entities in HASS."""
88 coordinator: WallboxCoordinator = hass.data[DOMAIN][entry.entry_id]
91 await coordinator.async_set_charging_current(
92 coordinator.data[CHARGER_MAX_CHARGING_CURRENT_KEY]
96 except ConnectionError
as exc:
97 raise PlatformNotReady
from exc
101 for ent
in coordinator.data
102 if (description := NUMBER_TYPES.get(ent))
107 """Representation of the Wallbox portal."""
109 entity_description: WallboxNumberEntityDescription
113 coordinator: WallboxCoordinator,
115 description: WallboxNumberEntityDescription,
117 """Initialize a Wallbox number entity."""
121 self.
_attr_unique_id_attr_unique_id = f
"{description.key}-{coordinator.data[CHARGER_DATA_KEY][CHARGER_SERIAL_NUMBER_KEY]}"
125 """Return the maximum available value."""
130 """Return the minimum available value."""
135 """Return the value of the entity."""
139 """Set the value of the entity."""
float|None native_value(self)
None async_set_native_value(self, float value)
float native_max_value(self)
None __init__(self, WallboxCoordinator coordinator, ConfigEntry entry, WallboxNumberEntityDescription description)
float native_min_value(self)
float min_charging_current_value(WallboxCoordinator coordinator)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)