1 """Support for switch platform for Hue resources (V2 only)."""
3 from __future__
import annotations
7 from aiohue.v2
import HueBridgeV2
8 from aiohue.v2.controllers.config
import BehaviorInstance, BehaviorInstanceController
9 from aiohue.v2.controllers.events
import EventType
10 from aiohue.v2.controllers.sensors
import (
20 SwitchEntityDescription,
27 from .bridge
import HueBridge
28 from .const
import DOMAIN
29 from .v2.entity
import HueBaseEntity
34 config_entry: ConfigEntry,
35 async_add_entities: AddEntitiesCallback,
37 """Set up Hue switch platform from Hue resources."""
38 bridge: HueBridge = hass.data[DOMAIN][config_entry.entry_id]
39 api: HueBridgeV2 = bridge.api
41 if bridge.api_version == 1:
43 raise NotImplementedError(
"Switch support is only available for V2 bridges")
47 controller: BehaviorInstanceController
48 | LightLevelController
51 HueBehaviorInstanceEnabledEntity
52 | HueLightSensorEnabledEntity
53 | HueMotionSensorEnabledEntity
58 event_type: EventType, resource: BehaviorInstance | LightLevel | Motion
60 """Add entity from Hue resource."""
64 for item
in controller:
65 async_add_entity(EventType.RESOURCE_ADDED, item)
68 config_entry.async_on_unload(
70 async_add_entity, event_filter=EventType.RESOURCE_ADDED
75 register_items(api.sensors.motion, HueMotionSensorEnabledEntity)
76 register_items(api.sensors.light_level, HueLightSensorEnabledEntity)
77 register_items(api.config.behavior_instance, HueBehaviorInstanceEnabledEntity)
81 """Representation of a Switch entity from a Hue resource that can be toggled enabled."""
83 controller: BehaviorInstanceController | LightLevelController | MotionController
84 resource: BehaviorInstance | LightLevel | Motion
87 key=
"sensing_service_enabled",
88 device_class=SwitchDeviceClass.SWITCH,
89 entity_category=EntityCategory.CONFIG,
95 """Return true if the switch is on."""
99 """Turn the entity on."""
100 await self.
bridgebridge.async_request_call(
105 """Turn the entity on."""
106 await self.
bridgebridge.async_request_call(
112 """Representation of a Switch entity to enable/disable a Hue Behavior Instance."""
114 resource: BehaviorInstance
117 key=
"behavior_instance",
118 device_class=SwitchDeviceClass.SWITCH,
119 entity_category=EntityCategory.CONFIG,
120 has_entity_name=
False,
125 """Return name for this entity."""
126 return f
"Automation: {self.resource.metadata.name}"
130 """Representation of a Switch entity to enable/disable a Hue motion sensor."""
133 key=
"motion_sensor_enabled",
134 device_class=SwitchDeviceClass.SWITCH,
135 entity_category=EntityCategory.CONFIG,
136 has_entity_name=
True,
137 translation_key=
"motion_sensor_enabled",
142 """Representation of a Switch entity to enable/disable a Hue light sensor."""
145 key=
"light_sensor_enabled",
146 device_class=SwitchDeviceClass.SWITCH,
147 entity_category=EntityCategory.CONFIG,
148 has_entity_name=
True,
149 translation_key=
"light_sensor_enabled",
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)