1 """Support for Axis switches."""
3 from dataclasses
import dataclass
6 from axis.models.event
import Event, EventTopic
11 SwitchEntityDescription,
17 from .
import AxisConfigEntry
18 from .entity
import AxisEventDescription, AxisEventEntity
19 from .hub
import AxisHub
22 @dataclass(frozen=True, kw_only=True)
24 """Axis switch entity description."""
27 ENTITY_DESCRIPTIONS = (
28 AxisSwitchDescription(
29 key=
"Relay state control",
30 device_class=SwitchDeviceClass.OUTLET,
31 entity_category=EntityCategory.CONFIG,
32 event_topic=EventTopic.RELAY,
33 supported_fn=
lambda hub, event: isinstance(
int(event.id), int),
34 name_fn=
lambda hub, event: hub.api.vapix.ports[event.id].name,
41 config_entry: AxisConfigEntry,
42 async_add_entities: AddEntitiesCallback,
44 """Set up the Axis switch platform."""
45 config_entry.runtime_data.entity_loader.register_platform(
46 async_add_entities, AxisSwitch, ENTITY_DESCRIPTIONS
51 """Representation of a Axis switch."""
53 entity_description: AxisSwitchDescription
56 self, hub: AxisHub, description: AxisSwitchDescription, event: Event
58 """Initialize the Axis switch."""
59 super().
__init__(hub, description, event)
65 """Update light state."""
71 await self.
hubhub.api.vapix.ports.close(self.
_event_id_event_id)
74 """Turn off switch."""
75 await self.
hubhub.api.vapix.ports.open(self.
_event_id_event_id)
None async_turn_on(self, **Any kwargs)
None __init__(self, AxisHub hub, AxisSwitchDescription description, Event event)
None async_event_callback(self, Event event)
None async_turn_off(self, **Any kwargs)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, AxisConfigEntry config_entry, AddEntitiesCallback async_add_entities)