Skip to content

Commit

Permalink
use sync methods , solves issue #34
Browse files Browse the repository at this point in the history
use sync methods to set values and solves issue #34
  • Loading branch information
dave-code-ruiz committed May 15, 2024
1 parent 73e8fdc commit f626ed7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
15 changes: 8 additions & 7 deletions custom_components/uhomeuponor/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,24 @@ async def async_update(self):
self._available = False
_LOGGER.error("Uponor thermostat was unable to update: %s", ex)

def set_hvac_mode(self, hvac_mode):
async def async_set_hvac_mode(self, hvac_mode):
if hvac_mode == HVACMode.HEAT:
value = UHOME_MODE_HEAT
else:
value = UHOME_MODE_COOL
self.thermostat.set_hvac_mode(value)
await self.thermostat.set_hvac_mode(value)

# Support setting preset_mode
def set_preset_mode(self, preset_mode):
async def async_set_preset_mode(self, preset_mode):
if preset_mode == PRESET_ECO:
value = UHOME_MODE_ECO
else:
value = UHOME_MODE_COMFORT
self.thermostat.set_preset_mode(value)
self.thermostat.set_auto_mode()
await self.thermostat.set_preset_mode(value)
await self.thermostat.set_auto_mode()

def set_temperature(self, **kwargs):
async def async_set_temperature(self, **kwargs):
if kwargs.get(ATTR_TEMPERATURE) is None:
return
self.thermostat.set_setpoint(kwargs.get(ATTR_TEMPERATURE))
await self.thermostat.set_setpoint(kwargs.get(ATTR_TEMPERATURE))

28 changes: 14 additions & 14 deletions custom_components/uhomeuponor/uponor_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def validate_values(self,response_data,allvalue_dict):
else:
return True

def set_values(self, *value_tuples):
async def set_values(self, *value_tuples):
"""Writes values to UHome, accepts tuples of (UponorValue, New Value)"""

#_LOGGER.debug("Requested write to %d values", len(value_tuples))
Expand All @@ -268,7 +268,7 @@ def set_values(self, *value_tuples):
obj = {'id': str(tpl[0].id), 'properties': {'85': {'value': str(tpl[1])}}}
self.add_request_object(req, obj)

self.hass.async_create_task(self.do_rest_call(req))
await self.do_rest_call(req)

# Apply new values, after the API call succeeds
for tpl in value_tuples:
Expand Down Expand Up @@ -355,38 +355,38 @@ def is_valid(self):
return -40 <= self.by_name('room_temperature').value and self.by_name('room_temperature').value <= 100 and \
1 <= self.by_name('room_setpoint').value and self.by_name('room_setpoint').value <= 40

def set_name(self, name):
async def set_name(self, name):
"""Updates the thermostats room name to a new value"""
self.uponor_client.set_values((self.by_name('room_name'), name))
await self.uponor_client.set_values((self.by_name('room_name'), name))

def set_setpoint(self, temperature):
async def set_setpoint(self, temperature):
"""Updates the thermostats setpoint to a new value"""
self.uponor_client.set_values(
await self.uponor_client.set_values(
(self.by_name('setpoint_write_enable'), 0),
(self.by_name('room_setpoint'), temperature)
)

def set_hvac_mode(self, value):
async def set_hvac_mode(self, value):
"""Updates the thermostats mode to a new value"""
self.uponor_client.set_values(
await self.uponor_client.set_values(
(self.uponor_client.uhome.by_name('allow_hc_mode_change'), 0),
(self.uponor_client.uhome.by_name('hc_mode'), value),
)

def set_preset_mode(self, value):
async def set_preset_mode(self, value):
"""Updates the thermostats mode to a new value"""
self.uponor_client.set_values((self.uponor_client.uhome.by_name('forced_eco_mode'), value))
await self.uponor_client.set_values((self.uponor_client.uhome.by_name('forced_eco_mode'), value))

def set_manual_mode(self):
self.uponor_client.set_values(
async def set_manual_mode(self):
await self.uponor_client.set_values(
(self.uponor_client.uhome.by_name('setpoint_write_enable'), 1),
(self.uponor_client.uhome.by_name('rh_control_activation'), 1),
(self.uponor_client.uhome.by_name('dehumidifier_control_activation'), 0),
(self.uponor_client.uhome.by_name('setpoint_write_enable'), 0),
)

def set_auto_mode(self):
self.uponor_client.set_values(
async def set_auto_mode(self):
await self.uponor_client.set_values(
(self.uponor_client.uhome.by_name('setpoint_write_enable'), 1),
(self.uponor_client.uhome.by_name('rh_control_activation'), 0),
(self.uponor_client.uhome.by_name('dehumidifier_control_activation'), 0),
Expand Down

0 comments on commit f626ed7

Please sign in to comment.