From 8615be9722595e07a90197010a557bf1b13f7429 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sun, 24 Feb 2019 16:39:09 -0500 Subject: [PATCH] Marginally more thread-safe monitoring This way, calling `poll` before `monitor_start` finishes won't crash. --- wideq.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/wideq.py b/wideq.py index c49a8af..6be5c20 100644 --- a/wideq.py +++ b/wideq.py @@ -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)