Add config flow for Rain Bird (#85271)
* 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>
This commit is contained in:
parent
e3e64c103d
commit
5000c426c6
19 changed files with 1016 additions and 471 deletions
|
@ -2,69 +2,58 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Union
|
||||
|
||||
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 ConfigType, DiscoveryInfoType, StateType
|
||||
from homeassistant.helpers.typing import StateType
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import SENSOR_TYPE_RAINDELAY, SENSOR_TYPE_RAINSENSOR
|
||||
from .const import DOMAIN
|
||||
from .coordinator import RainbirdUpdateCoordinator
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||
SensorEntityDescription(
|
||||
key=SENSOR_TYPE_RAINSENSOR,
|
||||
name="Rainsensor",
|
||||
icon="mdi:water",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key=SENSOR_TYPE_RAINDELAY,
|
||||
name="Raindelay",
|
||||
icon="mdi:water-off",
|
||||
),
|
||||
RAIN_DELAY_ENTITY_DESCRIPTION = SensorEntityDescription(
|
||||
key="raindelay",
|
||||
name="Raindelay",
|
||||
icon="mdi:water-off",
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up a Rain Bird sensor."""
|
||||
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
||||
"""Set up entry for a Rain Bird sensor."""
|
||||
async_add_entities(
|
||||
[
|
||||
RainBirdSensor(discovery_info[description.key], description)
|
||||
for description in SENSOR_TYPES
|
||||
],
|
||||
True,
|
||||
RainBirdSensor(
|
||||
hass.data[DOMAIN][config_entry.entry_id],
|
||||
RAIN_DELAY_ENTITY_DESCRIPTION,
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
class RainBirdSensor(
|
||||
CoordinatorEntity[RainbirdUpdateCoordinator[Union[int, bool]]], SensorEntity
|
||||
):
|
||||
class RainBirdSensor(CoordinatorEntity[RainbirdUpdateCoordinator], SensorEntity):
|
||||
"""A sensor implementation for Rain Bird device."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: RainbirdUpdateCoordinator[int | bool],
|
||||
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
|
||||
return self.coordinator.data.rain_delay
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue