* Rainbird config flow Convert rainbird to a config flow. Still need to handle irrigation numbers. * Add options for irrigation time and deprecate yaml * Combine exception handling paths to get 100% test coverage * Bump the rainird config deprecation release * Apply suggestions from code review Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Remove unnecessary sensor/binary sensor and address some PR feedback * Simplify configuration flow and options based on PR feedback * Consolidate data update coordinators to simplify overall integration * Fix type error on python3.9 * Handle yaml name import * Fix naming import post serialization * Parallelize requests to the device * Complete conversion to entity service * Update homeassistant/components/rainbird/switch.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/rainbird/config_flow.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Remove unused import * Set default duration in options used in tests * Add separate devices for each sprinkler zone and update service to use config entry Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
"""Support for Rain Bird Irrigation system LNK WiFi Module."""
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
from homeassistant.helpers.typing import StateType
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
|
|
from .const import DOMAIN
|
|
from .coordinator import RainbirdUpdateCoordinator
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
RAIN_DELAY_ENTITY_DESCRIPTION = SensorEntityDescription(
|
|
key="raindelay",
|
|
name="Raindelay",
|
|
icon="mdi:water-off",
|
|
)
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
config_entry: ConfigEntry,
|
|
async_add_entities: AddEntitiesCallback,
|
|
) -> None:
|
|
"""Set up entry for a Rain Bird sensor."""
|
|
async_add_entities(
|
|
[
|
|
RainBirdSensor(
|
|
hass.data[DOMAIN][config_entry.entry_id],
|
|
RAIN_DELAY_ENTITY_DESCRIPTION,
|
|
)
|
|
]
|
|
)
|
|
|
|
|
|
class RainBirdSensor(CoordinatorEntity[RainbirdUpdateCoordinator], SensorEntity):
|
|
"""A sensor implementation for Rain Bird device."""
|
|
|
|
def __init__(
|
|
self,
|
|
coordinator: RainbirdUpdateCoordinator,
|
|
description: SensorEntityDescription,
|
|
) -> None:
|
|
"""Initialize the Rain Bird sensor."""
|
|
super().__init__(coordinator)
|
|
self.entity_description = description
|
|
self._attr_unique_id = f"{coordinator.serial_number}-{description.key}"
|
|
self._attr_device_info = coordinator.device_info
|
|
|
|
@property
|
|
def native_value(self) -> StateType:
|
|
"""Return the value reported by the sensor."""
|
|
return self.coordinator.data.rain_delay
|