Add `restrict_watering` and `unrestrict_watering` services to RainMachine (#64219)

pull/64463/head
Aaron Bach 2022-01-19 11:58:15 -07:00 committed by GitHub
parent 573e17472b
commit ff4ad8ddf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 1 deletions

View File

@ -67,9 +67,9 @@ UPDATE_INTERVALS = {
DATA_ZONES: timedelta(seconds=15),
}
# Constants expected by the RainMachine API for Service Data
CONF_CONDITION = "condition"
CONF_DEWPOINT = "dewpoint"
CONF_DURATION = "duration"
CONF_ET = "et"
CONF_MAXRH = "maxrh"
CONF_MAXTEMP = "maxtemp"
@ -95,8 +95,10 @@ CV_WX_DATA_VALID_SOLARRAD = vol.All(vol.Coerce(float), vol.Range(min=0.0, max=5.
SERVICE_NAME_PAUSE_WATERING = "pause_watering"
SERVICE_NAME_PUSH_WEATHER_DATA = "push_weather_data"
SERVICE_NAME_RESTRICT_WATERING = "restrict_watering"
SERVICE_NAME_STOP_ALL = "stop_all"
SERVICE_NAME_UNPAUSE_WATERING = "unpause_watering"
SERVICE_NAME_UNRESTRICT_WATERING = "unrestrict_watering"
SERVICE_SCHEMA = vol.Schema(
{
@ -129,6 +131,12 @@ SERVICE_PUSH_WEATHER_DATA_SCHEMA = SERVICE_SCHEMA.extend(
}
)
SERVICE_RESTRICT_WATERING_SCHEMA = SERVICE_SCHEMA.extend(
{
vol.Required(CONF_DURATION): cv.time_period,
}
)
@callback
def async_get_controller_for_service_call(
@ -275,6 +283,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
}
)
async def async_restrict_watering(call: ServiceCall) -> None:
"""Restrict watering for a time period."""
controller = async_get_controller_for_service_call(hass, call)
await controller.restrictions.restrict(call.data[CONF_DURATION])
await async_update_programs_and_zones(hass, entry)
async def async_stop_all(call: ServiceCall) -> None:
"""Stop all watering."""
controller = async_get_controller_for_service_call(hass, call)
@ -287,6 +301,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
await controller.watering.unpause_all()
await async_update_programs_and_zones(hass, entry)
async def async_unrestrict_watering(call: ServiceCall) -> None:
"""Unrestrict watering."""
controller = async_get_controller_for_service_call(hass, call)
await controller.restrictions.unrestrict()
await async_update_programs_and_zones(hass, entry)
for service_name, schema, method in (
(
SERVICE_NAME_PAUSE_WATERING,
@ -298,8 +318,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
SERVICE_PUSH_WEATHER_DATA_SCHEMA,
async_push_weather_data,
),
(
SERVICE_NAME_RESTRICT_WATERING,
SERVICE_RESTRICT_WATERING_SCHEMA,
async_restrict_watering,
),
(SERVICE_NAME_STOP_ALL, SERVICE_SCHEMA, async_stop_all),
(SERVICE_NAME_UNPAUSE_WATERING, SERVICE_SCHEMA, async_unpause_watering),
(
SERVICE_NAME_UNRESTRICT_WATERING,
SERVICE_SCHEMA,
async_unrestrict_watering,
),
):
if hass.services.has_service(DOMAIN, service_name):
continue
@ -325,8 +355,10 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
for service_name in (
SERVICE_NAME_PAUSE_WATERING,
SERVICE_NAME_PUSH_WEATHER_DATA,
SERVICE_NAME_RESTRICT_WATERING,
SERVICE_NAME_STOP_ALL,
SERVICE_NAME_UNPAUSE_WATERING,
SERVICE_NAME_UNRESTRICT_WATERING,
):
hass.services.async_remove(DOMAIN, service_name)

View File

@ -47,6 +47,24 @@ pause_watering:
min: 1
max: 43200
unit_of_measurement: seconds
restrict_watering:
name: Restrict All Watering
description: Restrict all watering activities from starting for a time period
fields:
device_id:
name: Controller
description: The controller whose watering activities should be restricted
required: true
selector:
device:
integration: rainmachine
duration:
name: Duration
description: The time period to restrict watering activities from starting
required: true
default: "01:00:00"
selector:
text:
start_program:
name: Start Program
description: Start a program
@ -241,3 +259,14 @@ push_weather_data:
max: 40
step: 0.1
unit_of_measurement: '°C'
unrestrict_watering:
name: Unrestrict All Watering
description: Unrestrict all watering activities
fields:
device_id:
name: Controller
description: The controller whose watering activities should be unrestricted
required: true
selector:
device:
integration: rainmachine