From 69410576a7ded21b967048ac5112f1a9cb56bfa3 Mon Sep 17 00:00:00 2001 From: Chris Culhane Date: Fri, 19 Jun 2020 08:51:25 +1000 Subject: [PATCH] Adding get_lights() --- source/ConnectIQLIFXDelegate.mc | 3 ++- source/LIFX_API.mc | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/source/ConnectIQLIFXDelegate.mc b/source/ConnectIQLIFXDelegate.mc index 30d915f..422b350 100644 --- a/source/ConnectIQLIFXDelegate.mc +++ b/source/ConnectIQLIFXDelegate.mc @@ -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); } diff --git a/source/LIFX_API.mc b/source/LIFX_API.mc index e3fc815..84663f9 100644 --- a/source/LIFX_API.mc +++ b/source/LIFX_API.mc @@ -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]);