2019-02-13 20:21:14 +00:00
|
|
|
"""Support for monitoring the state of UpCloud servers."""
|
2018-02-28 21:17:12 +00:00
|
|
|
|
2021-12-01 07:12:09 +00:00
|
|
|
from homeassistant.components.binary_sensor import (
|
|
|
|
BinarySensorDeviceClass,
|
|
|
|
BinarySensorEntity,
|
|
|
|
)
|
2021-05-15 04:49:41 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2020-10-15 21:26:01 +00:00
|
|
|
from homeassistant.const import CONF_USERNAME
|
2021-05-15 04:49:41 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2021-12-16 14:14:46 +00:00
|
|
|
from . import DATA_UPCLOUD, UpCloudServerEntity
|
2018-02-28 21:17:12 +00:00
|
|
|
|
|
|
|
|
2021-05-15 04:49:41 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2018-02-28 21:17:12 +00:00
|
|
|
"""Set up the UpCloud server binary sensor."""
|
2020-10-15 21:26:01 +00:00
|
|
|
coordinator = hass.data[DATA_UPCLOUD].coordinators[config_entry.data[CONF_USERNAME]]
|
|
|
|
entities = [UpCloudBinarySensor(coordinator, uuid) for uuid in coordinator.data]
|
|
|
|
async_add_entities(entities, True)
|
2018-02-28 21:17:12 +00:00
|
|
|
|
|
|
|
|
2020-04-23 19:57:07 +00:00
|
|
|
class UpCloudBinarySensor(UpCloudServerEntity, BinarySensorEntity):
|
2018-02-28 21:17:12 +00:00
|
|
|
"""Representation of an UpCloud server sensor."""
|
2021-12-01 07:12:09 +00:00
|
|
|
|
|
|
|
_attr_device_class = BinarySensorDeviceClass.POWER
|