1 """Switch for Refoss."""
3 from __future__
import annotations
7 from refoss_ha.controller.toggle
import ToggleXMix
15 from .bridge
import RefossDataUpdateCoordinator
16 from .const
import COORDINATORS, DISPATCH_DEVICE_DISCOVERED, DOMAIN
17 from .entity
import RefossEntity
22 config_entry: ConfigEntry,
23 async_add_entities: AddEntitiesCallback,
25 """Set up the Refoss device from a config entry."""
28 def init_device(coordinator):
29 """Register the device."""
30 device = coordinator.device
31 if not isinstance(device, ToggleXMix):
35 for channel
in device.channels:
36 entity =
RefossSwitch(coordinator=coordinator, channel=channel)
37 new_entities.append(entity)
41 for coordinator
in hass.data[DOMAIN][COORDINATORS]:
42 init_device(coordinator)
44 config_entry.async_on_unload(
50 """Refoss Switch Device."""
54 coordinator: RefossDataUpdateCoordinator,
57 """Init Refoss switch."""
58 super().
__init__(coordinator, channel)
63 """Return true if switch is on."""
64 return self.coordinator.device.is_on(channel=self.
channel_idchannel_id)
67 """Turn the switch on."""
68 await self.coordinator.device.async_turn_on(self.
channel_idchannel_id)
72 """Turn the switch off."""
73 await self.coordinator.device.async_turn_off(self.
channel_idchannel_id)
77 """Toggle the switch."""
78 await self.coordinator.device.async_toggle(channel=self.
channel_idchannel_id)
None async_toggle(self, **Any kwargs)
None __init__(self, RefossDataUpdateCoordinator coordinator, int channel)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)