mirror of https://github.com/home-assistant/core
42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
"""Support for the Switchbot Bot as a Button."""
|
|
|
|
from typing import Any
|
|
|
|
from switchbot_api import BotCommands
|
|
|
|
from homeassistant.components.button import ButtonEntity
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant, callback
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from . import SwitchbotCloudData
|
|
from .const import DOMAIN
|
|
from .entity import SwitchBotCloudEntity
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
config: ConfigEntry,
|
|
async_add_entities: AddEntitiesCallback,
|
|
) -> None:
|
|
"""Set up SwitchBot Cloud entry."""
|
|
data: SwitchbotCloudData = hass.data[DOMAIN][config.entry_id]
|
|
async_add_entities(
|
|
SwitchBotCloudBot(data.api, device, coordinator)
|
|
for device, coordinator in data.devices.buttons
|
|
)
|
|
|
|
|
|
class SwitchBotCloudBot(SwitchBotCloudEntity, ButtonEntity):
|
|
"""Representation of a SwitchBot Bot."""
|
|
|
|
_attr_name = None
|
|
|
|
@callback
|
|
def _handle_coordinator_update(self) -> None:
|
|
"""Handle updated data from the coordinator."""
|
|
|
|
async def async_press(self, **kwargs: Any) -> None:
|
|
"""Bot press command."""
|
|
await self.send_api_command(BotCommands.PRESS)
|