Skip to content

Commit

Permalink
Additional IO improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
msp1974 committed Apr 30, 2020
1 parent 8ae2f92 commit 38f69bc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
24 changes: 16 additions & 8 deletions custom_components/wiser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,22 +304,26 @@ async def async_update_device_registry(self):
async def set_away_mode(self, away, away_temperature):
mode = "AWAY" if away else "HOME"
if self.wiserhub is None:
self.wiserhub = wiserHub(self.ip, self.secret)
self.wiserhub = await self.async_connect()
_LOGGER.debug(
"Setting away mode to {} with temp {}.".format(mode, away_temperature)
)
try:
self.wiserhub.setHomeAwayMode(mode, away_temperature)
await self._hass.async_add_executor_job(
partial(self.wiserhub.setHomeAwayMode, mode, away_temperature)
)
await self.async_update(no_throttle=True)
except BaseException as e:
_LOGGER.debug("Error setting away mode! {}".format(str(e)))

async def set_system_switch(self, switch, mode):
if self.wiserhub is None:
self.wiserhub = wiserHub(self.ip, self.secret)
self.wiserhub = await self.async_connect()
_LOGGER.debug("Setting {} system switch to {}.".format(switch, mode))
try:
self.wiserhub.setSystemSwitch(switch, mode)
await self._hass.async_add_executor_job(
partial(self.wiserhub.setSystemSwitch, switch, mode)
)
await self.async_update(no_throttle=True)
except BaseException as e:
_LOGGER.debug("Error setting {} system switch! {}".format(switch, str(e)))
Expand All @@ -332,11 +336,13 @@ async def set_smart_plug_state(self, plug_id, state):
:return:
"""
if self.wiserhub is None:
self.wiserhub = wiserHub(self.ip, self.secret)
self.wiserhub = await self.async_connect()
_LOGGER.info("Setting SmartPlug {} to {} ".format(plug_id, state))

try:
self.wiserhub.setSmartPlugState(plug_id, state)
await self._hass.async_add_executor_job(
partial(self.wiserhub.setSmartPlugState, plug_id, state)
)
# Add small delay to allow hub to update status before refreshing
await asyncio.sleep(0.5)
await self.async_update(no_throttle=True)
Expand All @@ -353,14 +359,16 @@ async def set_hotwater_mode(self, hotwater_mode):
"""
if self.wiserhub is None:
self.wiserhub = wiserHub(self.ip, self.secret)
self.wiserhub = await self.async_connect()
_LOGGER.info("Setting Hotwater to {} ".format(hotwater_mode))
# Add small delay to allow hub to update status before refreshing
await asyncio.sleep(0.5)
await self.async_update(no_throttle=True)

try:
self.wiserhub.setHotwaterMode(hotwater_mode)
await self._hass.async_add_executor_job(
partial(self.wiserhub.setHotwaterMode, hotwater_mode)
)

except BaseException as e:
_LOGGER.debug(
Expand Down
21 changes: 17 additions & 4 deletions custom_components/wiser/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import voluptuous as vol

from functools import partial
from homeassistant.components.climate import ClimateDevice
from homeassistant.core import callback

Expand Down Expand Up @@ -477,7 +478,11 @@ async def async_set_temperature(self, **kwargs):
_LOGGER.debug(
"Setting temperature for {} to {}".format(self.name, target_temperature)
)
self.data.wiserhub.setRoomTemperature(self.room_id, target_temperature)
await self.hass.async_add_executor_job(
partial(
self.data.wiserhub.setRoomTemperature, self.room_id, target_temperature
)
)
self._force_update = True
await self.async_update_ha_state(True)

Expand All @@ -490,15 +495,21 @@ async def set_room_mode(self, room_id, mode, boost_temp=None, boost_time=None):
_LOGGER.debug(
"Setting Room Mode to {} for roomId {}".format(mode, self.room_id)
)
self.data.wiserhub.setRoomMode(room_id, mode, boost_temp, boost_time)
await self.hass.async_add_executor_job(
partial(
self.data.wiserhub.setRoomMode, room_id, mode, boost_temp, boost_time
)
)
self._force_update = True
await self.async_update_ha_state(True)
return True

async def set_room_schedule(self, room_id, scheduleData):
if scheduleData != None:
scheduleData = convert_to_wiser_schedule(scheduleData)
self.data.wiserhub.setRoomSchedule(room_id, scheduleData)
await self.hass.async_add_executor_job(
partial(self.data.wiserhub.setRoomSchedule, room_id, scheduleData)
)
_LOGGER.debug("Set room schedule for {}".format(self.name))
self._force_update = True
await self.async_update_ha_state(True)
Expand All @@ -507,7 +518,9 @@ async def set_room_schedule(self, room_id, scheduleData):
return False

async def copy_room_schedule(self, room_id, to_room_id):
self.data.wiserhub.copyRoomSchedule(room_id, to_room_id)
await self.hass.async_add_executor_job(
partial(self.data.wiserhub.copyRoomSchedule, room_id, to_room_id)
)
_LOGGER.debug(
"Copied room schedule from {} to {}".format(
self.name, self.data.wiserhub.getRoom(to_room_id).get("Name")
Expand Down

0 comments on commit 38f69bc

Please sign in to comment.