1 """Platform for Kostal Plenticore numbers."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
6 from datetime
import timedelta
9 from pykoplenti
import SettingsData
14 NumberEntityDescription,
24 from .const
import DOMAIN
25 from .coordinator
import SettingDataUpdateCoordinator
26 from .helper
import PlenticoreDataFormatter
28 _LOGGER = logging.getLogger(__name__)
31 @dataclass(frozen=True, kw_only=True)
33 """Describes a Plenticore number entity."""
41 NUMBER_SETTINGS_DATA = [
43 key=
"battery_min_soc",
44 entity_category=EntityCategory.CONFIG,
45 entity_registry_enabled_default=
False,
46 icon=
"mdi:battery-negative",
47 name=
"Battery min SoC",
48 native_unit_of_measurement=PERCENTAGE,
52 module_id=
"devices:local",
53 data_id=
"Battery:MinSoc",
54 fmt_from=
"format_round",
55 fmt_to=
"format_round_back",
58 key=
"battery_min_home_consumption",
59 device_class=NumberDeviceClass.POWER,
60 entity_category=EntityCategory.CONFIG,
61 entity_registry_enabled_default=
False,
62 name=
"Battery min Home Consumption",
63 native_unit_of_measurement=UnitOfPower.WATT,
64 native_max_value=38000,
67 module_id=
"devices:local",
68 data_id=
"Battery:MinHomeComsumption",
69 fmt_from=
"format_round",
70 fmt_to=
"format_round_back",
76 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
78 """Add Kostal Plenticore Number entities."""
79 plenticore = hass.data[DOMAIN][entry.entry_id]
83 available_settings_data = await plenticore.client.get_settings()
92 for description
in NUMBER_SETTINGS_DATA:
94 description.module_id
not in available_settings_data
95 or description.data_id
97 setting.id
for setting
in available_settings_data[description.module_id]
101 "Skipping non existing setting data %s/%s",
102 description.module_id,
109 for sd
in available_settings_data[description.module_id]
110 if description.data_id == sd.id
115 settings_data_update_coordinator,
118 plenticore.device_info,
128 CoordinatorEntity[SettingDataUpdateCoordinator], NumberEntity
130 """Representation of a Kostal Plenticore Number entity."""
132 entity_description: PlenticoreNumberEntityDescription
136 coordinator: SettingDataUpdateCoordinator,
139 device_info: DeviceInfo,
140 description: PlenticoreNumberEntityDescription,
141 setting_data: SettingsData,
143 """Initialize the Plenticore Number entity."""
150 self.
_attr_unique_id_attr_unique_id = f
"{self.entry_id}_{self.module_id}_{self.data_id}"
151 self.
_attr_name_attr_name = f
"{platform_name} {description.name}"
154 self.
_formatter_formatter = PlenticoreDataFormatter.get_method(description.fmt_from)
155 self.
_formatter_back_formatter_back = PlenticoreDataFormatter.get_method(description.fmt_to)
158 if setting_data.min
is not None:
160 if setting_data.max
is not None:
165 """Return the plenticore module id of this entity."""
170 """Return the plenticore data id for this entity."""
175 """Return if entity is available."""
178 and self.coordinator.data
is not None
179 and self.
module_idmodule_id
in self.coordinator.data
184 """Register this entity on the Update Coordinator."""
191 """Unregister this entity from the Update Coordinator."""
197 """Return the current value."""
199 raw_value = self.coordinator.data[self.
module_idmodule_id][self.
data_iddata_id]
205 """Set a new value."""
bool async_write_data(self, str module_id, dict[str, str] value)
None stop_fetch_data(self, str module_id, str data_id)
CALLBACK_TYPE start_fetch_data(self, str module_id, str data_id)
float|None native_value(self)
None __init__(self, SettingDataUpdateCoordinator coordinator, str entry_id, str platform_name, DeviceInfo device_info, PlenticoreNumberEntityDescription description, SettingsData setting_data)
None async_set_native_value(self, float value)
None async_added_to_hass(self)
None async_will_remove_from_hass(self)
None async_on_remove(self, CALLBACK_TYPE func)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)