1 """Support for MySensors switches."""
3 from __future__
import annotations
14 from .
import setup_mysensors_platform
15 from .const
import MYSENSORS_DISCOVERY, DiscoveryInfo, SensorType
16 from .entity
import MySensorsChildEntity
17 from .helpers
import on_unload
22 config_entry: ConfigEntry,
23 async_add_entities: AddEntitiesCallback,
25 """Set up this platform for a specific ConfigEntry(==Gateway)."""
26 device_class_map: dict[SensorType, type[MySensorsSwitch]] = {
27 "S_DOOR": MySensorsSwitch,
28 "S_MOTION": MySensorsSwitch,
29 "S_SMOKE": MySensorsSwitch,
30 "S_LIGHT": MySensorsSwitch,
31 "S_LOCK": MySensorsSwitch,
32 "S_BINARY": MySensorsSwitch,
33 "S_SPRINKLER": MySensorsSwitch,
34 "S_WATER_LEAK": MySensorsSwitch,
35 "S_SOUND": MySensorsSwitch,
36 "S_VIBRATION": MySensorsSwitch,
37 "S_MOISTURE": MySensorsSwitch,
38 "S_WATER_QUALITY": MySensorsSwitch,
42 """Discover and add a MySensors switch."""
48 async_add_entities=async_add_entities,
53 config_entry.entry_id,
56 MYSENSORS_DISCOVERY.format(config_entry.entry_id, Platform.SWITCH),
63 """Representation of the value of a MySensors Switch child node."""
67 """Return True if switch is on."""
68 return self._values.
get(self.value_type) == STATE_ON
71 """Turn the switch on."""
72 self.gateway.set_child_value(
73 self.node_id, self.child_id, self.value_type, 1, ack=1
77 self._values[self.value_type] = STATE_ON
81 """Turn the switch off."""
82 self.gateway.set_child_value(
83 self.node_id, self.child_id, self.value_type, 0, ack=1
87 self._values[self.value_type] = STATE_OFF
None async_write_ha_state(self)
web.Response get(self, web.Request request, str config_key)
None on_unload(HomeAssistant hass, GatewayId gateway_id, Callable fnct)
None async_discover(DiscoveryInfo discovery_info)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
list[MySensorsChildEntity]|None setup_mysensors_platform(HomeAssistant hass, Platform domain, DiscoveryInfo discovery_info, type[MySensorsChildEntity]|Mapping[SensorType, type[MySensorsChildEntity]] device_class,(tuple|None) device_args=None, Callable|None async_add_entities=None)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)