1 """Support for TPLink switch entities."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
7 from typing
import Any, cast
9 from kasa
import Feature
15 from .
import TPLinkConfigEntry
17 CoordinatedTPLinkFeatureEntity,
18 TPLinkFeatureEntityDescription,
22 _LOGGER = logging.getLogger(__name__)
25 @dataclass(frozen=True, kw_only=True)
27 SwitchEntityDescription, TPLinkFeatureEntityDescription
29 """Base class for a TPLink feature based sensor entity description."""
32 SWITCH_DESCRIPTIONS: tuple[TPLinkSwitchEntityDescription, ...] = (
40 key=
"auto_update_enabled",
43 key=
"auto_off_enabled",
46 key=
"smooth_transitions",
59 SWITCH_DESCRIPTIONS_MAP = {desc.key: desc
for desc
in SWITCH_DESCRIPTIONS}
64 config_entry: TPLinkConfigEntry,
65 async_add_entities: AddEntitiesCallback,
67 """Set up switches."""
68 data = config_entry.runtime_data
69 parent_coordinator = data.parent_coordinator
70 device = parent_coordinator.device
72 entities = CoordinatedTPLinkFeatureEntity.entities_for_device_and_its_children(
75 coordinator=parent_coordinator,
76 feature_type=Feature.Switch,
77 entity_class=TPLinkSwitch,
78 descriptions=SWITCH_DESCRIPTIONS_MAP,
85 """Representation of a feature-based TPLink switch."""
87 entity_description: TPLinkSwitchEntityDescription
91 """Turn the switch on."""
92 await self.
_feature_feature.set_value(
True)
96 """Turn the switch off."""
97 await self.
_feature_feature.set_value(
False)
101 """Update the entity's attributes."""
None _async_update_attrs(self)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, TPLinkConfigEntry config_entry, AddEntitiesCallback async_add_entities)