Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Binary sensor for Wyoming."""
2 
3 from __future__ import annotations
4 
5 from typing import TYPE_CHECKING
6 
8  BinarySensorEntity,
9  BinarySensorEntityDescription,
10 )
11 from homeassistant.config_entries import ConfigEntry
12 from homeassistant.core import HomeAssistant, callback
13 from homeassistant.helpers.entity_platform import AddEntitiesCallback
14 
15 from .const import DOMAIN
16 from .entity import WyomingSatelliteEntity
17 
18 if TYPE_CHECKING:
19  from .models import DomainDataItem
20 
21 
23  hass: HomeAssistant,
24  config_entry: ConfigEntry,
25  async_add_entities: AddEntitiesCallback,
26 ) -> None:
27  """Set up binary sensor entities."""
28  item: DomainDataItem = hass.data[DOMAIN][config_entry.entry_id]
29 
30  # Setup is only forwarded for satellites
31  assert item.device is not None
32 
34 
35 
37  """Entity to represent Assist is in progress for satellite."""
38 
39  entity_description = BinarySensorEntityDescription(
40  entity_registry_enabled_default=False,
41  key="assist_in_progress",
42  translation_key="assist_in_progress",
43  )
44  _attr_is_on = False
45 
46  async def async_added_to_hass(self) -> None:
47  """Call when entity about to be added to hass."""
48  await super().async_added_to_hass()
49 
50  self._device_device.set_is_active_listener(self._is_active_changed_is_active_changed)
51 
52  @callback
53  def _is_active_changed(self) -> None:
54  """Call when active state changed."""
55  self._attr_is_on_attr_is_on_attr_is_on = self._device_device.is_active
56  self.async_write_ha_stateasync_write_ha_state()
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)