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