diff --git a/homeassistant/components/rainmachine/__init__.py b/homeassistant/components/rainmachine/__init__.py index 78083e0d9da..6d986fa5c67 100644 --- a/homeassistant/components/rainmachine/__init__.py +++ b/homeassistant/components/rainmachine/__init__.py @@ -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), diff --git a/homeassistant/components/rainmachine/services.yaml b/homeassistant/components/rainmachine/services.yaml index a165c14d0e6..288161968de 100644 --- a/homeassistant/components/rainmachine/services.yaml +++ b/homeassistant/components/rainmachine/services.yaml @@ -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: