diff --git a/homeassistant/components/rainbird/services.yaml b/homeassistant/components/rainbird/services.yaml index e1fa1879549..3d5f55dba14 100644 --- a/homeassistant/components/rainbird/services.yaml +++ b/homeassistant/components/rainbird/services.yaml @@ -19,3 +19,16 @@ start_irrigation: min: 1 max: 1440 unit_of_measurement: "minutes" +set_rain_delay: + name: Set rain delay + description: Set how long automatic irrigation is turned off. + fields: + duration: + name: Duration + description: Duration for this system to be turned off. + required: true + selector: + number: + min: 0 + max: 14 + unit_of_measurement: "days" diff --git a/homeassistant/components/rainbird/switch.py b/homeassistant/components/rainbird/switch.py index 7acb9740616..df83f054275 100644 --- a/homeassistant/components/rainbird/switch.py +++ b/homeassistant/components/rainbird/switch.py @@ -11,6 +11,7 @@ from . import CONF_ZONES, DATA_RAINBIRD, DOMAIN, RAINBIRD_CONTROLLER ATTR_DURATION = "duration" SERVICE_START_IRRIGATION = "start_irrigation" +SERVICE_SET_RAIN_DELAY = "set_rain_delay" SERVICE_SCHEMA_IRRIGATION = vol.Schema( { @@ -19,6 +20,12 @@ SERVICE_SCHEMA_IRRIGATION = vol.Schema( } ) +SERVICE_SCHEMA_RAIN_DELAY = vol.Schema( + { + vol.Required(ATTR_DURATION): cv.positive_float, + } +) + def setup_platform(hass, config, add_entities, discovery_info=None): """Set up Rain Bird switches over a Rain Bird controller.""" @@ -64,6 +71,18 @@ def setup_platform(hass, config, add_entities, discovery_info=None): schema=SERVICE_SCHEMA_IRRIGATION, ) + def set_rain_delay(service): + duration = service.data[ATTR_DURATION] + + controller.set_rain_delay(duration) + + hass.services.register( + DOMAIN, + SERVICE_SET_RAIN_DELAY, + set_rain_delay, + schema=SERVICE_SCHEMA_RAIN_DELAY, + ) + class RainBirdSwitch(SwitchEntity): """Representation of a Rain Bird switch."""