diff --git a/homeassistant/components/rainmachine/__init__.py b/homeassistant/components/rainmachine/__init__.py index 8cc3b3d5e80..a0b11653272 100644 --- a/homeassistant/components/rainmachine/__init__.py +++ b/homeassistant/components/rainmachine/__init__.py @@ -20,6 +20,7 @@ from homeassistant.const import ( CONF_PASSWORD, CONF_PORT, CONF_SSL, + CONF_UNIT_OF_MEASUREMENT, Platform, ) from homeassistant.core import HomeAssistant, ServiceCall, callback @@ -79,9 +80,19 @@ CONF_SECONDS = "seconds" CONF_SOLARRAD = "solarrad" CONF_TEMPERATURE = "temperature" CONF_TIMESTAMP = "timestamp" +CONF_UNITS = "units" +CONF_VALUE = "value" CONF_WEATHER = "weather" CONF_WIND = "wind" +# Config Validator for Flow Meter Data +CV_FLOW_METER_VALID_UNITS = { + "clicks", + "gal", + "litre", + "m3", +} + # Config Validators for Weather Service Data CV_WX_DATA_VALID_PERCENTAGE = vol.All(vol.Coerce(int), vol.Range(min=0, max=100)) CV_WX_DATA_VALID_TEMP_RANGE = vol.All(vol.Coerce(float), vol.Range(min=-40.0, max=40.0)) @@ -91,6 +102,7 @@ CV_WX_DATA_VALID_PRESSURE = vol.All(vol.Coerce(float), vol.Range(min=60.0, max=1 CV_WX_DATA_VALID_SOLARRAD = vol.All(vol.Coerce(float), vol.Range(min=0.0, max=5.0)) SERVICE_NAME_PAUSE_WATERING = "pause_watering" +SERVICE_NAME_PUSH_FLOW_METER_DATA = "push_flow_meter_data" SERVICE_NAME_PUSH_WEATHER_DATA = "push_weather_data" SERVICE_NAME_RESTRICT_WATERING = "restrict_watering" SERVICE_NAME_STOP_ALL = "stop_all" @@ -109,6 +121,15 @@ SERVICE_PAUSE_WATERING_SCHEMA = SERVICE_SCHEMA.extend( } ) +SERVICE_PUSH_FLOW_METER_DATA_SCHEMA = SERVICE_SCHEMA.extend( + { + vol.Required(CONF_VALUE): cv.positive_float, + vol.Optional(CONF_UNIT_OF_MEASUREMENT): vol.All( + cv.string, vol.In(CV_FLOW_METER_VALID_UNITS) + ), + } +) + SERVICE_PUSH_WEATHER_DATA_SCHEMA = SERVICE_SCHEMA.extend( { vol.Optional(CONF_TIMESTAMP): cv.positive_float, @@ -320,6 +341,17 @@ async def async_setup_entry( # noqa: C901 """Pause watering for a set number of seconds.""" await controller.watering.pause_all(call.data[CONF_SECONDS]) + @call_with_controller(update_programs_and_zones=False) + async def async_push_flow_meter_data( + call: ServiceCall, controller: Controller + ) -> None: + """Push flow meter data to the device.""" + value = call.data[CONF_VALUE] + if units := call.data.get(CONF_UNIT_OF_MEASUREMENT): + await controller.watering.post_flowmeter(value=value, units=units) + else: + await controller.watering.post_flowmeter(value=value) + @call_with_controller(update_programs_and_zones=False) async def async_push_weather_data( call: ServiceCall, controller: Controller @@ -378,6 +410,11 @@ async def async_setup_entry( # noqa: C901 SERVICE_PAUSE_WATERING_SCHEMA, async_pause_watering, ), + ( + SERVICE_NAME_PUSH_FLOW_METER_DATA, + SERVICE_PUSH_FLOW_METER_DATA_SCHEMA, + async_push_flow_meter_data, + ), ( SERVICE_NAME_PUSH_WEATHER_DATA, SERVICE_PUSH_WEATHER_DATA_SCHEMA, @@ -419,6 +456,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: # defined during integration setup: for service_name in ( SERVICE_NAME_PAUSE_WATERING, + SERVICE_NAME_PUSH_FLOW_METER_DATA, SERVICE_NAME_PUSH_WEATHER_DATA, SERVICE_NAME_RESTRICT_WATERING, SERVICE_NAME_STOP_ALL, diff --git a/homeassistant/components/rainmachine/manifest.json b/homeassistant/components/rainmachine/manifest.json index ca7543bfb38..08fef4973bc 100644 --- a/homeassistant/components/rainmachine/manifest.json +++ b/homeassistant/components/rainmachine/manifest.json @@ -3,7 +3,7 @@ "name": "RainMachine", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/rainmachine", - "requirements": ["regenmaschine==2022.09.2"], + "requirements": ["regenmaschine==2022.10.0"], "codeowners": ["@bachya"], "iot_class": "local_polling", "homekit": { diff --git a/homeassistant/components/rainmachine/services.yaml b/homeassistant/components/rainmachine/services.yaml index 198aec94a22..9aa2bb7f50a 100644 --- a/homeassistant/components/rainmachine/services.yaml +++ b/homeassistant/components/rainmachine/services.yaml @@ -97,6 +97,37 @@ unpause_watering: selector: device: integration: rainmachine +push_flow_meter_data: + name: Push Flow Meter Data + description: Push Flow Meter data to the RainMachine device. + fields: + device_id: + name: Controller + description: The controller to send flow meter data to + required: true + selector: + device: + integration: rainmachine + value: + name: Value + description: The flow meter value to send + required: true + selector: + number: + min: 0.0 + max: 1000000000.0 + step: 0.1 + mode: box + unit_of_measurement: + name: Unit of Measurement + description: The flow meter units to send + selector: + select: + options: + - "clicks" + - "gal" + - "litre" + - "m3" push_weather_data: name: Push Weather Data description: >- diff --git a/requirements_all.txt b/requirements_all.txt index e8991661ddd..c25834d151b 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2147,7 +2147,7 @@ raincloudy==0.0.7 raspyrfm-client==1.2.8 # homeassistant.components.rainmachine -regenmaschine==2022.09.2 +regenmaschine==2022.10.0 # homeassistant.components.renault renault-api==0.1.11 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 82e87ca9ae2..f4d4e2ed2ba 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1483,7 +1483,7 @@ radios==0.1.1 radiotherm==2.1.0 # homeassistant.components.rainmachine -regenmaschine==2022.09.2 +regenmaschine==2022.10.0 # homeassistant.components.renault renault-api==0.1.11