1 """Platform for switch integration."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
8 from boschshcpy
import (
16 from boschshcpy.device
import SHCDevice
21 SwitchEntityDescription,
29 from .const
import DATA_SESSION, DOMAIN
30 from .entity
import SHCEntity
33 @dataclass(frozen=True, kw_only=True)
35 """Class describing SHC switch entities."""
42 SWITCH_TYPES: dict[str, SHCSwitchEntityDescription] = {
45 device_class=SwitchDeviceClass.OUTLET,
47 on_value=SHCSmartPlug.PowerSwitchService.State.ON,
51 key=
"smartplugcompact",
52 device_class=SwitchDeviceClass.OUTLET,
54 on_value=SHCSmartPlugCompact.PowerSwitchService.State.ON,
59 device_class=SwitchDeviceClass.SWITCH,
61 on_value=SHCLightSwitch.PowerSwitchService.State.ON,
66 device_class=SwitchDeviceClass.SWITCH,
68 on_value=SHCCameraEyes.CameraLightService.State.ON,
73 device_class=SwitchDeviceClass.SWITCH,
75 on_value=SHCCamera360.PrivacyModeService.State.DISABLED,
83 config_entry: ConfigEntry,
84 async_add_entities: AddEntitiesCallback,
86 """Set up the SHC switch platform."""
87 session: SHCSession = hass.data[DOMAIN][config_entry.entry_id][DATA_SESSION]
89 entities: list[SwitchEntity] = [
92 parent_id=session.information.unique_id,
93 entry_id=config_entry.entry_id,
94 description=SWITCH_TYPES[
"smartplug"],
96 for switch
in session.device_helper.smart_plugs
102 parent_id=session.information.unique_id,
103 entry_id=config_entry.entry_id,
105 for switch
in session.device_helper.smart_plugs
111 parent_id=session.information.unique_id,
112 entry_id=config_entry.entry_id,
113 description=SWITCH_TYPES[
"lightswitch"],
115 for switch
in session.device_helper.light_switches_bsm
121 parent_id=session.information.unique_id,
122 entry_id=config_entry.entry_id,
123 description=SWITCH_TYPES[
"smartplugcompact"],
125 for switch
in session.device_helper.smart_plugs_compact
131 parent_id=session.information.unique_id,
132 entry_id=config_entry.entry_id,
133 description=SWITCH_TYPES[
"cameraeyes"],
135 for switch
in session.device_helper.camera_eyes
141 parent_id=session.information.unique_id,
142 entry_id=config_entry.entry_id,
143 description=SWITCH_TYPES[
"camera360"],
145 for switch
in session.device_helper.camera_360
152 """Representation of a SHC switch."""
154 entity_description: SHCSwitchEntityDescription
161 description: SHCSwitchEntityDescription,
163 """Initialize a SHC switch."""
164 super().
__init__(device, parent_id, entry_id)
169 """Return the state of the switch."""
176 """Turn the switch on."""
180 """Turn the switch off."""
185 """Switch needs polling."""
189 """Trigger an update of the device."""
194 """Representation of a SHC routing switch."""
196 _attr_translation_key =
"routing"
197 _attr_entity_category = EntityCategory.CONFIG
199 def __init__(self, device: SHCDevice, parent_id: str, entry_id: str) ->
None:
200 """Initialize an SHC communication quality reporting sensor."""
201 super().
__init__(device, parent_id, entry_id)
206 """Return the state of the switch."""
207 return self.
_device_device.routing.name ==
"ENABLED"
210 """Turn the switch on."""
211 self.
_device_device.routing =
True
214 """Turn the switch off."""
215 self.
_device_device.routing =
False
None turn_on(self, **Any kwargs)
None turn_off(self, **Any kwargs)
None __init__(self, SHCDevice device, str parent_id, str entry_id)
None __init__(self, SHCDevice device, str parent_id, str entry_id, SHCSwitchEntityDescription description)
None turn_off(self, **Any kwargs)
None turn_on(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)