1 """Plugwise Switch component for HomeAssistant."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
8 from plugwise.constants
import SwitchType
13 SwitchEntityDescription,
19 from .
import PlugwiseConfigEntry
20 from .coordinator
import PlugwiseDataUpdateCoordinator
21 from .entity
import PlugwiseEntity
22 from .util
import plugwise_command
25 @dataclass(frozen=True)
27 """Describes Plugwise switch entity."""
32 SWITCHES: tuple[PlugwiseSwitchEntityDescription, ...] = (
35 translation_key=
"dhw_cm_switch",
36 entity_category=EntityCategory.CONFIG,
40 translation_key=
"lock",
41 entity_category=EntityCategory.CONFIG,
45 translation_key=
"relay",
46 device_class=SwitchDeviceClass.SWITCH,
49 key=
"cooling_ena_switch",
50 translation_key=
"cooling_ena_switch",
52 entity_category=EntityCategory.CONFIG,
59 entry: PlugwiseConfigEntry,
60 async_add_entities: AddEntitiesCallback,
62 """Set up the Smile switches from a config entry."""
63 coordinator = entry.runtime_data
66 def _add_entities() -> None:
68 if not coordinator.new_devices:
73 for device_id
in coordinator.new_devices
74 if (switches := coordinator.data.devices[device_id].
get(
"switches"))
75 for description
in SWITCHES
76 if description.key
in switches
80 entry.async_on_unload(coordinator.async_add_listener(_add_entities))
84 """Representation of a Plugwise plug."""
86 entity_description: PlugwiseSwitchEntityDescription
90 coordinator: PlugwiseDataUpdateCoordinator,
92 description: PlugwiseSwitchEntityDescription,
94 """Set up the Plugwise API."""
95 super().
__init__(coordinator, device_id)
101 """Return True if entity is on."""
106 """Turn the device on."""
107 await self.coordinator.api.set_switch_state(
116 """Turn the device off."""
117 await self.coordinator.api.set_switch_state(
GwEntityData device(self)
None __init__(self, PlugwiseDataUpdateCoordinator coordinator, str device_id, PlugwiseSwitchEntityDescription description)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, PlugwiseConfigEntry entry, AddEntitiesCallback async_add_entities)