2019-09-26 09:24:03 +00:00
|
|
|
"""Support for Rain Bird Irrigation system LNK WiFi Module."""
|
2022-01-03 10:35:02 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2019-09-26 09:24:03 +00:00
|
|
|
import logging
|
2022-12-27 20:17:20 +00:00
|
|
|
from typing import Union
|
2019-09-26 09:24:03 +00:00
|
|
|
|
2021-07-27 16:06:46 +00:00
|
|
|
from homeassistant.components.binary_sensor import (
|
|
|
|
BinarySensorEntity,
|
|
|
|
BinarySensorEntityDescription,
|
|
|
|
)
|
2022-01-03 10:35:02 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
2022-12-27 20:17:20 +00:00
|
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
2019-09-26 09:24:03 +00:00
|
|
|
|
2022-12-22 21:00:17 +00:00
|
|
|
from .const import SENSOR_TYPE_RAINDELAY, SENSOR_TYPE_RAINSENSOR
|
2022-12-27 20:17:20 +00:00
|
|
|
from .coordinator import RainbirdUpdateCoordinator
|
2022-12-22 21:00:17 +00:00
|
|
|
|
2019-09-26 09:24:03 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2022-12-22 21:00:17 +00:00
|
|
|
BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
|
|
|
|
BinarySensorEntityDescription(
|
|
|
|
key=SENSOR_TYPE_RAINSENSOR,
|
|
|
|
name="Rainsensor",
|
|
|
|
icon="mdi:water",
|
|
|
|
),
|
|
|
|
BinarySensorEntityDescription(
|
|
|
|
key=SENSOR_TYPE_RAINDELAY,
|
|
|
|
name="Raindelay",
|
|
|
|
icon="mdi:water-off",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_platform(
|
2022-01-03 10:35:02 +00:00
|
|
|
hass: HomeAssistant,
|
|
|
|
config: ConfigType,
|
2022-12-22 21:00:17 +00:00
|
|
|
async_add_entities: AddEntitiesCallback,
|
2022-01-03 10:35:02 +00:00
|
|
|
discovery_info: DiscoveryInfoType | None = None,
|
|
|
|
) -> None:
|
2019-09-26 09:24:03 +00:00
|
|
|
"""Set up a Rain Bird sensor."""
|
|
|
|
if discovery_info is None:
|
|
|
|
return
|
|
|
|
|
2022-12-22 21:00:17 +00:00
|
|
|
async_add_entities(
|
2021-07-22 13:29:50 +00:00
|
|
|
[
|
2022-12-22 21:00:17 +00:00
|
|
|
RainBirdSensor(discovery_info[description.key], description)
|
2021-07-27 16:06:46 +00:00
|
|
|
for description in BINARY_SENSOR_TYPES
|
2021-07-22 13:29:50 +00:00
|
|
|
],
|
|
|
|
True,
|
2019-09-26 09:24:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-12-27 20:17:20 +00:00
|
|
|
class RainBirdSensor(
|
|
|
|
CoordinatorEntity[RainbirdUpdateCoordinator[Union[int, bool]]], BinarySensorEntity
|
|
|
|
):
|
2019-09-26 09:24:03 +00:00
|
|
|
"""A sensor implementation for Rain Bird device."""
|
|
|
|
|
2021-07-22 13:29:50 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
2022-12-27 20:17:20 +00:00
|
|
|
coordinator: RainbirdUpdateCoordinator[int | bool],
|
2021-07-27 16:06:46 +00:00
|
|
|
description: BinarySensorEntityDescription,
|
|
|
|
) -> None:
|
2019-09-26 09:24:03 +00:00
|
|
|
"""Initialize the Rain Bird sensor."""
|
2022-12-22 21:00:17 +00:00
|
|
|
super().__init__(coordinator)
|
2021-07-27 16:06:46 +00:00
|
|
|
self.entity_description = description
|
2021-07-22 13:29:50 +00:00
|
|
|
|
2022-12-22 21:00:17 +00:00
|
|
|
@property
|
|
|
|
def is_on(self) -> bool | None:
|
|
|
|
"""Return True if entity is on."""
|
|
|
|
return None if self.coordinator.data is None else bool(self.coordinator.data)
|