2021-10-14 22:50:09 +00:00
|
|
|
"""UptimeRobot binary_sensor platform."""
|
2021-08-04 20:20:03 +00:00
|
|
|
from __future__ import annotations
|
2018-06-10 08:28:53 +00:00
|
|
|
|
2020-09-12 18:21:57 +00:00
|
|
|
from homeassistant.components.binary_sensor import (
|
2021-12-01 09:36:15 +00:00
|
|
|
BinarySensorDeviceClass,
|
2020-09-12 18:21:57 +00:00
|
|
|
BinarySensorEntity,
|
2021-08-03 18:20:12 +00:00
|
|
|
BinarySensorEntityDescription,
|
2020-09-12 18:21:57 +00:00
|
|
|
)
|
2021-10-15 10:33:10 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2021-08-03 18:20:12 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2021-08-04 20:20:03 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
2018-06-10 08:28:53 +00:00
|
|
|
|
2021-08-04 20:20:03 +00:00
|
|
|
from .const import DOMAIN
|
|
|
|
from .entity import UptimeRobotEntity
|
2018-06-10 08:58:45 +00:00
|
|
|
|
2018-06-10 08:28:53 +00:00
|
|
|
|
2021-08-04 20:20:03 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
|
|
|
) -> None:
|
2021-10-14 22:50:09 +00:00
|
|
|
"""Set up the UptimeRobot binary_sensors."""
|
2021-08-04 20:20:03 +00:00
|
|
|
coordinator: DataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
2021-08-03 18:20:12 +00:00
|
|
|
async_add_entities(
|
|
|
|
[
|
2019-07-31 19:25:30 +00:00
|
|
|
UptimeRobotBinarySensor(
|
2021-08-03 18:20:12 +00:00
|
|
|
coordinator,
|
2021-08-04 07:29:51 +00:00
|
|
|
BinarySensorEntityDescription(
|
2021-08-04 20:20:03 +00:00
|
|
|
key=str(monitor.id),
|
2021-08-05 10:13:47 +00:00
|
|
|
name=monitor.friendly_name,
|
2021-12-01 09:36:15 +00:00
|
|
|
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
2021-08-03 18:20:12 +00:00
|
|
|
),
|
2021-08-10 14:29:51 +00:00
|
|
|
monitor=monitor,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2021-08-04 20:20:03 +00:00
|
|
|
for monitor in coordinator.data
|
2021-08-03 18:20:12 +00:00
|
|
|
],
|
|
|
|
)
|
2018-06-10 08:28:53 +00:00
|
|
|
|
|
|
|
|
2021-08-04 20:20:03 +00:00
|
|
|
class UptimeRobotBinarySensor(UptimeRobotEntity, BinarySensorEntity):
|
2021-10-14 22:50:09 +00:00
|
|
|
"""Representation of a UptimeRobot binary sensor."""
|
2018-06-10 08:28:53 +00:00
|
|
|
|
2021-08-04 07:29:51 +00:00
|
|
|
@property
|
|
|
|
def is_on(self) -> bool:
|
|
|
|
"""Return True if the entity is on."""
|
2021-08-04 20:20:03 +00:00
|
|
|
return self.monitor_available
|