From 6d9b464e466cc91bafe7094a9829eba04b062594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=BCpper?= Date: Wed, 8 May 2019 15:15:28 +0200 Subject: [PATCH 1/4] implemented scan for lights and sensors --- phue.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/phue.py b/phue.py index a1a9f2e..2e4f291 100755 --- a/phue.py +++ b/phue.py @@ -890,7 +890,17 @@ def set_light(self, light_id, parameter, value=None, transitiontime=None): logger.debug(result) return result - + def scan_lights(): + if self.request('GET', '/api/' + self.username + '/lights/new')['lastscan'] != 'active': + logger.info("Scanning for new lights") + # empty POST request initialises scan + self.request('POST', '/api/' + self.username + 'lights', "") + else: + logger.info("Scan for new light requested, but there is an ongoing scan") + + def scan_lights_active(): + return self.request('GET', '/api/' + self.username + '/lights/new')['lastscan'] == 'active' + # Sensors ##### @property @@ -1028,6 +1038,17 @@ def delete_sensor(self, sensor_id): return self.request('DELETE', '/api/' + self.username + '/sensors/' + str(sensor_id)) except: logger.debug("Unable to delete nonexistent sensor with ID {0}".format(sensor_id)) + + def scan_sensors(): + if self.request('GET', '/api/' + self.username + '/sensors/new')['lastscan'] != 'active': + logger.info("Scanning for new sensors") + # empty POST request initialises scan + self.request('POST', '/api/' + self.username + 'sensors', "") + else: + logger.info("Scan for new sensor requested, but there is an ongoing scan") + + def scan_sensors_active(): + return self.request('GET', '/api/' + self.username + '/sensors/new')['lastscan'] == 'active' # Groups of lights ##### @property From d8449aa1df58baa906831636dae2aa443936d37f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=BCpper?= Date: Wed, 8 May 2019 15:19:47 +0200 Subject: [PATCH 2/4] fixed indentation error --- phue.py | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/phue.py b/phue.py index 2e4f291..00ac285 100755 --- a/phue.py +++ b/phue.py @@ -890,17 +890,18 @@ def set_light(self, light_id, parameter, value=None, transitiontime=None): logger.debug(result) return result - def scan_lights(): - if self.request('GET', '/api/' + self.username + '/lights/new')['lastscan'] != 'active': - logger.info("Scanning for new lights") - # empty POST request initialises scan - self.request('POST', '/api/' + self.username + 'lights', "") - else: - logger.info("Scan for new light requested, but there is an ongoing scan") - - def scan_lights_active(): - return self.request('GET', '/api/' + self.username + '/lights/new')['lastscan'] == 'active' - + + def scan_lights(): + if self.request('GET', '/api/' + self.username + '/lights/new')['lastscan'] != 'active': + logger.info("Scanning for new lights") + # empty POST request initialises scan + self.request('POST', '/api/' + self.username + 'lights', "") + else: + logger.info("Scan for new light requested, but there is an ongoing scan") + + def scan_lights_active(): + return self.request('GET', '/api/' + self.username + '/lights/new')['lastscan'] == 'active' + # Sensors ##### @property @@ -1039,16 +1040,16 @@ def delete_sensor(self, sensor_id): except: logger.debug("Unable to delete nonexistent sensor with ID {0}".format(sensor_id)) - def scan_sensors(): - if self.request('GET', '/api/' + self.username + '/sensors/new')['lastscan'] != 'active': - logger.info("Scanning for new sensors") - # empty POST request initialises scan - self.request('POST', '/api/' + self.username + 'sensors', "") - else: - logger.info("Scan for new sensor requested, but there is an ongoing scan") - - def scan_sensors_active(): - return self.request('GET', '/api/' + self.username + '/sensors/new')['lastscan'] == 'active' + def scan_sensors(): + if self.request('GET', '/api/' + self.username + '/sensors/new')['lastscan'] != 'active': + logger.info("Scanning for new sensors") + # empty POST request initialises scan + self.request('POST', '/api/' + self.username + 'sensors', "") + else: + logger.info("Scan for new sensor requested, but there is an ongoing scan") + + def scan_sensors_active(): + return self.request('GET', '/api/' + self.username + '/sensors/new')['lastscan'] == 'active' # Groups of lights ##### @property From 911dff20ec011349a1b12275bf8517803e7659dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=BCpper?= Date: Wed, 8 May 2019 15:23:46 +0200 Subject: [PATCH 3/4] forgot 'self' in method parameters --- phue.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phue.py b/phue.py index 00ac285..e995b2a 100755 --- a/phue.py +++ b/phue.py @@ -891,7 +891,7 @@ def set_light(self, light_id, parameter, value=None, transitiontime=None): logger.debug(result) return result - def scan_lights(): + def scan_lights(self): if self.request('GET', '/api/' + self.username + '/lights/new')['lastscan'] != 'active': logger.info("Scanning for new lights") # empty POST request initialises scan @@ -899,7 +899,7 @@ def scan_lights(): else: logger.info("Scan for new light requested, but there is an ongoing scan") - def scan_lights_active(): + def scan_lights_active(self): return self.request('GET', '/api/' + self.username + '/lights/new')['lastscan'] == 'active' # Sensors ##### @@ -1040,7 +1040,7 @@ def delete_sensor(self, sensor_id): except: logger.debug("Unable to delete nonexistent sensor with ID {0}".format(sensor_id)) - def scan_sensors(): + def scan_sensors(self): if self.request('GET', '/api/' + self.username + '/sensors/new')['lastscan'] != 'active': logger.info("Scanning for new sensors") # empty POST request initialises scan @@ -1048,7 +1048,7 @@ def scan_sensors(): else: logger.info("Scan for new sensor requested, but there is an ongoing scan") - def scan_sensors_active(): + def scan_sensors_active(self): return self.request('GET', '/api/' + self.username + '/sensors/new')['lastscan'] == 'active' # Groups of lights ##### From 920d0df118976ceffcc7dc5b3fad8c0791c23280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=BCpper?= Date: Wed, 8 May 2019 15:34:39 +0200 Subject: [PATCH 4/4] fixed request path --- phue.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phue.py b/phue.py index e995b2a..27cc35a 100755 --- a/phue.py +++ b/phue.py @@ -895,7 +895,7 @@ def scan_lights(self): if self.request('GET', '/api/' + self.username + '/lights/new')['lastscan'] != 'active': logger.info("Scanning for new lights") # empty POST request initialises scan - self.request('POST', '/api/' + self.username + 'lights', "") + self.request('POST', '/api/' + self.username + '/lights', "") else: logger.info("Scan for new light requested, but there is an ongoing scan") @@ -1044,7 +1044,7 @@ def scan_sensors(self): if self.request('GET', '/api/' + self.username + '/sensors/new')['lastscan'] != 'active': logger.info("Scanning for new sensors") # empty POST request initialises scan - self.request('POST', '/api/' + self.username + 'sensors', "") + self.request('POST', '/api/' + self.username + '/sensors', "") else: logger.info("Scan for new sensor requested, but there is an ongoing scan")