1
0
mirror of https://github.com/no2chem/wideq.git synced 2025-05-19 00:30:10 -07:00

Marginally more thread-safe monitoring

This way, calling `poll` before `monitor_start` finishes won't crash.
This commit is contained in:
Adrian Sampson 2019-02-24 16:39:09 -05:00
parent 0b14dd5832
commit 8615be9722

View File

@ -953,8 +953,9 @@ class ACDevice(Device):
def monitor_start(self):
"""Start monitoring the device's status."""
self.mon = Monitor(self.client.session, self.device.id)
self.mon.start()
mon = Monitor(self.client.session, self.device.id)
mon.start()
self.mon = mon
def monitor_stop(self):
"""Stop monitoring the device's status."""
@ -969,6 +970,10 @@ class ACDevice(Device):
available.
"""
# Abort if monitoring has not started yet.
if not hasattr(self, 'mon'):
return None
res = self.mon.poll_json()
if res:
return ACStatus(self, res)