From e1c3f16cd2ea64b08c193abccc8489e592bee980 Mon Sep 17 00:00:00 2001 From: Zach Auclair Date: Thu, 20 Dec 2018 22:49:58 -0500 Subject: [PATCH] feat(devices): more support, including vivosmart 3 Specifically, this trims some memory, adds better touch-screen support, and updates the manifest. --- manifest.xml | 17 ++++++++++++----- source/CameraListView.mc | 9 +++++++-- source/NestApi.mc | 5 ++++- source/Properties.mc | 8 ++++++++ source/SummaryView.mc | 29 +++++++++++++++++++---------- 5 files changed, 50 insertions(+), 18 deletions(-) diff --git a/manifest.xml b/manifest.xml index 73156ec..37aa8f7 100644 --- a/manifest.xml +++ b/manifest.xml @@ -1,18 +1,25 @@ - - - + + + + + + - + + + - + + + diff --git a/source/CameraListView.mc b/source/CameraListView.mc index 82d6885..b250b3c 100644 --- a/source/CameraListView.mc +++ b/source/CameraListView.mc @@ -14,12 +14,17 @@ class CameraListDelegate extends Ui.BehaviorDelegate { BehaviorDelegate.initialize(); } + function onSelect() { + var camera = NestApi.getInstance().getCameraList()[self.page]; + NestApi.getInstance().requestToggleStreaming(camera); + return true; + } + function onKey(ev) { var key = ev.getKey(); Logger.getInstance().infoF("ref=camera-list-delegate at=on-key key=$1$", [key]); if (key == Ui.KEY_START || key == Ui.KEY_ENTER) { - var camera = NestApi.getInstance().getCameraList()[self.page]; - NestApi.getInstance().requestToggleStreaming(camera); + return onSelect(); } else if (key == Ui.KEY_DOWN) { return onNextPage(); } else if (key == Ui.KEY_UP) { diff --git a/source/NestApi.mc b/source/NestApi.mc index 5b5e298..2bc2ee0 100644 --- a/source/NestApi.mc +++ b/source/NestApi.mc @@ -13,7 +13,8 @@ var _api; // TODO: buffer, splay and retry request to handle BLE QUEUE FULL error (code -101) // TODO also a way of queueing or handlying multiple request/response pairs static class NestApi { - static const unusedCameraFields = ["app_url", "web_url", "last_event", "where_id", "where_name", "structure_id", "software_version", "name_long", "last_is_online_change", "is_video_history_enabled", "is_audio_input_enabled"]; + // static const unusedCameraFields = ["app_url", "web_url", "last_event", "where_id", "where_name", "structure_id", "software_version", "name_long", "last_is_online_change", "is_video_history_enabled", "is_audio_input_enabled"]; + static const unusedCameraFields = ["fwId", "hwId", "appServerUrl", "deviceHwVer", "deviceMac", "oemId", "isSameRegion", "role", "fwVer", "deviceName", "deviceType"]; enum { StateRequestError = 0, @@ -194,6 +195,8 @@ static class NestApi { self.setPollerStateRequestError(Lang.format("Error $1$", [responseCode])); } } else if (self.setPollerStateRequestSuccess()) { + Properties.clearCameraList(); + var cameraList = data; // clean out some of the data we don't use since the memory usage may be too beefy for (var i = 0; i < cameraList.size(); i++) { diff --git a/source/Properties.mc b/source/Properties.mc index 3821f2d..85b4d8c 100644 --- a/source/Properties.mc +++ b/source/Properties.mc @@ -32,6 +32,14 @@ static class Properties { Logger.getInstance().info("ref=properties at=get-camera-list"); return cameraList; } + static function clearCameraList() { + if (getApp().getProperty("camera_list") == null) { + return; + } + + Logger.getInstance().info("ref=properties at=clear-camera-list"); + getApp().setProperty("camera_list", null); + } static function setCameraList(cameraList) { if (!(cameraList instanceof Lang.Array)) { throw new InvalidArgumentError("expected camera_list to be Toybox.Lang.Array"); diff --git a/source/SummaryView.mc b/source/SummaryView.mc index 638c392..c4b137d 100644 --- a/source/SummaryView.mc +++ b/source/SummaryView.mc @@ -14,25 +14,34 @@ class SummaryDelegate extends Ui.BehaviorDelegate { self.summaryUi = summaryUi; BehaviorDelegate.initialize(); } + + function onBack() { + Ui.popView(Ui.SLIDE_IMMEDIATE); + return true; + } - function onKey(ev) { - var key = ev.getKey(); - if (Ui.KEY_START != key && Ui.KEY_ENTER != key) { - return false; - } - - Logger.getInstance().info("ref=summary-delegate at=on-ok"); + function onSelect() { if (!NestApi.getInstance().isConnected()) { NestApi.getInstance().requestOauthConnect(); - return true; } else if (NestApi.getInstance().hasCameras()) { var view = new CameraListView(); Ui.pushView(view, new CameraListDelegate(view), Ui.SLIDE_LEFT); - return true; } else { NestApi.getInstance().requestCameraStatus(); } - return false; + return true; + } + + function onKey(ev) { + var key = ev.getKey(); + Logger.getInstance().infoF("ref=summary-delegate at=on-key key=$1$", [key]); + + if (Ui.KEY_START == key || Ui.KEY_ENTER == key) { + return onSelect(); + } else if (key == Ui.KEY_ESC || key == Ui.KEY_LAP) { + return onBack(); + } + return false; } }