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
|
|
|
|
|
2021-07-27 16:06:46 +00:00
|
|
|
from homeassistant.components.binary_sensor import (
|
|
|
|
BinarySensorEntity,
|
|
|
|
BinarySensorEntityDescription,
|
|
|
|
)
|
2023-01-07 17:34:01 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2022-01-03 10:35:02 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2022-12-27 20:17:20 +00:00
|
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
2019-09-26 09:24:03 +00:00
|
|
|
|
2023-01-07 17:34:01 +00:00
|
|
|
from .const import DOMAIN
|
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__)
|
|
|
|
|
|
|
|
|
2023-01-07 17:34:01 +00:00
|
|
|
RAIN_SENSOR_ENTITY_DESCRIPTION = BinarySensorEntityDescription(
|
|
|
|
key="rainsensor",
|
|
|
|
name="Rainsensor",
|
|
|
|
icon="mdi:water",
|
2022-12-22 21:00:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-01-07 17:34:01 +00:00
|
|
|
async def async_setup_entry(
|
2022-01-03 10:35:02 +00:00
|
|
|
hass: HomeAssistant,
|
2023-01-07 17:34:01 +00:00
|
|
|
config_entry: ConfigEntry,
|
2022-12-22 21:00:17 +00:00
|
|
|
async_add_entities: AddEntitiesCallback,
|
2022-01-03 10:35:02 +00:00
|
|
|
) -> None:
|
2023-01-07 17:34:01 +00:00
|
|
|
"""Set up entry for a Rain Bird binary_sensor."""
|
|
|
|
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
|
|
|
async_add_entities([RainBirdSensor(coordinator, RAIN_SENSOR_ENTITY_DESCRIPTION)])
|
2019-09-26 09:24:03 +00:00
|
|
|
|
|
|
|
|
2023-01-07 17:34:01 +00:00
|
|
|
class RainBirdSensor(CoordinatorEntity[RainbirdUpdateCoordinator], 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,
|
2023-01-07 17:34:01 +00:00
|
|
|
coordinator: RainbirdUpdateCoordinator,
|
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
|
2023-01-07 17:34:01 +00:00
|
|
|
self._attr_unique_id = f"{coordinator.serial_number}-{description.key}"
|
|
|
|
self._attr_device_info = coordinator.device_info
|
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."""
|
2023-01-07 17:34:01 +00:00
|
|
|
return self.coordinator.data.rain
|