mirror of
https://github.com/no2chem/wideq.git
synced 2025-05-19 08:40:25 -07:00
Marginally more thread-safe monitoring
This way, calling `poll` before `monitor_start` finishes won't crash.
This commit is contained in:
parent
0b14dd5832
commit
8615be9722
9
wideq.py
9
wideq.py
@ -953,8 +953,9 @@ class ACDevice(Device):
|
|||||||
def monitor_start(self):
|
def monitor_start(self):
|
||||||
"""Start monitoring the device's status."""
|
"""Start monitoring the device's status."""
|
||||||
|
|
||||||
self.mon = Monitor(self.client.session, self.device.id)
|
mon = Monitor(self.client.session, self.device.id)
|
||||||
self.mon.start()
|
mon.start()
|
||||||
|
self.mon = mon
|
||||||
|
|
||||||
def monitor_stop(self):
|
def monitor_stop(self):
|
||||||
"""Stop monitoring the device's status."""
|
"""Stop monitoring the device's status."""
|
||||||
@ -969,6 +970,10 @@ class ACDevice(Device):
|
|||||||
available.
|
available.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Abort if monitoring has not started yet.
|
||||||
|
if not hasattr(self, 'mon'):
|
||||||
|
return None
|
||||||
|
|
||||||
res = self.mon.poll_json()
|
res = self.mon.poll_json()
|
||||||
if res:
|
if res:
|
||||||
return ACStatus(self, res)
|
return ACStatus(self, res)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user