From 027d125617af8c016c1cc9a3906b8868f7543154 Mon Sep 17 00:00:00 2001 From: Nick Adams <4012017+Nick-Adams-AU@users.noreply.github.com> Date: Tue, 2 Mar 2021 22:58:41 +1000 Subject: [PATCH] Add services for izone airflow min/max (#45727) * Create airflow_min and airflow_max services for the izone component * Bump pizone library requirement --- homeassistant/components/izone/climate.py | 62 ++++++++++++++++++++ homeassistant/components/izone/manifest.json | 2 +- homeassistant/components/izone/services.yaml | 18 ++++++ requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 5 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 homeassistant/components/izone/services.yaml diff --git a/homeassistant/components/izone/climate.py b/homeassistant/components/izone/climate.py index 776d3f120c9..5f00720ae9d 100644 --- a/homeassistant/components/izone/climate.py +++ b/homeassistant/components/izone/climate.py @@ -1,8 +1,10 @@ """Support for the iZone HVAC.""" + import logging from typing import List, Optional from pizone import Controller, Zone +import voluptuous as vol from homeassistant.components.climate import ClimateEntity from homeassistant.components.climate.const import ( @@ -24,12 +26,14 @@ from homeassistant.components.climate.const import ( ) from homeassistant.const import ( ATTR_TEMPERATURE, + CONF_ENTITY_ID, CONF_EXCLUDE, PRECISION_HALVES, PRECISION_TENTHS, TEMP_CELSIUS, ) from homeassistant.core import callback +from homeassistant.helpers import config_validation as cv, entity_platform from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.temperature import display_temp as show_temp from homeassistant.helpers.typing import ConfigType, HomeAssistantType @@ -54,6 +58,20 @@ _IZONE_FAN_TO_HA = { Controller.Fan.AUTO: FAN_AUTO, } +ATTR_AIRFLOW = "airflow" + +IZONE_SERVICE_AIRFLOW_MIN = "airflow_min" +IZONE_SERVICE_AIRFLOW_MAX = "airflow_max" + +IZONE_SERVICE_AIRFLOW_SCHEMA = vol.Schema( + { + vol.Required(CONF_ENTITY_ID): cv.entity_id, + vol.Required(ATTR_AIRFLOW): vol.All( + vol.Coerce(int), vol.Range(min=0, max=100), msg="invalid airflow" + ), + } +) + async def async_setup_entry( hass: HomeAssistantType, config: ConfigType, async_add_entities @@ -83,6 +101,18 @@ async def async_setup_entry( # connect to register any further components async_dispatcher_connect(hass, DISPATCH_CONTROLLER_DISCOVERED, init_controller) + platform = entity_platform.current_platform.get() + platform.async_register_entity_service( + IZONE_SERVICE_AIRFLOW_MIN, + IZONE_SERVICE_AIRFLOW_SCHEMA, + "async_set_airflow_min", + ) + platform.async_register_entity_service( + IZONE_SERVICE_AIRFLOW_MAX, + IZONE_SERVICE_AIRFLOW_SCHEMA, + "async_set_airflow_max", + ) + return True @@ -572,6 +602,38 @@ class ZoneDevice(ClimateEntity): """Return the maximum temperature.""" return self._controller.max_temp + @property + def airflow_min(self): + """Return the minimum air flow.""" + return self._zone.airflow_min + + @property + def airflow_max(self): + """Return the maximum air flow.""" + return self._zone.airflow_max + + @property + def device_state_attributes(self): + """Return the optional state attributes.""" + return { + "airflow_min": self._zone.airflow_min, + "airflow_max": self._zone.airflow_max, + } + + async def async_set_airflow_min(self, **kwargs): + """Set new airflow minimum.""" + await self._controller.wrap_and_catch( + self._zone.set_airflow_min(int(kwargs[ATTR_AIRFLOW])) + ) + self.async_write_ha_state() + + async def async_set_airflow_max(self, **kwargs): + """Set new airflow maximum.""" + await self._controller.wrap_and_catch( + self._zone.set_airflow_max(int(kwargs[ATTR_AIRFLOW])) + ) + self.async_write_ha_state() + async def async_set_temperature(self, **kwargs): """Set new target temperature.""" if self._zone.mode != Zone.Mode.AUTO: diff --git a/homeassistant/components/izone/manifest.json b/homeassistant/components/izone/manifest.json index 479ac496906..bed7654b7e8 100644 --- a/homeassistant/components/izone/manifest.json +++ b/homeassistant/components/izone/manifest.json @@ -2,7 +2,7 @@ "domain": "izone", "name": "iZone", "documentation": "https://www.home-assistant.io/integrations/izone", - "requirements": ["python-izone==1.1.3"], + "requirements": ["python-izone==1.1.4"], "codeowners": ["@Swamp-Ig"], "config_flow": true, "homekit": { diff --git a/homeassistant/components/izone/services.yaml b/homeassistant/components/izone/services.yaml new file mode 100644 index 00000000000..14aaa69349a --- /dev/null +++ b/homeassistant/components/izone/services.yaml @@ -0,0 +1,18 @@ +airflow_min: + description: Set the airflow minimum percent for a zone + fields: + entity_id: + description: iZone Zone entity + example: "climate.bed_1" + airflow: + description: Airflow percent in 5% increments + example: "95" +airflow_max: + description: Set the airflow maximum percent for a zone + fields: + entity_id: + description: iZone Zone entity + example: "climate.bed_1" + airflow: + description: Airflow percent in 5% increments + example: "95" diff --git a/requirements_all.txt b/requirements_all.txt index 75e660f0fb0..09c328b2842 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1784,7 +1784,7 @@ python-gitlab==1.6.0 python-hpilo==4.3 # homeassistant.components.izone -python-izone==1.1.3 +python-izone==1.1.4 # homeassistant.components.joaoapps_join python-join-api==0.0.6 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 2037a55bd49..63eeddffe5a 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -930,7 +930,7 @@ python-ecobee-api==0.2.10 python-forecastio==1.4.0 # homeassistant.components.izone -python-izone==1.1.3 +python-izone==1.1.4 # homeassistant.components.juicenet python-juicenet==1.0.1