Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """The Keenetic Client class."""
2 
4  BinarySensorDeviceClass,
5  BinarySensorEntity,
6 )
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.core import HomeAssistant
9 from homeassistant.helpers.dispatcher import async_dispatcher_connect
10 from homeassistant.helpers.entity_platform import AddEntitiesCallback
11 
12 from . import KeeneticRouter
13 from .const import DOMAIN, ROUTER
14 
15 
17  hass: HomeAssistant,
18  config_entry: ConfigEntry,
19  async_add_entities: AddEntitiesCallback,
20 ) -> None:
21  """Set up device tracker for Keenetic NDMS2 component."""
22  router: KeeneticRouter = hass.data[DOMAIN][config_entry.entry_id][ROUTER]
23 
25 
26 
28  """Representation router connection status."""
29 
30  _attr_device_class = BinarySensorDeviceClass.CONNECTIVITY
31  _attr_should_poll = False
32  _attr_has_entity_name = True
33 
34  def __init__(self, router: KeeneticRouter) -> None:
35  """Initialize the APCUPSd binary device."""
36  self._router_router = router
37  self._attr_unique_id_attr_unique_id = f"online_{router.config_entry.entry_id}"
38  self._attr_device_info_attr_device_info = router.device_info
39 
40  @property
41  def is_on(self):
42  """Return true if the UPS is online, else false."""
43  return self._router_router.available
44 
45  async def async_added_to_hass(self) -> None:
46  """Client entity created."""
47  self.async_on_removeasync_on_remove(
49  self.hasshass,
50  self._router_router.signal_update,
51  self.async_write_ha_stateasync_write_ha_state,
52  )
53  )
None async_on_remove(self, CALLBACK_TYPE func)
Definition: entity.py:1331
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)
Definition: dispatcher.py:103