From 6a198087180de966d18cd13d819872e55e4b970e Mon Sep 17 00:00:00 2001 From: GraceGRD <123941606+GraceGRD@users.noreply.github.com> Date: Sat, 22 Jun 2024 12:53:13 +0200 Subject: [PATCH] Add transparent command to opentherm_gw (#116494) --- .../components/opentherm_gw/__init__.py | 30 +++++++++++++++++++ .../components/opentherm_gw/const.py | 3 ++ .../components/opentherm_gw/icons.json | 3 +- .../components/opentherm_gw/services.yaml | 16 ++++++++++ .../components/opentherm_gw/strings.json | 18 +++++++++++ 5 files changed, 69 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/opentherm_gw/__init__.py b/homeassistant/components/opentherm_gw/__init__.py index ca37b7baaef..46cc6f3daa0 100644 --- a/homeassistant/components/opentherm_gw/__init__.py +++ b/homeassistant/components/opentherm_gw/__init__.py @@ -36,6 +36,8 @@ from .const import ( ATTR_DHW_OVRD, ATTR_GW_ID, ATTR_LEVEL, + ATTR_TRANSP_ARG, + ATTR_TRANSP_CMD, CONF_CLIMATE, CONF_FLOOR_TEMP, CONF_PRECISION, @@ -46,6 +48,7 @@ from .const import ( DATA_OPENTHERM_GW, DOMAIN, SERVICE_RESET_GATEWAY, + SERVICE_SEND_TRANSP_CMD, SERVICE_SET_CH_OVRD, SERVICE_SET_CLOCK, SERVICE_SET_CONTROL_SETPOINT, @@ -254,6 +257,19 @@ def register_services(hass: HomeAssistant) -> None: ), } ) + service_send_transp_cmd_schema = vol.Schema( + { + vol.Required(ATTR_GW_ID): vol.All( + cv.string, vol.In(hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS]) + ), + vol.Required(ATTR_TRANSP_CMD): vol.All( + cv.string, vol.Length(min=2, max=2), vol.Coerce(str.upper) + ), + vol.Required(ATTR_TRANSP_ARG): vol.All( + cv.string, vol.Length(min=1, max=12) + ), + } + ) async def reset_gateway(call: ServiceCall) -> None: """Reset the OpenTherm Gateway.""" @@ -377,6 +393,20 @@ def register_services(hass: HomeAssistant) -> None: DOMAIN, SERVICE_SET_SB_TEMP, set_setback_temp, service_set_sb_temp_schema ) + async def send_transparent_cmd(call: ServiceCall) -> None: + """Send a transparent OpenTherm Gateway command.""" + gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]] + transp_cmd = call.data[ATTR_TRANSP_CMD] + transp_arg = call.data[ATTR_TRANSP_ARG] + await gw_dev.gateway.send_transparent_command(transp_cmd, transp_arg) + + hass.services.async_register( + DOMAIN, + SERVICE_SEND_TRANSP_CMD, + send_transparent_cmd, + service_send_transp_cmd_schema, + ) + async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Cleanup and disconnect from gateway.""" diff --git a/homeassistant/components/opentherm_gw/const.py b/homeassistant/components/opentherm_gw/const.py index 74b856b4eaf..6b0a27aec92 100644 --- a/homeassistant/components/opentherm_gw/const.py +++ b/homeassistant/components/opentherm_gw/const.py @@ -19,6 +19,8 @@ ATTR_GW_ID = "gateway_id" ATTR_LEVEL = "level" ATTR_DHW_OVRD = "dhw_override" ATTR_CH_OVRD = "ch_override" +ATTR_TRANSP_CMD = "transp_cmd" +ATTR_TRANSP_ARG = "transp_arg" CONF_CLIMATE = "climate" CONF_FLOOR_TEMP = "floor_temperature" @@ -45,6 +47,7 @@ SERVICE_SET_LED_MODE = "set_led_mode" SERVICE_SET_MAX_MOD = "set_max_modulation" SERVICE_SET_OAT = "set_outside_temperature" SERVICE_SET_SB_TEMP = "set_setback_temperature" +SERVICE_SEND_TRANSP_CMD = "send_transparent_command" TRANSLATE_SOURCE = { gw_vars.BOILER: "Boiler", diff --git a/homeassistant/components/opentherm_gw/icons.json b/homeassistant/components/opentherm_gw/icons.json index 9d5d903aabc..13dbe0a70a1 100644 --- a/homeassistant/components/opentherm_gw/icons.json +++ b/homeassistant/components/opentherm_gw/icons.json @@ -10,6 +10,7 @@ "set_led_mode": "mdi:led-on", "set_max_modulation": "mdi:thermometer-lines", "set_outside_temperature": "mdi:thermometer-lines", - "set_setback_temperature": "mdi:thermometer-lines" + "set_setback_temperature": "mdi:thermometer-lines", + "send_transparent_command": "mdi:console" } } diff --git a/homeassistant/components/opentherm_gw/services.yaml b/homeassistant/components/opentherm_gw/services.yaml index d68624e0763..d521425d06b 100644 --- a/homeassistant/components/opentherm_gw/services.yaml +++ b/homeassistant/components/opentherm_gw/services.yaml @@ -181,3 +181,19 @@ set_setback_temperature: max: 30 step: 0.1 unit_of_measurement: "°" + +send_transparent_command: + fields: + gateway_id: + required: true + example: "opentherm_gateway" + selector: + text: + transp_cmd: + required: true + selector: + text: + transp_arg: + required: true + selector: + text: diff --git a/homeassistant/components/opentherm_gw/strings.json b/homeassistant/components/opentherm_gw/strings.json index a5b8395b56b..2ad34f8d659 100644 --- a/homeassistant/components/opentherm_gw/strings.json +++ b/homeassistant/components/opentherm_gw/strings.json @@ -190,6 +190,24 @@ "description": "The setback temperature to configure on the gateway." } } + }, + "send_transparent_command": { + "name": "Send transparent command", + "description": "Sends custom otgw commands (https://otgw.tclcode.com/firmware.html) through a transparent interface.", + "fields": { + "gateway_id": { + "name": "[%key:component::opentherm_gw::services::reset_gateway::fields::gateway_id::name%]", + "description": "[%key:component::opentherm_gw::services::reset_gateway::fields::gateway_id::description%]" + }, + "transp_cmd": { + "name": "Command", + "description": "The command to be sent to the OpenTherm Gateway." + }, + "transp_arg": { + "name": "Argument", + "description": "The argument of the command to be sent to the OpenTherm Gateway." + } + } } } }