1 """Support for SwitchBot switch."""
5 from switchbot_api
import CommonCommands, Device, PowerState, Remote, SwitchBotAPI
12 from .
import SwitchbotCloudData
13 from .const
import DOMAIN
14 from .coordinator
import SwitchBotCoordinator
15 from .entity
import SwitchBotCloudEntity
21 async_add_entities: AddEntitiesCallback,
23 """Set up SwitchBot Cloud entry."""
24 data: SwitchbotCloudData = hass.data[DOMAIN][config.entry_id]
27 for device, coordinator
in data.devices.switches
32 """Representation of a SwitchBot switch."""
34 _attr_device_class = SwitchDeviceClass.SWITCH
38 """Turn the device on."""
44 """Turn the device off."""
51 """Handle updated data from the coordinator."""
52 if not self.coordinator.data:
54 self.
_attr_is_on_attr_is_on = self.coordinator.data.get(
"power") == PowerState.ON.value
59 """Representation of a SwitchBot switch provider by a remote."""
63 """Handle updated data from the coordinator."""
66 class SwitchBotCloudPlugSwitch(SwitchBotCloudSwitch):
67 """Representation of a SwitchBot plug switch."""
69 _attr_device_class = SwitchDeviceClass.OUTLET
74 api: SwitchBotAPI, device: Device | Remote, coordinator: SwitchBotCoordinator
75 ) -> SwitchBotCloudSwitch:
76 """Make a SwitchBotCloudSwitch or SwitchBotCloudRemoteSwitch."""
77 if isinstance(device, Remote):
79 if "Plug" in device.device_type:
81 raise NotImplementedError(f
"Unsupported device type: {device.device_type}")
None send_api_command(self, Commands command, str command_type="command", dict|str parameters="default")
None _handle_coordinator_update(self)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None _handle_coordinator_update(self)
None async_write_ha_state(self)
SwitchBotCloudSwitch _async_make_entity(SwitchBotAPI api, Device|Remote device, SwitchBotCoordinator coordinator)
None async_setup_entry(HomeAssistant hass, ConfigEntry config, AddEntitiesCallback async_add_entities)