Skip to content

Commit

Permalink
Added set_variable service
Browse files Browse the repository at this point in the history
  • Loading branch information
asev committed Feb 12, 2021
1 parent c78a54a commit c622e45
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Each thermostat will be registered as a separate device. Also one device will be
`switch.uponor_cooling_mode` activates cooling mode when switched on and heating mode when it's switched off.
This switch will be added only if cooling is available in your system.

`uponor.set_variable` service allows to send POST requests to Uponor API. Use it with caution!

### Climate entity

Expand Down
12 changes: 12 additions & 0 deletions custom_components/uponor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
"thermostats": thermostats
}

def handle_set_variable(call):
var_name = call.data.get('var_name')
var_value = call.data.get('var_value')
hass.data[DOMAIN]['state_proxy'].set_variable(var_name, var_value)

hass.services.async_register(DOMAIN, "set_variable", handle_set_variable)

hass.async_create_task(hass.config_entries.async_forward_entry_setup(config_entry, "climate"))
hass.async_create_task(hass.config_entries.async_forward_entry_setup(config_entry, "switch"))

Expand Down Expand Up @@ -279,3 +286,8 @@ def is_eco(self, thermostat):
async def async_update(self, event_time):
self._data = await self._hass.async_add_executor_job(lambda: self._client.get_data())
async_dispatcher_send(self._hass, SIGNAL_UPONOR_STATE_UPDATE)

def set_variable(self, var_name, var_value):
self._client.send_data({var_name: var_value})
self._data[var_name] = var_value
async_dispatcher_send(self._hass, SIGNAL_UPONOR_STATE_UPDATE)
9 changes: 9 additions & 0 deletions custom_components/uponor/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set_variable:
description: Send variable update to Uponor API
fields:
var_name:
description: Name of the variable
example: "sys_heat_cool_mode"
var_value:
description: Value of the variable
example: 0

0 comments on commit c622e45

Please sign in to comment.