1 """Platform for Kostal Plenticore switches."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
6 from datetime
import timedelta
18 from .const
import DOMAIN
19 from .coordinator
import SettingDataUpdateCoordinator
21 _LOGGER = logging.getLogger(__name__)
24 @dataclass(frozen=True, kw_only=True)
26 """A class that describes plenticore switch entities."""
36 SWITCH_SETTINGS_DATA = [
38 module_id=
"devices:local",
39 key=
"Battery:Strategy",
40 name=
"Battery Strategy",
45 off_label=
"Automatic economical",
51 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
53 """Add kostal plenticore Switch."""
54 plenticore = hass.data[DOMAIN][entry.entry_id]
58 available_settings_data = await plenticore.client.get_settings()
66 for description
in SWITCH_SETTINGS_DATA:
68 description.module_id
not in available_settings_data
71 setting.id
for setting
in available_settings_data[description.module_id]
75 "Skipping non existing setting data %s/%s",
76 description.module_id,
83 settings_data_update_coordinator,
87 plenticore.device_info,
95 CoordinatorEntity[SettingDataUpdateCoordinator], SwitchEntity
97 """Representation of a Plenticore Switch."""
99 _attr_entity_category = EntityCategory.CONFIG
100 entity_description: PlenticoreSwitchEntityDescription
104 coordinator: SettingDataUpdateCoordinator,
105 description: PlenticoreSwitchEntityDescription,
108 device_info: DeviceInfo,
110 """Create a new Switch Entity for Plenticore process data."""
118 self.
_attr_name_attr_name = f
"{platform_name} {description.name}"
123 self.
_attr_unique_id_attr_unique_id = f
"{entry_id}_{description.module_id}_{description.key}"
129 """Return if entity is available."""
132 and self.coordinator.data
is not None
133 and self.
module_idmodule_id
in self.coordinator.data
138 """Register this entity on the Update Coordinator."""
145 """Unregister this entity from the Update Coordinator."""
150 """Turn device on."""
154 self.coordinator.name = f
"{self.platform_name} {self._name} {self.on_label}"
158 """Turn device off."""
162 self.coordinator.name = (
163 f
"{self.platform_name} {self._name} {self.off_label}"
169 """Return true if device is on."""
171 self.coordinator.name = f
"{self.platform_name} {self._name} {self.on_label}"
173 self.coordinator.name = (
174 f
"{self.platform_name} {self._name} {self.off_label}"
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)
None async_added_to_hass(self)
None async_will_remove_from_hass(self)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None __init__(self, SettingDataUpdateCoordinator coordinator, PlenticoreSwitchEntityDescription description, str entry_id, str platform_name, DeviceInfo device_info)
None async_on_remove(self, CALLBACK_TYPE func)
None async_request_refresh(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)