2019-02-13 20:21:14 +00:00
|
|
|
"""Support for monitoring the state of UpCloud servers."""
|
2018-02-28 21:17:12 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import voluptuous as vol
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorDevice
|
2019-03-21 05:56:46 +00:00
|
|
|
import homeassistant.helpers.config_validation as cv
|
|
|
|
|
|
|
|
from . import CONF_SERVERS, DATA_UPCLOUD, UpCloudServerEntity
|
2018-02-28 21:17:12 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|
|
|
{vol.Required(CONF_SERVERS): vol.All(cv.ensure_list, [cv.string])}
|
|
|
|
)
|
2018-02-28 21:17:12 +00:00
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2018-02-28 21:17:12 +00:00
|
|
|
"""Set up the UpCloud server binary sensor."""
|
|
|
|
upcloud = hass.data[DATA_UPCLOUD]
|
|
|
|
|
|
|
|
servers = config.get(CONF_SERVERS)
|
|
|
|
|
|
|
|
devices = [UpCloudBinarySensor(upcloud, uuid) for uuid in servers]
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities(devices, True)
|
2018-02-28 21:17:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UpCloudBinarySensor(UpCloudServerEntity, BinarySensorDevice):
|
|
|
|
"""Representation of an UpCloud server sensor."""
|