Add config flow to Hydrawise (#95589)
* Add config flow to Hydrawise * Raise an issue when a YAML config is detected * Add a test for YAML import * Add missing __init__.py * Update CODEOWNERS * Update requirements_test_all.txt * Add config flow data to strings.json * Hande scan_interval not being in YAML on import * Fix requirements * Update deprecation dates * Update requirements_test_all.txt * Changes from review * Update homeassistant/components/hydrawise/__init__.py Co-authored-by: G Johansson <goran.johansson@shiftit.se> * Add already_configured to strings.json * Add back setup_platform functions * Apply suggestions from code review Co-authored-by: G Johansson <goran.johansson@shiftit.se> * Add back setup_platform * Update requirements_test_all.txt * Run black on hydrawise/*.py * Add missing import of HOMEASSISTANT_DOMAIN * Use more specific errors in config flow * Add additional tests * Update config flow to use pydrawise.legacy * Re-work YAML deprecation issues * Revert some changes to binary_sensor, as requested in review * Changes requested during review * Apply suggestions from code review Co-authored-by: G Johansson <goran.johansson@shiftit.se> * Remove unused STE_USER_DATA_SCHEMA Co-authored-by: G Johansson <goran.johansson@shiftit.se> * Update comment in setup_platform * Re-work the config flow again * Apply suggestions from code review Co-authored-by: G Johansson <goran.johansson@shiftit.se> * Update tests * Add back the _default_watering_timer attribute * Bump deprecation dates * Update requirements_test_all.txt * Update CODEOWNERS --------- Co-authored-by: G Johansson <goran.johansson@shiftit.se> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
28dc17c0b3
commit
f8a8fe760d
16 changed files with 478 additions and 57 deletions
|
@ -10,6 +10,7 @@ from homeassistant.components.binary_sensor import (
|
|||
BinarySensorEntity,
|
||||
BinarySensorEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_MONITORED_CONDITIONS
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -38,6 +39,8 @@ BINARY_SENSOR_KEYS: list[str] = [
|
|||
desc.key for desc in (BINARY_SENSOR_STATUS, *BINARY_SENSOR_TYPES)
|
||||
]
|
||||
|
||||
# Deprecated since Home Assistant 2023.10.0
|
||||
# Can be removed completely in 2024.4.0
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Optional(CONF_MONITORED_CONDITIONS, default=BINARY_SENSOR_KEYS): vol.All(
|
||||
|
@ -54,32 +57,39 @@ def setup_platform(
|
|||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up a sensor for a Hydrawise device."""
|
||||
coordinator: HydrawiseDataUpdateCoordinator = hass.data[DOMAIN]
|
||||
hydrawise: LegacyHydrawise = coordinator.api
|
||||
monitored_conditions = config[CONF_MONITORED_CONDITIONS]
|
||||
# We don't need to trigger import flow from here as it's triggered from `__init__.py`
|
||||
return
|
||||
|
||||
entities = []
|
||||
if BINARY_SENSOR_STATUS.key in monitored_conditions:
|
||||
entities.append(
|
||||
HydrawiseBinarySensor(
|
||||
data=hydrawise.current_controller,
|
||||
coordinator=coordinator,
|
||||
description=BINARY_SENSOR_STATUS,
|
||||
)
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Hydrawise binary_sensor platform."""
|
||||
coordinator: HydrawiseDataUpdateCoordinator = hass.data[DOMAIN][
|
||||
config_entry.entry_id
|
||||
]
|
||||
hydrawise: LegacyHydrawise = coordinator.api
|
||||
|
||||
entities = [
|
||||
HydrawiseBinarySensor(
|
||||
data=hydrawise.current_controller,
|
||||
coordinator=coordinator,
|
||||
description=BINARY_SENSOR_STATUS,
|
||||
)
|
||||
]
|
||||
|
||||
# create a sensor for each zone
|
||||
for zone in hydrawise.relays:
|
||||
for description in BINARY_SENSOR_TYPES:
|
||||
if description.key not in monitored_conditions:
|
||||
continue
|
||||
entities.append(
|
||||
HydrawiseBinarySensor(
|
||||
data=zone, coordinator=coordinator, description=description
|
||||
)
|
||||
)
|
||||
|
||||
add_entities(entities, True)
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class HydrawiseBinarySensor(HydrawiseEntity, BinarySensorEntity):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue