Skip to content

Commit

Permalink
Adding get_lights()
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Culhane committed Jun 18, 2020
1 parent 85cd7be commit 6941057
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion source/ConnectIQLIFXDelegate.mc
Expand Up @@ -25,7 +25,8 @@ class ConnectIQLIFXDelegate extends WatchUi.BehaviorDelegate {
notify.invoke("Executing\nRequest");
var lifx_api;
lifx_api = new LIFX_API(self.notify);
lifx_api.power_toggle();
// lifx_api.power_toggle();
lifx_api.get_lights(null);
}


Expand Down
24 changes: 24 additions & 0 deletions source/LIFX_API.mc
Expand Up @@ -67,6 +67,30 @@ class LIFX_API extends WatchUi.BehaviorDelegate {
return responseCallback;
}

function get_lights(selector){
// Gets all lights on network, returns dict
// Selector is defined as per https://api.developer.lifx.com/v1/docs/selectors
// e.g. 'all' for all lights, 'id:afs097fds87a4f' for a specific light ID

if (selector == null) {
selector = "all";
}

System.println("Using selector: " + selector);
var url = "https://api.lifx.com/v1/lights/all";
var params = null;
var options = {
:method => comms.HTTP_REQUEST_METHOD_GET,
:headers => HEADERS,
:responseType => comms.HTTP_RESPONSE_CONTENT_TYPE_JSON
};
var responseCallback = method(:onReceive);

// Make the Communications.makeWebRequest() call
comms.makeWebRequest(url, params, options, method(:onReceive));
return responseCallback;
}

function set_scene(scene_uuid) {
var url_format = "https://api.lifx.com/v1/scenes/scene_id:$1$/activate"; // set the url
var url = Lang.format(url_format, [scene_uuid]);
Expand Down

0 comments on commit 6941057

Please sign in to comment.