Add services for izone airflow min/max (#45727)

* Create airflow_min and airflow_max services for the izone component
* Bump pizone library requirement
This commit is contained in:
Nick Adams 2021-03-02 22:58:41 +10:00 committed by GitHub
parent 6b9abfc2c6
commit 027d125617
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 83 additions and 3 deletions

View file

@ -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: