From 6da86560ee6c26aede7d9e7d5bd87bde7001cff7 Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Mon, 24 Jun 2024 09:28:47 +0200 Subject: [PATCH 1/6] adjust sample data --- sample/sample.json | 314 +++++++++++++++++++++++---------------------- 1 file changed, 162 insertions(+), 152 deletions(-) diff --git a/sample/sample.json b/sample/sample.json index 4fbec021..8ea1155b 100644 --- a/sample/sample.json +++ b/sample/sample.json @@ -1,158 +1,168 @@ -[ - { - "station_name": "Hamburg (Wohnzimmer)", - "type": "NAMain", - "module_name": "Main", - "wifi_status": 50, - "reachable": true, - "co2_calibrating": false, - "data_type": [ - "Temperature", - "CO2", - "Humidity", - "Noise", - "Pressure" - ], - "place": { - "altitude": 0, - "city": "Hamburg", - "country": "DE", - "timezone": "Europe/Berlin", - "location": [ - 10, - 10 - ] - }, - "home_name": "Hamburg", - "dashboard_data": { - "Temperature": 12.2, - "CO2": 1114, - "Humidity": 84, - "Noise": 39, - "Pressure": 1014.2, - "AbsolutePressure": 1011.2, - "min_temp": 9.3, - "max_temp": 13.3, - "pressure_trend": "stable" - }, - "modules": [ - { - "type": "NAModule4", - "module_name": "Indoor", - "data_type": [ - "Temperature", - "CO2", - "Humidity" - ], - "battery_percent": 50, - "reachable": true, - "rf_status": 50, - "battery_vp": 5040, - "dashboard_data": { - "Temperature": 12.7, - "CO2": 995, - "Humidity": 72, - "min_temp": 12.2, - "max_temp": 12.8 - } +{ + "user": { + "administrative": { + "feel_like_algo": 0, + "pressureunit": 0, + "unit": 0, + "windunit": 4 + } + }, + "devices": [ + { + "station_name": "Hamburg (Wohnzimmer)", + "type": "NAMain", + "module_name": "Main", + "wifi_status": 50, + "reachable": true, + "co2_calibrating": false, + "data_type": [ + "Temperature", + "CO2", + "Humidity", + "Noise", + "Pressure" + ], + "place": { + "altitude": 0, + "city": "Hamburg", + "country": "DE", + "timezone": "Europe/Berlin", + "location": [ + 10, + 10 + ] }, - { - "type": "NAModule1", - "module_name": "Outdoor", - "data_type": [ - "Temperature", - "Humidity" - ], - "battery_percent": 90, - "reachable": true, - "rf_status": 50, - "battery_vp": 5040, - "dashboard_data": { - "Temperature": 15.4, - "temp_trend": "down", - "Humidity": 36, - "min_temp": 2.2, - "max_temp": 19.7 - } + "home_name": "Hamburg", + "dashboard_data": { + "Temperature": 12.2, + "CO2": 1114, + "Humidity": 84, + "Noise": 39, + "Pressure": 1014.2, + "AbsolutePressure": 1011.2, + "min_temp": 9.3, + "max_temp": 13.3, + "pressure_trend": "stable" }, - { - "type": "NAModule2", - "module_name": "Wind", - "data_type": [ - "Wind" - ], - "battery_percent": 10, - "reachable": true, - "rf_status": 50, - "battery_vp": 5040, - "dashboard_data": { - "WindAngle": 221, - "WindStrength": 2, - "GustAngle": 208, - "GustStrength": 4, - "WindHistoric": [], - "min_temp": 0, - "max_temp": 0, - "max_wind_angle": 44, - "max_wind_str": 20 + "modules": [ + { + "type": "NAModule4", + "module_name": "Indoor", + "data_type": [ + "Temperature", + "CO2", + "Humidity" + ], + "battery_percent": 50, + "reachable": true, + "rf_status": 50, + "battery_vp": 5040, + "dashboard_data": { + "Temperature": 12.7, + "CO2": 995, + "Humidity": 72, + "min_temp": 12.2, + "max_temp": 12.8 + } + }, + { + "type": "NAModule1", + "module_name": "Outdoor", + "data_type": [ + "Temperature", + "Humidity" + ], + "battery_percent": 90, + "reachable": true, + "rf_status": 50, + "battery_vp": 5040, + "dashboard_data": { + "Temperature": 15.4, + "temp_trend": "down", + "Humidity": 36, + "min_temp": 2.2, + "max_temp": 19.7 + } + }, + { + "type": "NAModule2", + "module_name": "Wind", + "data_type": [ + "Wind" + ], + "battery_percent": 10, + "reachable": true, + "rf_status": 50, + "battery_vp": 5040, + "dashboard_data": { + "WindAngle": 221, + "WindStrength": 2, + "GustAngle": 208, + "GustStrength": 4, + "WindHistoric": [], + "min_temp": 0, + "max_temp": 0, + "max_wind_angle": 44, + "max_wind_str": 20 + } + }, + { + "type": "NAModule3", + "module_name": "Rain", + "data_type": [ + "Rain" + ], + "battery_percent": 30, + "reachable": true, + "rf_status": 50, + "battery_vp": 5040, + "dashboard_data": { + "Rain": 0, + "sum_rain_24": 0, + "sum_rain_1": 0 + } } + ] + }, + { + "station_name": "Altona (Wohnzimmer)", + "type": "NAMain", + "module_name": "Main", + "wifi_status": 50, + "reachable": false, + "co2_calibrating": false, + "data_type": [ + "Temperature", + "CO2", + "Humidity", + "Noise", + "Pressure" + ], + "place": { + "altitude": 0, + "city": "Altona", + "country": "DE", + "timezone": "Europe/Berlin", + "location": [ + 10, + 10 + ] }, - { - "type": "NAModule3", - "module_name": "Rain", - "data_type": [ - "Rain" - ], - "battery_percent": 30, - "reachable": true, - "rf_status": 50, - "battery_vp": 5040, - "dashboard_data": { - "Rain": 0, - "sum_rain_24": 0, - "sum_rain_1": 0 + "home_name": "Altona", + "modules": [ + { + "type": "NAModule1", + "module_name": "Outdoor", + "data_type": [ + "Temperature", + "Humidity" + ], + "battery_percent": 50, + "reachable": false, + "rf_status": 50, + "battery_vp": 5040 } - } - ] - }, - { - "station_name": "Altona (Wohnzimmer)", - "type": "NAMain", - "module_name": "Main", - "wifi_status": 50, - "reachable": false, - "co2_calibrating": false, - "data_type": [ - "Temperature", - "CO2", - "Humidity", - "Noise", - "Pressure" - ], - "place": { - "altitude": 0, - "city": "Altona", - "country": "DE", - "timezone": "Europe/Berlin", - "location": [ - 10, - 10 ] - }, - "home_name": "Altona", - "modules": [ - { - "type": "NAModule1", - "module_name": "Outdoor", - "data_type": [ - "Temperature", - "Humidity" - ], - "battery_percent": 50, - "reachable": false, - "rf_status": 50, - "battery_vp": 5040 - } - ] - } -] + } + ] +} From 4c0b5c3df22b0e0a0c33a0bbdcd3e3d260aee8f7 Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Mon, 24 Jun 2024 09:29:00 +0200 Subject: [PATCH 2/6] hand down user prefs --- helper.js | 2 +- netatmo.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/helper.js b/helper.js index b5dd4722..b30a2cee 100644 --- a/helper.js +++ b/helper.js @@ -110,7 +110,7 @@ module.exports = { }; this.sendSocketNotification(this.notifications.DATA_RESPONSE, { - payloadReturn: result.body.devices, + payloadReturn: result.body, status: 'OK', }) } catch (error) { diff --git a/netatmo.js b/netatmo.js index 4e942af5..f63bf94e 100755 --- a/netatmo.js +++ b/netatmo.js @@ -443,8 +443,9 @@ Module.register('netatmo', { break case this.notifications.DATA_RESPONSE: if (payload.status === 'OK') { - console.log('Devices %o', payload.payloadReturn) - const stationList = payload.payloadReturn + console.log('Devices %o', payload.payloadReturn.devices) + const stationList = payload.payloadReturn.devices + const userPreferences = payload.payloadReturn.user.administrative this.updateModuleList(stationList) this.updateDom(this.config.animationSpeed) } else if (payload.status === 'INVALID_TOKEN') { From b2b86f999307a351bf1473a9d8d6a470753da5f4 Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Mon, 24 Jun 2024 11:38:45 +0200 Subject: [PATCH 3/6] add uom conversion, thanks to @Duhlin12 --- netatmo.js | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/netatmo.js b/netatmo.js index f63bf94e..9cd87f9e 100755 --- a/netatmo.js +++ b/netatmo.js @@ -32,6 +32,7 @@ Module.register('netatmo', { fontClassMeasurement: 'xsmall', thresholdCO2Average: 800, thresholdCO2Bad: 1800, + unitOfMeasurementWind: '', mockData: false, }, notifications: { @@ -80,6 +81,12 @@ Module.register('netatmo', { this.sendSocketNotification(this.notifications.DATA) }, this.config.updateInterval * 60 * 1000 + this.config.initialDelay * 1000) }, + updateUnitOfMeasurements (userPreferences) { + if (this.config.unitOfMeasurementWind === ''){ + this.config.unitOfMeasurementWind = this.convertNetatmoWindUOM(userPreferences.windunit) + console.log('Using user preferred unit of measurement for wind values %o', this.config.unitOfMeasurementWind) + } + }, updateModuleList (stationList) { let moduleList = [] @@ -285,7 +292,7 @@ Module.register('netatmo', { return value.toFixed(1)// + ' mm/h' case this.measurement.WIND_STRENGTH: case this.measurement.GUST_STRENGTH: - return value.toFixed(0)// + ' km/h' + return this.convertWindUnit(value, this.config.unitOfMeasurementWind) case this.measurement.WIND_ANGLE: case this.measurement.GUST_ANGLE: return `${this.getDirection(value)} | ${value}`// + '°' @@ -296,6 +303,51 @@ Module.register('netatmo', { return value } }, + convertNetatmoWindUOM (unit) { + switch (unit) { + case 4: + return 'KT' + case 3: + return 'BFT' + case 2: + return 'MS' + case 1: + return 'MPH' + case 0: + default: + return 'KPH' + } + }, + convertWindUnit (value, unit) { + switch (unit) { + case 'MPH': + return (value / 1.609).toFixed(1) + case 'MS': + return (value / 3.6).toFixed(1) + case 'BFT': + return this.convertToBeaufort(value) + case 'KT': + return (value / 1.852).toFixed(1) + case 'KPH': + default: + return value.toFixed(1) + } + }, + convertToBeaufort (value) { + if (value < 1) return 0 + if (value <= 5) return 1 + if (value <= 11) return 2 + if (value <= 19) return 3 + if (value <= 28) return 4 + if (value <= 38) return 5 + if (value <= 49) return 6 + if (value <= 61) return 7 + if (value <= 74) return 8 + if (value <= 88) return 9 + if (value <= 102) return 10 + if (value <= 117) return 11 + return 12 + }, getUnit (measurement) { switch (measurement) { case this.measurement.CO2: @@ -317,7 +369,7 @@ Module.register('netatmo', { return 'mm/h' case this.measurement.WIND_STRENGTH: case this.measurement.GUST_STRENGTH: - return 'km/h' + return this.getWindUnitLabel(this.config.unitOfMeasurementWind) case this.measurement.WIND_ANGLE: case this.measurement.GUST_ANGLE: return '°' @@ -325,6 +377,21 @@ Module.register('netatmo', { return '' } }, + getWindUnitLabel (unit) { + switch (unit) { + case 'MPH': + return 'mph' + case 'MS': + return 'm/s' + case 'BFT': + return 'Bft' + case 'KT': + return 'kt' + case 'KMH': + default: + return 'km/h' + } + }, getDirection (value) { if (value < 11.25) return 'N' if (value < 33.75) return 'NNE' @@ -446,6 +513,7 @@ Module.register('netatmo', { console.log('Devices %o', payload.payloadReturn.devices) const stationList = payload.payloadReturn.devices const userPreferences = payload.payloadReturn.user.administrative + this.updateUnitOfMeasurements(userPreferences) this.updateModuleList(stationList) this.updateDom(this.config.animationSpeed) } else if (payload.status === 'INVALID_TOKEN') { From a4418eb1f81a05e7fe71e5beacfc01639f137af3 Mon Sep 17 00:00:00 2001 From: Christopher Fenner <9592452+CFenner@users.noreply.github.com> Date: Mon, 24 Jun 2024 11:40:43 +0200 Subject: [PATCH 4/6] Update netatmo.js --- netatmo.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netatmo.js b/netatmo.js index 9cd87f9e..ee320b62 100755 --- a/netatmo.js +++ b/netatmo.js @@ -83,7 +83,7 @@ Module.register('netatmo', { }, updateUnitOfMeasurements (userPreferences) { if (this.config.unitOfMeasurementWind === ''){ - this.config.unitOfMeasurementWind = this.convertNetatmoWindUOM(userPreferences.windunit) + this.config.unitOfMeasurementWind = this.convertNetatmoWindUnit(userPreferences.windunit) console.log('Using user preferred unit of measurement for wind values %o', this.config.unitOfMeasurementWind) } }, @@ -303,7 +303,7 @@ Module.register('netatmo', { return value } }, - convertNetatmoWindUOM (unit) { + convertNetatmoWindUnit (unit) { switch (unit) { case 4: return 'KT' From 2d7b506171bf8a2db97a868337c5c9911dc246ff Mon Sep 17 00:00:00 2001 From: Christopher Fenner <9592452+CFenner@users.noreply.github.com> Date: Mon, 24 Jun 2024 11:42:02 +0200 Subject: [PATCH 5/6] Update netatmo.js --- netatmo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netatmo.js b/netatmo.js index ee320b62..77d73051 100755 --- a/netatmo.js +++ b/netatmo.js @@ -387,7 +387,7 @@ Module.register('netatmo', { return 'Bft' case 'KT': return 'kt' - case 'KMH': + case 'KPH': default: return 'km/h' } From dfdb9e12a1658e1e5f44c2f4384d6059fc8c0741 Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Mon, 24 Jun 2024 11:53:51 +0200 Subject: [PATCH 6/6] fix eslint findings --- netatmo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netatmo.js b/netatmo.js index 77d73051..fda41818 100755 --- a/netatmo.js +++ b/netatmo.js @@ -82,7 +82,7 @@ Module.register('netatmo', { }, this.config.updateInterval * 60 * 1000 + this.config.initialDelay * 1000) }, updateUnitOfMeasurements (userPreferences) { - if (this.config.unitOfMeasurementWind === ''){ + if (this.config.unitOfMeasurementWind === '') { this.config.unitOfMeasurementWind = this.convertNetatmoWindUnit(userPreferences.windunit) console.log('Using user preferred unit of measurement for wind values %o', this.config.unitOfMeasurementWind) }