From 56c598e4d367c9ce75eb6a4425d6647eae58ad07 Mon Sep 17 00:00:00 2001 From: Paul Molensky Date: Tue, 16 Jul 2019 01:37:56 +0200 Subject: [PATCH] Provide feedback on missing sensor data Four types of sensor data are required. Added named feedback to app when one of these are missing. --- drivers/ipwebcam/device.js | 13 ++++++++++- lib/util.js | 46 +++++++++++++++++++++++++------------- locales/en.json | 4 ++++ locales/nl.json | 4 ++++ 4 files changed, 50 insertions(+), 17 deletions(-) diff --git a/drivers/ipwebcam/device.js b/drivers/ipwebcam/device.js index 05cde78c..e3ee397b 100644 --- a/drivers/ipwebcam/device.js +++ b/drivers/ipwebcam/device.js @@ -53,7 +53,18 @@ class IpwebcamDevice extends Homey.Device { } }) .catch(error => { - this.setUnavailable(Homey.__('Unreachable')); + switch (error) + { + case 'err_sensor_motion': + case 'err_sensor_sound': + case 'err_sensor_light': + case 'err_sensor_battery': + this.setUnavailable(Homey.__(error)); + break; + default: + this.setUnavailable(Homey.__('Unreachable')); + break; + } this.pingDevice(); }) }, 1000 * interval); diff --git a/lib/util.js b/lib/util.js index 7bfa5fd8..a3792035 100644 --- a/lib/util.js +++ b/lib/util.js @@ -61,28 +61,42 @@ exports.getIpwebcam = function (address, port, username, password) { .then(json => { var lux = 0; - if(json.hasOwnProperty("motion_active") && !isEmpty(json.motion_active.data) && json.motion_active.data[0][1][0] == 1) { - var motion = true; - } else { - var motion = false; - } - - if(json.hasOwnProperty("sound_event") && !isEmpty(json.sound_event.data) && json.sound_event.data[0][1][0] == 1) { - var sound = true; - } else { - var sound = false; - } - - if(json.hasOwnProperty("light") && !isEmpty(json.light.data)) { + if(json.hasOwnProperty("motion_active") && + !isEmpty(json.motion_active.data)) + { + if(json.motion_active.data[0][1][0] == 1) + { + var motion = true; + } else { + var motion = false; + } + } else { return reject('err_sensor_motion'); } + + if(json.hasOwnProperty("sound_event") && + !isEmpty(json.sound_event.data)) + { + if(json.sound_event.data[0][1][0] == 1) + { + var sound = true; + } else { + var sound = false; + } + } else { return reject('err_sensor_sound'); } + + if(json.hasOwnProperty("light") && + !isEmpty(json.light.data)) + { var lux = json.light.data[0][1][0]; } else { - var lux = 0; + return reject('err_sensor_light'); } - if(json.hasOwnProperty("battery_level") && !isEmpty(json.battery_level.data)) { + if(json.hasOwnProperty("battery_level") && + !isEmpty(json.battery_level.data)) + { var battery = json.battery_level.data[0][1][0]; } else { - var battery = 100; + return reject('err_sensor_battery'); } var result = { diff --git a/locales/en.json b/locales/en.json index 4e6a1483..433d0c81 100644 --- a/locales/en.json +++ b/locales/en.json @@ -33,6 +33,10 @@ "success": "Settings have been saved succesfully." }, "Unreachable": "Unreachable", + "err_sensor_motion": "Missing sensor data: motion", + "err_sensor_sound": "Missing sensor data: sound", + "err_sensor_light": "Missing sensor data: light", + "err_sensor_battery": "Missing sensor data: battery", "Live Snapshot": "Live Snapshot", "This is a test email which confirms your email settings in the Homey IP Webcam App are correct.": "This is a test email which confirms your email settings in the Homey IP Webcam App are correct.", "

Homey IP Webcam App

This is a test email which confirms your email settings in the Homey IP Webcam App are correct.

": "

Homey IP Webcam App

This is a test email which confirms your email settings in the Homey IP Webcam App are correct.

", diff --git a/locales/nl.json b/locales/nl.json index 0163d8bd..ebcc7f71 100644 --- a/locales/nl.json +++ b/locales/nl.json @@ -33,6 +33,10 @@ "success": "Instellingen zijn succesvol opgeslagen." }, "Unreachable": "Onbereikbaar", + "err_sensor_motion": "Sensor data ontbreekt: motion", + "err_sensor_sound": "Sensor data ontbreekt: sound", + "err_sensor_light": "Sensor data ontbreekt: light", + "err_sensor_battery": "Sensor data ontbreekt: battery", "Live Snapshot": "Live snapshot", "This is a test email which confirms your email settings in the Homey IP Webcam App are correct.": "Dit is een test email die bevestigd dat je instellingen voor email in de Homey IP Webcam App correct zijn.", "

Homey IP Webcam App

This is a test email which confirms your email settings in the Homey IP Webcam App are correct.

": "

Homey IP Webcam App

Dit is een test email die bevestigd dat je instellingen voor email in de Homey IP Webcam App correct zijn.

",