From 326513af906f968900fa83c012588b715444006e Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Thu, 28 Feb 2019 18:58:39 -0700 Subject: [PATCH] Add pause/unpause services to RainMachine (#21548) * Add pause/unpause services to RainMachine * Update requirements --- .../components/rainmachine/__init__.py | 21 +++++++++++++++++-- .../components/rainmachine/services.yaml | 8 +++++++ requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/rainmachine/__init__.py b/homeassistant/components/rainmachine/__init__.py index 0591af8acfa..6da5b2d6c10 100644 --- a/homeassistant/components/rainmachine/__init__.py +++ b/homeassistant/components/rainmachine/__init__.py @@ -19,7 +19,7 @@ from .config_flow import configured_instances from .const import ( DATA_CLIENT, DEFAULT_PORT, DEFAULT_SCAN_INTERVAL, DEFAULT_SSL, DOMAIN) -REQUIREMENTS = ['regenmaschine==1.1.0'] +REQUIREMENTS = ['regenmaschine==1.2.0'] _LOGGER = logging.getLogger(__name__) @@ -31,6 +31,7 @@ ZONE_UPDATE_TOPIC = '{0}_zone_update'.format(DOMAIN) CONF_CONTROLLERS = 'controllers' CONF_PROGRAM_ID = 'program_id' +CONF_SECONDS = 'seconds' CONF_ZONE_ID = 'zone_id' CONF_ZONE_RUN_TIME = 'zone_run_time' @@ -73,6 +74,10 @@ SENSOR_SCHEMA = vol.Schema({ vol.All(cv.ensure_list, [vol.In(SENSORS)]) }) +SERVICE_PAUSE_WATERING = vol.Schema({ + vol.Required(CONF_SECONDS): cv.positive_int, +}) + SERVICE_START_PROGRAM_SCHEMA = vol.Schema({ vol.Required(CONF_PROGRAM_ID): cv.positive_int, }) @@ -184,6 +189,11 @@ async def async_setup_entry(hass, config_entry): refresh, timedelta(seconds=config_entry.data[CONF_SCAN_INTERVAL])) + async def pause_watering(service): + """Pause watering for a set number of seconds.""" + await rainmachine.client.watering.pause_all(service.data[CONF_SECONDS]) + async_dispatcher_send(hass, PROGRAM_UPDATE_TOPIC) + async def start_program(service): """Start a particular program.""" await rainmachine.client.programs.start(service.data[CONF_PROGRAM_ID]) @@ -210,12 +220,19 @@ async def async_setup_entry(hass, config_entry): await rainmachine.client.zones.stop(service.data[CONF_ZONE_ID]) async_dispatcher_send(hass, ZONE_UPDATE_TOPIC) + async def unpause_watering(service): + """Unpause watering.""" + await rainmachine.client.watering.unpause_all() + async_dispatcher_send(hass, PROGRAM_UPDATE_TOPIC) + for service, method, schema in [ + ('pause_watering', pause_watering, SERVICE_PAUSE_WATERING), ('start_program', start_program, SERVICE_START_PROGRAM_SCHEMA), ('start_zone', start_zone, SERVICE_START_ZONE_SCHEMA), ('stop_all', stop_all, {}), ('stop_program', stop_program, SERVICE_STOP_PROGRAM_SCHEMA), - ('stop_zone', stop_zone, SERVICE_STOP_ZONE_SCHEMA) + ('stop_zone', stop_zone, SERVICE_STOP_ZONE_SCHEMA), + ('unpause_watering', unpause_watering, {}), ]: hass.services.async_register(DOMAIN, service, method, schema=schema) diff --git a/homeassistant/components/rainmachine/services.yaml b/homeassistant/components/rainmachine/services.yaml index a8c77628c8f..a165c14d0e6 100644 --- a/homeassistant/components/rainmachine/services.yaml +++ b/homeassistant/components/rainmachine/services.yaml @@ -1,6 +1,12 @@ # Describes the format for available RainMachine services --- +pause_watering: + description: Pause all watering for a number of seconds. + fields: + seconds: + description: The number of seconds to pause. + example: 30 start_program: description: Start a program. fields: @@ -30,3 +36,5 @@ stop_zone: zone_id: description: The zone to stop. example: 3 +unpause_watering: + description: Unpause all watering. diff --git a/requirements_all.txt b/requirements_all.txt index 5b91e095aa3..93397ed18e8 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1486,7 +1486,7 @@ raspyrfm-client==1.2.8 recollect-waste==1.0.1 # homeassistant.components.rainmachine -regenmaschine==1.1.0 +regenmaschine==1.2.0 # homeassistant.components.python_script restrictedpython==4.0b8 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 89c071e0ad3..8513a00ad30 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -254,7 +254,7 @@ pyunifi==2.16 pywebpush==1.6.0 # homeassistant.components.rainmachine -regenmaschine==1.1.0 +regenmaschine==1.2.0 # homeassistant.components.python_script restrictedpython==4.0b8