Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow scanning for new lights and sensors #154

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion phue.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,18 @@ def set_light(self, light_id, parameter, value=None, transitiontime=None):

logger.debug(result)
return result


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', "")
else:
logger.info("Scan for new light requested, but there is an ongoing scan")

def scan_lights_active(self):
return self.request('GET', '/api/' + self.username + '/lights/new')['lastscan'] == 'active'

# Sensors #####

@property
Expand Down Expand Up @@ -1028,6 +1039,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(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', "")
else:
logger.info("Scan for new sensor requested, but there is an ongoing scan")

def scan_sensors_active(self):
return self.request('GET', '/api/' + self.username + '/sensors/new')['lastscan'] == 'active'

# Groups of lights #####
@property
Expand Down