Skip to content

Commit

Permalink
Fix kasa relay caching #898
Browse files Browse the repository at this point in the history
  • Loading branch information
theyosh committed Apr 10, 2024
1 parent 43da9a3 commit 1dc488d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions hardware/relay/kasa_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ async def __set_hardware_state(state):

return state

data = self.__state_cache.get_data(self._address[0])
if data is not None and terrariumUtils.is_true(data[self._device["switch"]]) == (state != 0.0):
return True

data = self.__asyncio.run(__set_hardware_state(state))

# Update the cache after relay change
self._get_hardware_value(True)

return data == state

def _get_hardware_value(self):
def _get_hardware_value(self, force = False):
async def __get_hardware_state():
data = []
await self.device.update()
Expand All @@ -66,7 +66,7 @@ async def __get_hardware_state():
try:
data = self.__state_cache.get_data(self._address[0])

if data is None:
if data is None or force:
data = self.__asyncio.run(__get_hardware_state())
self.__state_cache.set_data(self._address[0], data, cache_timeout=20)

Expand Down

0 comments on commit 1dc488d

Please sign in to comment.