Add program/zone enable/disable services to RainMachine (#21785)

This commit is contained in:
Aaron Bach 2019-03-13 08:20:13 -06:00 committed by GitHub
parent 897862fca4
commit a71394a0ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 0 deletions

View file

@ -74,6 +74,14 @@ SENSOR_SCHEMA = vol.Schema({
vol.All(cv.ensure_list, [vol.In(SENSORS)])
})
SERVICE_ALTER_PROGRAM = vol.Schema({
vol.Required(CONF_PROGRAM_ID): cv.positive_int,
})
SERVICE_ALTER_ZONE = vol.Schema({
vol.Required(CONF_ZONE_ID): cv.positive_int,
})
SERVICE_PAUSE_WATERING = vol.Schema({
vol.Required(CONF_SECONDS): cv.positive_int,
})
@ -189,6 +197,27 @@ async def async_setup_entry(hass, config_entry):
refresh,
timedelta(seconds=config_entry.data[CONF_SCAN_INTERVAL]))
async def disable_program(service):
"""Disable a program."""
await rainmachine.client.programs.disable(
service.data[CONF_PROGRAM_ID])
async_dispatcher_send(hass, PROGRAM_UPDATE_TOPIC)
async def disable_zone(service):
"""Disable a zone."""
await rainmachine.client.zones.disable(service.data[CONF_ZONE_ID])
async_dispatcher_send(hass, ZONE_UPDATE_TOPIC)
async def enable_program(service):
"""Enable a program."""
await rainmachine.client.programs.enable(service.data[CONF_PROGRAM_ID])
async_dispatcher_send(hass, PROGRAM_UPDATE_TOPIC)
async def enable_zone(service):
"""Enable a zone."""
await rainmachine.client.zones.enable(service.data[CONF_ZONE_ID])
async_dispatcher_send(hass, ZONE_UPDATE_TOPIC)
async def pause_watering(service):
"""Pause watering for a set number of seconds."""
await rainmachine.client.watering.pause_all(service.data[CONF_SECONDS])
@ -226,6 +255,10 @@ async def async_setup_entry(hass, config_entry):
async_dispatcher_send(hass, PROGRAM_UPDATE_TOPIC)
for service, method, schema in [
('disable_program', disable_program, SERVICE_ALTER_PROGRAM),
('disable_zone', disable_zone, SERVICE_ALTER_ZONE),
('enable_program', enable_program, SERVICE_ALTER_PROGRAM),
('enable_zone', enable_zone, SERVICE_ALTER_ZONE),
('pause_watering', pause_watering, SERVICE_PAUSE_WATERING),
('start_program', start_program, SERVICE_START_PROGRAM_SCHEMA),
('start_zone', start_zone, SERVICE_START_ZONE_SCHEMA),

View file

@ -1,6 +1,30 @@
# Describes the format for available RainMachine services
---
disable_program:
description: Disable a program.
fields:
program_id:
description: The program to disable.
example: 3
disable_zone:
description: Disable a zone.
fields:
zone_id:
description: The zone to disable.
example: 3
enable_program:
description: Enable a program.
fields:
program_id:
description: The program to enable.
example: 3
enable_zone:
description: Enable a zone.
fields:
zone_id:
description: The zone to enable.
example: 3
pause_watering:
description: Pause all watering for a number of seconds.
fields: