Home Assistant Unofficial Reference 2024.12.1
switch.py
Go to the documentation of this file.
1 """Support for Steamist switches."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
8 from homeassistant.config_entries import ConfigEntry
9 from homeassistant.core import HomeAssistant
10 from homeassistant.helpers.entity_platform import AddEntitiesCallback
11 
12 from .const import DOMAIN
13 from .coordinator import SteamistDataUpdateCoordinator
14 from .entity import SteamistEntity
15 
16 ACTIVE_SWITCH = SwitchEntityDescription(
17  key="active",
18  translation_key="steam_active",
19 )
20 
21 
23  hass: HomeAssistant,
24  config_entry: ConfigEntry,
25  async_add_entities: AddEntitiesCallback,
26 ) -> None:
27  """Set up sensors."""
28  coordinator: SteamistDataUpdateCoordinator = hass.data[DOMAIN][
29  config_entry.entry_id
30  ]
31  async_add_entities([SteamistSwitchEntity(coordinator, config_entry, ACTIVE_SWITCH)])
32 
33 
35  """Representation of a Steamist steam switch."""
36 
37  @property
38  def is_on(self) -> bool:
39  """Return if the steam is active."""
40  return self._status_status.active
41 
42  async def async_turn_on(self, **kwargs: Any) -> None:
43  """Turn the steam on."""
44  await self.coordinator.client.async_turn_on_steam()
45  await self.coordinator.async_request_refresh()
46 
47  async def async_turn_off(self, **kwargs: Any) -> None:
48  """Turn the steam off."""
49  await self.coordinator.client.async_turn_off_steam()
50  await self.coordinator.async_request_refresh()
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: switch.py:26