* Add switch platfor mto UptimeRobot * Add tests * Apply review comment * review comments part 2 * review comments part 3 * Fix tests after swapping logic on/off * Fix reauth test * Check for read-only key * Fix reauth for switch platform * mypy * cleanup * cleanup part 2 * Fixes + review comments * Tests * Apply more review comments * Required changes * fix test * Remove if * 100% tests coverage * Check readonly key in config_flow * Fix strings & translation * Add guard for 'monitor' keys * allign tests * Wrong API key message reworded
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
"""UptimeRobot binary_sensor platform."""
|
|
from __future__ import annotations
|
|
|
|
from homeassistant.components.binary_sensor import (
|
|
BinarySensorDeviceClass,
|
|
BinarySensorEntity,
|
|
BinarySensorEntityDescription,
|
|
)
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from . import UptimeRobotDataUpdateCoordinator
|
|
from .const import DOMAIN
|
|
from .entity import UptimeRobotEntity
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
entry: ConfigEntry,
|
|
async_add_entities: AddEntitiesCallback,
|
|
) -> None:
|
|
"""Set up the UptimeRobot binary_sensors."""
|
|
coordinator: UptimeRobotDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
|
async_add_entities(
|
|
UptimeRobotBinarySensor(
|
|
coordinator,
|
|
BinarySensorEntityDescription(
|
|
key=str(monitor.id),
|
|
name=monitor.friendly_name,
|
|
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
|
),
|
|
monitor=monitor,
|
|
)
|
|
for monitor in coordinator.data
|
|
)
|
|
|
|
|
|
class UptimeRobotBinarySensor(UptimeRobotEntity, BinarySensorEntity):
|
|
"""Representation of a UptimeRobot binary sensor."""
|
|
|
|
@property
|
|
def is_on(self) -> bool:
|
|
"""Return True if the entity is on."""
|
|
return self.monitor_available
|