1 """Platform for Kostal Plenticore select widgets."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
6 from datetime
import timedelta
17 from .const
import DOMAIN
18 from .coordinator
import Plenticore, SelectDataUpdateCoordinator
20 _LOGGER = logging.getLogger(__name__)
23 @dataclass(frozen=True, kw_only=True)
25 """A class that describes plenticore select entities."""
30 SELECT_SETTINGS_DATA = [
32 module_id=
"devices:local",
34 name=
"Battery Charging / Usage mode",
37 "Battery:SmartBatteryControl:Enable",
38 "Battery:TimeControl:Enable",
45 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
47 """Add kostal plenticore Select widget."""
48 plenticore: Plenticore = hass.data[DOMAIN][entry.entry_id]
50 available_settings_data = await plenticore.client.get_settings()
60 for description
in SELECT_SETTINGS_DATA:
61 assert description.options
is not None
62 if description.module_id
not in available_settings_data:
65 data_id
for data_id
in description.options
if data_id !=
"None"
67 available_data_ids = {
68 setting.id
for setting
in available_settings_data[description.module_id]
70 if not needed_data_ids <= available_data_ids:
74 select_data_update_coordinator,
76 entry_id=entry.entry_id,
77 platform_name=entry.title,
78 device_info=plenticore.device_info,
86 CoordinatorEntity[SelectDataUpdateCoordinator], SelectEntity
88 """Representation of a Plenticore Select."""
90 _attr_entity_category = EntityCategory.CONFIG
91 entity_description: PlenticoreSelectEntityDescription
95 coordinator: SelectDataUpdateCoordinator,
96 description: PlenticoreSelectEntityDescription,
99 device_info: DeviceInfo,
101 """Create a new Select Entity for Plenticore process data."""
113 """Return if entity is available."""
116 and self.coordinator.data
is not None
117 and self.
module_idmodule_id
in self.coordinator.data
122 """Register this entity on the Update Coordinator."""
131 """Unregister this entity from the Update Coordinator."""
136 """Update the current selected option."""
137 for all_option
in self.
optionsoptions:
138 if all_option !=
"None":
140 self.
module_idmodule_id, {all_option:
"0"}
148 """Return the selected entity option to represent the entity state."""
bool async_write_data(self, str module_id, dict[str, str] value)
CALLBACK_TYPE start_fetch_data(self, str module_id, str data_id, list[str] all_options)
None stop_fetch_data(self, str module_id, str data_id, list[str] all_options)
None __init__(self, SelectDataUpdateCoordinator coordinator, PlenticoreSelectEntityDescription description, str entry_id, str platform_name, DeviceInfo device_info)
None async_added_to_hass(self)
str|None current_option(self)
None async_will_remove_from_hass(self)
None async_select_option(self, str option)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)