From 4b3ed974d064b788f470c9439a719a3f3ed95cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Beye?= Date: Wed, 20 Jan 2021 20:02:31 +0100 Subject: [PATCH] feat(vendor.roborock): Do not disturb capability (#659) * Roborock/Capability Do Not Disturb Co-authored-by: bensweet86 --- client/services/api.service.js | 26 ++++----- client/settings-timers.html | 7 ++- client/settings-timers.js | 53 +++++++++++-------- client/settings.html | 4 +- .../capabilities/DoNotDisturbCapability.js | 30 +++++++++++ lib/core/capabilities/index.js | 1 + lib/entities/core/ValetudoDNDConfiguration.js | 31 +++++++++++ lib/robots/roborock/RoborockValetudoRobot.js | 3 ++ .../RoborockDoNotDisturbCapability.js | 45 ++++++++++++++++ lib/robots/roborock/capabilities/index.js | 3 +- lib/webserver/CapabilitiesRouter.js | 3 +- .../DoNotDisturbCapabilityRouter.js | 30 +++++++++++ lib/webserver/capabilityRouters/index.js | 3 +- 13 files changed, 197 insertions(+), 42 deletions(-) create mode 100644 lib/core/capabilities/DoNotDisturbCapability.js create mode 100644 lib/entities/core/ValetudoDNDConfiguration.js create mode 100644 lib/robots/roborock/capabilities/RoborockDoNotDisturbCapability.js create mode 100644 lib/webserver/capabilityRouters/DoNotDisturbCapabilityRouter.js diff --git a/client/services/api.service.js b/client/services/api.service.js index 668c261f3a1..6bbeaeb2ba6 100644 --- a/client/services/api.service.js +++ b/client/services/api.service.js @@ -226,16 +226,22 @@ export class ApiService { await this.fetch("DELETE", "api/timers/" + id); } - static async getDnd() { - return await this.fetch("GET", "api/get_dnd"); + static async getDndConfiguration() { + return await this.fetch("GET", "api/v2/robot/capabilities/DoNotDisturbCapability"); } - static async deleteDnd() { - await this.fetch("PUT", "api/delete_dnd"); - } - - static async setDnd(start_hour, start_minute, end_hour, end_minute) { - await this.fetch("POST", "api/set_dnd", {start_hour, start_minute, end_hour, end_minute}); + static async setDndConfiguration(enabled, start_hour, start_minute, end_hour, end_minute) { + await this.fetch("PUT", "api/v2/robot/capabilities/DoNotDisturbCapability", { + enabled: enabled, + start: { + hour: start_hour, + minute: start_minute + }, + end: { + hour: end_hour, + minute: end_minute + } + }); } static async getCarpetMode() { @@ -270,10 +276,6 @@ export class ApiService { } - static async setLabStatus(labStatus) { - await this.fetch("PUT", "api/set_lab_status", {lab_status: labStatus}); - } - static async resetConsumable(type, subType) { var url = "api/v2/robot/capabilities/ConsumableMonitoringCapability/" + type; diff --git a/client/settings-timers.html b/client/settings-timers.html index 064f4c4bb8e..882d2713d8d 100644 --- a/client/settings-timers.html +++ b/client/settings-timers.html @@ -124,18 +124,21 @@
Timers
+
+ "Do Not Disturb" - Timer @@ -148,7 +151,7 @@ ons.getScriptPage().appendChild(s); ons.getScriptPage().onShow = function() { - updateSettingsTimersPage(); + //updateSettingsTimersPage(); updateDndTimerPage(); }; } diff --git a/client/settings-timers.js b/client/settings-timers.js index a3b7eed5ce3..6db868d2595 100644 --- a/client/settings-timers.js +++ b/client/settings-timers.js @@ -95,9 +95,9 @@ async function updateDndTimerPage() { dndTimerList.removeChild(dndTimerList.lastChild); } try { - let res = await ApiService.getDnd(); + let res = await ApiService.getDndConfiguration(); // TODO: Check if multiple dnd timers can be created! - if (res.length === 0 || res[0].enabled === 0) { + if (res.length === 0 || !(res.enabled) ) { // no timer is enabled yet, show possibility to add dnd timer dndTimerList.appendChild(ons.createElement( "\n" + @@ -110,24 +110,23 @@ async function updateDndTimerPage() { "")); } else { // Show current active timer - res.forEach(function(dndTimer) { - dndTimerList.appendChild(ons.createElement( - "\n" + - "
DND will start at " + dndTimer.start_hour + ":" + - asTwoDigitNumber(dndTimer.start_minute) + " and end on " + - dndTimer.end_hour + ":" + asTwoDigitNumber(dndTimer.end_minute) + "
" + - "
" + - " " + - " " + - " " + - " " + - " " + - " " + - "
" + - "
")); - }); + dndTimerList.appendChild(ons.createElement( + "\n" + + "
DND will start at " + res.start.hour + ":" + + asTwoDigitNumber(res.start.minute) + " and end on " + + res.end.hour + ":" + asTwoDigitNumber(res.end.minute) + "
" + + "
" + + " " + + " " + + " " + + " " + + " " + + " " + + "
" + + "
" + )); } } catch (err) { ons.notification.toast(err.message, @@ -143,7 +142,7 @@ async function deleteDndTimer() { let answer = await ons.notification.confirm("Do you really want to disable DND?"); if (answer === 1) { loadingBarSettingsTimers.setAttribute("indeterminate", "indeterminate"); - await ApiService.deleteDnd(); + await ApiService.setDndConfiguration(false, 0, 0, 0, 0); updateDndTimerPage(); } } catch (err) { @@ -160,9 +159,17 @@ async function saveDndTimer() { var start_minute = document.getElementById("edit-dnd-form").start_minute.value; var end_hour = document.getElementById("edit-dnd-form").end_hour.value; var end_minute = document.getElementById("edit-dnd-form").end_minute.value; + if (start_hour && start_minute && end_hour && end_minute) { try { - await ApiService.setDnd(start_hour, start_minute, end_hour, end_minute); + await ApiService.setDndConfiguration( + true, + parseInt(start_hour), + parseInt(start_minute), + parseInt(end_hour), + parseInt(end_minute) + ); + hideDndTimerDialog(); updateDndTimerPage(); } catch (err) { @@ -413,4 +420,4 @@ window.deleteDndTimer = deleteDndTimer; window.saveDndTimer = saveDndTimer; window.addNewTimer = addNewTimer; window.showAddTimerDialog = showAddTimerDialog; -window.hideNewTimerDialog = hideNewTimerDialog; \ No newline at end of file +window.hideNewTimerDialog = hideNewTimerDialog; diff --git a/client/settings.html b/client/settings.html index 558c95276cb..a3a963e71da 100644 --- a/client/settings.html +++ b/client/settings.html @@ -3,12 +3,12 @@
Info
View device information
- +