Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Support for monitoring the state of UpCloud servers."""
2 
4  BinarySensorDeviceClass,
5  BinarySensorEntity,
6 )
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import CONF_USERNAME
9 from homeassistant.core import HomeAssistant
10 from homeassistant.helpers.entity_platform import AddEntitiesCallback
11 
12 from .const import DATA_UPCLOUD
13 from .entity import UpCloudServerEntity
14 
15 
17  hass: HomeAssistant,
18  config_entry: ConfigEntry,
19  async_add_entities: AddEntitiesCallback,
20 ) -> None:
21  """Set up the UpCloud server binary sensor."""
22  coordinator = hass.data[DATA_UPCLOUD].coordinators[config_entry.data[CONF_USERNAME]]
23  entities = [UpCloudBinarySensor(coordinator, uuid) for uuid in coordinator.data]
24  async_add_entities(entities, True)
25 
26 
28  """Representation of an UpCloud server sensor."""
29 
30  _attr_device_class = BinarySensorDeviceClass.POWER
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)