From 6652af5cc0ea898ebfe76d97812df029b873d4da Mon Sep 17 00:00:00 2001 From: mvn23 Date: Thu, 23 Jul 2020 20:24:17 +0200 Subject: [PATCH] Add set_central_heating_ovrd service to opentherm_gw (#34425) * Add set_central_heating_ovrd service to opentherm_gw * Use await instead of async_create_task Use await instead of async_create_task as per review. Co-authored-by: J. Nick Koston * Use boolean values for service call to opentherm_gw.set_central_heating_ovrd Co-authored-by: J. Nick Koston --- .../components/opentherm_gw/__init__.py | 22 +++++++++++++++++++ .../components/opentherm_gw/const.py | 2 ++ .../components/opentherm_gw/services.yaml | 16 ++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/homeassistant/components/opentherm_gw/__init__.py b/homeassistant/components/opentherm_gw/__init__.py index 71fd104bd2f..8d1d3ae4d62 100644 --- a/homeassistant/components/opentherm_gw/__init__.py +++ b/homeassistant/components/opentherm_gw/__init__.py @@ -29,6 +29,7 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_send from .const import ( + ATTR_CH_OVRD, ATTR_DHW_OVRD, ATTR_GW_ID, ATTR_LEVEL, @@ -39,6 +40,7 @@ from .const import ( DATA_OPENTHERM_GW, DOMAIN, SERVICE_RESET_GATEWAY, + SERVICE_SET_CH_OVRD, SERVICE_SET_CLOCK, SERVICE_SET_CONTROL_SETPOINT, SERVICE_SET_GPIO_MODE, @@ -127,6 +129,14 @@ def register_services(hass): ) } ) + service_set_central_heating_ovrd_schema = vol.Schema( + { + vol.Required(ATTR_GW_ID): vol.All( + cv.string, vol.In(hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS]) + ), + vol.Required(ATTR_CH_OVRD): cv.boolean, + } + ) service_set_clock_schema = vol.Schema( { vol.Required(ATTR_GW_ID): vol.All( @@ -235,6 +245,18 @@ def register_services(hass): DOMAIN, SERVICE_RESET_GATEWAY, reset_gateway, service_reset_schema ) + async def set_ch_ovrd(call): + """Set the central heating override on the OpenTherm Gateway.""" + gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]] + await gw_dev.gateway.set_ch_enable_bit(1 if call.data[ATTR_CH_OVRD] else 0) + + hass.services.async_register( + DOMAIN, + SERVICE_SET_CH_OVRD, + set_ch_ovrd, + service_set_central_heating_ovrd_schema, + ) + async def set_control_setpoint(call): """Set the control setpoint on the OpenTherm Gateway.""" gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]] diff --git a/homeassistant/components/opentherm_gw/const.py b/homeassistant/components/opentherm_gw/const.py index 14b54366b4a..5be29522535 100644 --- a/homeassistant/components/opentherm_gw/const.py +++ b/homeassistant/components/opentherm_gw/const.py @@ -12,6 +12,7 @@ from homeassistant.const import ( ATTR_GW_ID = "gateway_id" ATTR_LEVEL = "level" ATTR_DHW_OVRD = "dhw_override" +ATTR_CH_OVRD = "ch_override" CONF_CLIMATE = "climate" CONF_FLOOR_TEMP = "floor_temperature" @@ -27,6 +28,7 @@ DEVICE_CLASS_PROBLEM = "problem" DOMAIN = "opentherm_gw" SERVICE_RESET_GATEWAY = "reset_gateway" +SERVICE_SET_CH_OVRD = "set_central_heating_ovrd" SERVICE_SET_CLOCK = "set_clock" SERVICE_SET_CONTROL_SETPOINT = "set_control_setpoint" SERVICE_SET_HOT_WATER_SETPOINT = "set_hot_water_setpoint" diff --git a/homeassistant/components/opentherm_gw/services.yaml b/homeassistant/components/opentherm_gw/services.yaml index f60648ee8d4..8a1bddc2100 100644 --- a/homeassistant/components/opentherm_gw/services.yaml +++ b/homeassistant/components/opentherm_gw/services.yaml @@ -7,6 +7,22 @@ reset_gateway: description: The gateway_id of the OpenTherm Gateway. example: "opentherm_gateway" +set_central_heating_ovrd: + description: > + Set the central heating override option on the gateway. + When overriding the control setpoint (via a set_control_setpoint service call with a value other than 0), the gateway automatically enables the central heating override to start heating. + This service can then be used to control the central heating override status. + To return control of the central heating to the thermostat, call the set_control_setpoint service with temperature value 0. + You will only need this if you are writing your own software thermostat. + fields: + gateway_id: + description: The gateway_id of the OpenTherm Gateway. + example: "opentherm_gateway" + ch_override: + description: > + The desired boolean value for the central heating override. + example: "on" + set_clock: description: Set the clock and day of the week on the connected thermostat. fields: