iobroker.nuasense 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,92 +1,269 @@
1
1
  {
2
- "i18n": false,
2
+ "i18n": true,
3
3
  "type": "tabs",
4
4
  "items": {
5
5
  "read": {
6
6
  "type": "panel",
7
- "label": { "en": "Read from NuaSense", "de": "Von NuaSense lesen" },
7
+ "label": "Read from NuaSense",
8
8
  "items": {
9
9
  "intro": {
10
10
  "type": "staticText",
11
- "text": { "en": "An API key from platform.nuasense.com → API Keys, with the ingest:write scope (it is also what reads your own stations). Leave empty if you only want to forward a station.", "de": "Ein API-Key von platform.nuasense.com → API Keys mit dem Scope ingest:write (er liest auch die eigenen Stationen). Leer lassen, wenn nur eine Station weitergeleitet werden soll." },
12
- "newLine": true
11
+ "text": "An API key from platform.nuasense.com, API Keys, with the ingest:write scope. Leave empty if you only want to forward a station.",
12
+ "newLine": true,
13
+ "xs": 12,
14
+ "sm": 12,
15
+ "md": 12,
16
+ "lg": 12,
17
+ "xl": 12
13
18
  },
14
19
  "apiKey": {
15
20
  "type": "password",
16
- "label": { "en": "API key", "de": "API-Key" },
21
+ "label": "API key",
17
22
  "newLine": true,
18
- "sm": 12, "md": 8
23
+ "xs": 12,
24
+ "sm": 12,
25
+ "md": 8,
26
+ "lg": 6,
27
+ "xl": 6
19
28
  },
20
29
  "stationId": {
21
30
  "type": "text",
22
- "label": { "en": "Station id (empty = all stations on the account)", "de": "Station-ID (leer = alle Stationen des Kontos)" },
31
+ "label": "Station id (empty = all stations on the account)",
32
+ "newLine": true,
33
+ "xs": 12,
34
+ "sm": 12,
35
+ "md": 8,
36
+ "lg": 6,
37
+ "xl": 6
38
+ },
39
+ "plant": {
40
+ "type": "select",
41
+ "label": "The garden is mostly",
42
+ "options": [
43
+ {
44
+ "label": "Lawn",
45
+ "value": "lawn"
46
+ },
47
+ {
48
+ "label": "Vegetables",
49
+ "value": "vegetables"
50
+ },
51
+ {
52
+ "label": "Flower beds and shrubs",
53
+ "value": "beds"
54
+ }
55
+ ],
56
+ "newLine": true,
57
+ "xs": 12,
58
+ "sm": 12,
59
+ "md": 4,
60
+ "lg": 3,
61
+ "xl": 3
62
+ },
63
+ "sprinklerRate": {
64
+ "type": "number",
65
+ "label": "Sprinkler rate (mm per hour; 0 = only mm)",
66
+ "min": 0,
67
+ "max": 100,
68
+ "step": 0.5,
69
+ "xs": 12,
70
+ "sm": 12,
71
+ "md": 4,
72
+ "lg": 3,
73
+ "xl": 3
74
+ },
75
+ "advanced": {
76
+ "type": "checkbox",
77
+ "label": "Advanced: agronomy values (spray window, ET0 per hour, leaf wetness, VPD, delta T)",
23
78
  "newLine": true,
24
- "sm": 12, "md": 8
79
+ "xs": 12,
80
+ "sm": 12,
81
+ "md": 8,
82
+ "lg": 6,
83
+ "xl": 6
25
84
  },
26
85
  "pollMinutes": {
27
86
  "type": "number",
28
- "label": { "en": "Read every (minutes)", "de": "Lesen alle (Minuten)" },
29
- "min": 5, "max": 240,
87
+ "label": "Read every (minutes)",
88
+ "min": 5,
89
+ "max": 240,
30
90
  "newLine": true,
31
- "sm": 6, "md": 3
91
+ "xs": 12,
92
+ "sm": 6,
93
+ "md": 3,
94
+ "lg": 2,
95
+ "xl": 2
32
96
  },
33
97
  "baseUrl": {
34
98
  "type": "text",
35
- "label": { "en": "API address", "de": "API-Adresse" },
99
+ "label": "API address",
36
100
  "newLine": true,
37
- "sm": 12, "md": 8
101
+ "xs": 12,
102
+ "sm": 12,
103
+ "md": 8,
104
+ "lg": 6,
105
+ "xl": 6
38
106
  }
39
107
  }
40
108
  },
41
109
  "send": {
42
110
  "type": "panel",
43
- "label": { "en": "Forward a station to NuaSense", "de": "Station an NuaSense weiterleiten" },
111
+ "label": "Forward a station to NuaSense",
44
112
  "items": {
45
113
  "intro2": {
46
114
  "type": "staticText",
47
- "text": { "en": "In the NuaSense console: External stations → Add a station → pick 'Home Assistant / weewx / Meteobridge / Node-RED'. The last screen shows a path like /station/kw7n-4hpd-x2vt; the part after /station/ is the token. Then pick the ioBroker states that hold your station's values; missing ones are simply not sent.", "de": "In der NuaSense-Konsole: External stations → Add a station → «Home Assistant / weewx / Meteobridge / Node-RED» wählen. Der letzte Schritt zeigt einen Pfad wie /station/kw7n-4hpd-x2vt; der Teil nach /station/ ist der Token. Dann die ioBroker-States wählen, die die Werte der Station halten; fehlende werden einfach nicht gesendet." },
48
- "newLine": true
115
+ "text": "In the NuaSense console: External stations, Add a station, pick Home Assistant / weewx / Meteobridge / Node-RED. The last screen shows a path like /station/kw7n-4hpd-x2vt; the part after /station/ is the token. Then pick the ioBroker states that hold your station's values; missing ones are simply not sent.",
116
+ "newLine": true,
117
+ "xs": 12,
118
+ "sm": 12,
119
+ "md": 12,
120
+ "lg": 12,
121
+ "xl": 12
49
122
  },
50
123
  "forwardEnabled": {
51
124
  "type": "checkbox",
52
- "label": { "en": "Forward a station", "de": "Station weiterleiten" },
53
- "newLine": true
125
+ "label": "Forward a station",
126
+ "newLine": true,
127
+ "xs": 12,
128
+ "sm": 12,
129
+ "md": 6,
130
+ "lg": 4,
131
+ "xl": 4
54
132
  },
55
133
  "forwardToken": {
56
134
  "type": "password",
57
- "label": { "en": "Station token", "de": "Station-Token" },
135
+ "label": "Station token",
58
136
  "newLine": true,
59
- "sm": 12, "md": 6
137
+ "xs": 12,
138
+ "sm": 12,
139
+ "md": 6,
140
+ "lg": 4,
141
+ "xl": 4
60
142
  },
61
143
  "forwardDeviceId": {
62
144
  "type": "text",
63
- "label": { "en": "Device id (any text; keep it stable)", "de": "Geräte-ID (beliebiger Text; stabil lassen)" },
64
- "sm": 12, "md": 6
145
+ "label": "Device id (any text; keep it stable)",
146
+ "xs": 12,
147
+ "sm": 12,
148
+ "md": 6,
149
+ "lg": 4,
150
+ "xl": 4
65
151
  },
66
152
  "forwardServer": {
67
153
  "type": "text",
68
- "label": { "en": "Receiver", "de": "Empfänger" },
154
+ "label": "Receiver",
69
155
  "newLine": true,
70
- "sm": 12, "md": 6
156
+ "xs": 12,
157
+ "sm": 12,
158
+ "md": 6,
159
+ "lg": 4,
160
+ "xl": 4
161
+ },
162
+ "temperatureState": {
163
+ "type": "objectId",
164
+ "label": "Temperature (°C)",
165
+ "newLine": true,
166
+ "xs": 12,
167
+ "sm": 12,
168
+ "md": 6,
169
+ "lg": 4,
170
+ "xl": 4
171
+ },
172
+ "humidityState": {
173
+ "type": "objectId",
174
+ "label": "Humidity (%)",
175
+ "xs": 12,
176
+ "sm": 12,
177
+ "md": 6,
178
+ "lg": 4,
179
+ "xl": 4
180
+ },
181
+ "pressureState": {
182
+ "type": "objectId",
183
+ "label": "Pressure at station level (hPa)",
184
+ "newLine": true,
185
+ "xs": 12,
186
+ "sm": 12,
187
+ "md": 6,
188
+ "lg": 4,
189
+ "xl": 4
190
+ },
191
+ "windSpeedState": {
192
+ "type": "objectId",
193
+ "label": "Wind speed",
194
+ "xs": 12,
195
+ "sm": 12,
196
+ "md": 4,
197
+ "lg": 3,
198
+ "xl": 3
71
199
  },
72
- "temperatureState": { "type": "objectId", "label": { "en": "Temperature (°C)", "de": "Temperatur (°C)" }, "newLine": true, "sm": 12, "md": 6 },
73
- "humidityState": { "type": "objectId", "label": { "en": "Humidity (%)", "de": "Luftfeuchte (%)" }, "sm": 12, "md": 6 },
74
- "pressureState": { "type": "objectId", "label": { "en": "Pressure, station level (hPa)", "de": "Luftdruck, Stationshöhe (hPa)" }, "newLine": true, "sm": 12, "md": 6 },
75
- "windSpeedState": { "type": "objectId", "label": { "en": "Wind speed", "de": "Windgeschwindigkeit" }, "sm": 12, "md": 4 },
76
200
  "windUnit": {
77
201
  "type": "select",
78
- "label": { "en": "Wind unit", "de": "Windeinheit" },
202
+ "label": "Wind unit",
79
203
  "options": [
80
- { "label": "m/s", "value": "ms" },
81
- { "label": "km/h", "value": "kmh" }
204
+ {
205
+ "label": "m/s",
206
+ "value": "ms"
207
+ },
208
+ {
209
+ "label": "km/h",
210
+ "value": "kmh"
211
+ }
82
212
  ],
83
- "sm": 12, "md": 2
213
+ "xs": 12,
214
+ "sm": 12,
215
+ "md": 2,
216
+ "lg": 1,
217
+ "xl": 1
218
+ },
219
+ "windGustState": {
220
+ "type": "objectId",
221
+ "label": "Wind gusts",
222
+ "newLine": true,
223
+ "xs": 12,
224
+ "sm": 12,
225
+ "md": 6,
226
+ "lg": 4,
227
+ "xl": 4
84
228
  },
85
- "windGustState": { "type": "objectId", "label": { "en": "Wind gusts", "de": "Windböen" }, "newLine": true, "sm": 12, "md": 6 },
86
- "windDirectionState": { "type": "objectId", "label": { "en": "Wind direction (°)", "de": "Windrichtung (°)" }, "sm": 12, "md": 6 },
87
- "rainTotalState": { "type": "objectId", "label": { "en": "Rain total (mm, a counter that only grows)", "de": "Regen gesamt (mm, ein Zähler, der nur wächst)" }, "newLine": true, "sm": 12, "md": 6 },
88
- "solarState": { "type": "objectId", "label": { "en": "Solar radiation (W/m²)", "de": "Globalstrahlung (W/m²)" }, "sm": 12, "md": 6 },
89
- "luxState": { "type": "objectId", "label": { "en": "Light (lux), if no W/m²", "de": "Licht (Lux), falls kein W/m²" }, "newLine": true, "sm": 12, "md": 6 }
229
+ "windDirectionState": {
230
+ "type": "objectId",
231
+ "label": "Wind direction (°)",
232
+ "xs": 12,
233
+ "sm": 12,
234
+ "md": 6,
235
+ "lg": 4,
236
+ "xl": 4
237
+ },
238
+ "rainTotalState": {
239
+ "type": "objectId",
240
+ "label": "Rain total (mm, a counter that only grows)",
241
+ "newLine": true,
242
+ "xs": 12,
243
+ "sm": 12,
244
+ "md": 6,
245
+ "lg": 4,
246
+ "xl": 4
247
+ },
248
+ "solarState": {
249
+ "type": "objectId",
250
+ "label": "Solar radiation (W/m²)",
251
+ "xs": 12,
252
+ "sm": 12,
253
+ "md": 6,
254
+ "lg": 4,
255
+ "xl": 4
256
+ },
257
+ "luxState": {
258
+ "type": "objectId",
259
+ "label": "Light (lux), if no W/m²",
260
+ "newLine": true,
261
+ "xs": 12,
262
+ "sm": 12,
263
+ "md": 6,
264
+ "lg": 4,
265
+ "xl": 4
266
+ }
90
267
  }
91
268
  }
92
269
  }
package/io-package.json CHANGED
@@ -1,8 +1,34 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "nuasense",
4
- "version": "0.1.0",
4
+ "version": "0.2.0",
5
5
  "news": {
6
+ "0.2.0": {
7
+ "en": "House & garden first: frost tonight, watering today in mm and minutes, rain next 24 h, plausibility; agronomy values behind Advanced",
8
+ "de": "Haus & Garten zuerst: Frost heute Nacht, Giessen heute in mm und Minuten, Regen der nächsten 24 h, Plausibilität; Agronomie-Werte unter «Erweitert»",
9
+ "ru": "Сначала дом и сад: заморозки ночью, полив сегодня в мм и минутах, дождь за 24 ч, правдоподобность; агрономические значения в разделе «Расширенные»",
10
+ "pt": "Casa e jardim primeiro: geada esta noite, rega hoje em mm e minutos, chuva nas próximas 24 h, plausibilidade; valores agronómicos em Avançado",
11
+ "nl": "Huis & tuin eerst: vorst vannacht, water geven vandaag in mm en minuten, regen komende 24 u, plausibiliteit; agronomische waarden onder Geavanceerd",
12
+ "fr": "Maison et jardin d'abord : gel cette nuit, arrosage du jour en mm et en minutes, pluie des 24 h à venir, plausibilité ; valeurs agronomiques dans Avancé",
13
+ "it": "Prima casa e giardino: gelo stanotte, irrigazione di oggi in mm e minuti, pioggia nelle prossime 24 h, plausibilità; valori agronomici in Avanzate",
14
+ "es": "Primero casa y jardín: helada esta noche, riego de hoy en mm y minutos, lluvia en las próximas 24 h, plausibilidad; valores agronómicos en Avanzado",
15
+ "pl": "Najpierw dom i ogród: przymrozek w nocy, podlewanie dziś w mm i minutach, deszcz w ciągu 24 h, wiarygodność; wartości agronomiczne w Zaawansowanych",
16
+ "uk": "Спочатку дім і сад: заморозки вночі, полив сьогодні в мм і хвилинах, дощ на 24 год, правдоподібність; агрономічні значення в розділі «Розширені»",
17
+ "zh-cn": "优先家居与花园:今夜霜冻、今日浇水量(毫米与分钟)、未来 24 小时降雨、合理性;农艺数值放在“高级”中"
18
+ },
19
+ "0.1.1": {
20
+ "en": "Checker fixes: Node.js 22, i18n for the admin UI, responsive sizes, trusted publishing workflow",
21
+ "de": "Checker-Korrekturen: Node.js 22, i18n für die Admin-Oberfläche, responsive Größen, Trusted-Publishing-Workflow",
22
+ "ru": "Исправления по чекеру: Node.js 22, i18n для панели администратора, адаптивные размеры, рабочий процесс доверенной публикации",
23
+ "pt": "Correções do verificador: Node.js 22, i18n para a interface de administração, tamanhos responsivos, fluxo de publicação confiável",
24
+ "nl": "Checker-fixes: Node.js 22, i18n voor de beheer-UI, responsieve groottes, trusted-publishing-workflow",
25
+ "fr": "Corrections du vérificateur : Node.js 22, i18n pour l'interface d'administration, tailles responsives, flux de publication de confiance",
26
+ "it": "Correzioni del checker: Node.js 22, i18n per l'interfaccia di amministrazione, dimensioni responsive, flusso di pubblicazione attendibile",
27
+ "es": "Correcciones del verificador: Node.js 22, i18n para la interfaz de administración, tamaños adaptables, flujo de publicación de confianza",
28
+ "pl": "Poprawki checkera: Node.js 22, i18n dla panelu administracyjnego, rozmiary responsywne, zaufany proces publikacji",
29
+ "uk": "Виправлення за чекером: Node.js 22, i18n для панелі адміністратора, адаптивні розміри, довірений процес публікації",
30
+ "zh-cn": "检查器修复:Node.js 22、管理界面 i18n、响应式尺寸、可信发布工作流"
31
+ },
6
32
  "0.1.0": {
7
33
  "en": "First release: first look and hourly agronomy as states; optional forwarding of a station from ioBroker to NuaSense",
8
34
  "de": "Erste Version: Erster Blick und stündliche Agronomie als States; optional Weiterleitung einer Station von ioBroker zu NuaSense",
@@ -31,20 +57,30 @@
31
57
  "zh-cn": "NuaSense"
32
58
  },
33
59
  "desc": {
34
- "en": "What your weather station means for your crop: tonight's low and frost, the next spray window, ET0, leaf wetness, spray quality. Optionally forwards a station from ioBroker to NuaSense.",
35
- "de": "Was deine Wetterstation für deine Kultur bedeutet: Tief und Frost heute Nacht, das nächste Spritzfenster, ET0, Blattnässe, Spritzqualität. Optional Weiterleitung einer Station von ioBroker zu NuaSense.",
36
- "ru": "Что ваша метеостанция значит для вашей культуры: ночной минимум и заморозки, следующее окно для опрыскивания, ET0, увлажнение листьев. Опционально пересылает станцию из ioBroker в NuaSense.",
37
- "pt": "O que a sua estação meteorológica significa para a sua cultura: mínima e geada desta noite, próxima janela de pulverização, ET0, molhamento foliar. Opcionalmente encaminha uma estação do ioBroker para o NuaSense.",
38
- "nl": "Wat je weerstation betekent voor je gewas: minimum en vorst vannacht, het volgende spuitvenster, ET0, bladnat. Optioneel doorsturen van een station van ioBroker naar NuaSense.",
39
- "fr": "Ce que votre station météo signifie pour votre culture : minimum et gel de la nuit, prochaine fenêtre de pulvérisation, ET0, humectation foliaire. Transfert optionnel d'une station d'ioBroker vers NuaSense.",
40
- "it": "Cosa significa la tua stazione meteo per la tua coltura: minima e gelo stanotte, prossima finestra di irrorazione, ET0, bagnatura fogliare. Inoltro opzionale di una stazione da ioBroker a NuaSense.",
41
- "es": "Lo que su estación meteorológica significa para su cultivo: mínima y helada de esta noche, próxima ventana de pulverización, ET0, mojado foliar. Reenvío opcional de una estación de ioBroker a NuaSense.",
42
- "pl": "Co Twoja stacja pogodowa oznacza dla Twojej uprawy: nocne minimum i przymrozek, następne okno oprysku, ET0, zwilżenie liści. Opcjonalne przekazywanie stacji z ioBroker do NuaSense.",
43
- "uk": "Що ваша метеостанція означає для вашої культури: нічний мінімум і заморозки, наступне вікно обприскування, ET0, зволоження листя. Необов'язкове пересилання станції з ioBroker до NuaSense.",
44
- "zh-cn": "您的气象站对作物意味着什么:今夜最低温与霜冻、下一个喷药窗口、ET0、叶面湿润。可选将气象站从 ioBroker 转发到 NuaSense。"
60
+ "en": "What your weather station means for your house and garden: frost tonight, watering today in mm and minutes, rain in the next 24 hours, plausibility of the readings. Optionally forwards a station from ioBroker to NuaSense; agronomy values for farms on request.",
61
+ "de": "Was deine Wetterstation für Haus und Garten bedeutet: Frost heute Nacht, Giessen heute in mm und Minuten, Regen der nächsten 24 Stunden, Plausibilität der Messwerte. Optional Weiterleitung einer Station von ioBroker zu NuaSense; Agronomie-Werte für Betriebe auf Wunsch.",
62
+ "ru": "Что ваша метеостанция значит для дома и сада: заморозки ночью, полив сегодня в мм и минутах, дождь в ближайшие 24 часа, правдоподобность показаний. Опционально пересылает станцию из ioBroker в NuaSense; агрономические значения для хозяйств по желанию.",
63
+ "pt": "O que a sua estação meteorológica significa para a casa e o jardim: geada esta noite, rega hoje em mm e minutos, chuva nas próximas 24 horas, plausibilidade das leituras. Opcionalmente encaminha uma estação do ioBroker para o NuaSense; valores agronómicos para explorações a pedido.",
64
+ "nl": "Wat je weerstation betekent voor huis en tuin: vorst vannacht, water geven vandaag in mm en minuten, regen in de komende 24 uur, plausibiliteit van de metingen. Optioneel doorsturen van een station van ioBroker naar NuaSense; agronomische waarden voor bedrijven op verzoek.",
65
+ "fr": "Ce que votre station météo signifie pour la maison et le jardin : gel cette nuit, arrosage du jour en mm et en minutes, pluie des 24 prochaines heures, plausibilité des mesures. Transfert optionnel d'une station d'ioBroker vers NuaSense ; valeurs agronomiques pour les exploitations sur demande.",
66
+ "it": "Cosa significa la tua stazione meteo per casa e giardino: gelo stanotte, irrigazione di oggi in mm e minuti, pioggia nelle prossime 24 ore, plausibilità delle misure. Inoltro opzionale di una stazione da ioBroker a NuaSense; valori agronomici per le aziende su richiesta.",
67
+ "es": "Lo que su estación meteorológica significa para la casa y el jardín: helada esta noche, riego de hoy en mm y minutos, lluvia en las próximas 24 horas, plausibilidad de las lecturas. Reenvío opcional de una estación de ioBroker a NuaSense; valores agronómicos para explotaciones bajo demanda.",
68
+ "pl": "Co Twoja stacja pogodowa oznacza dla domu i ogrodu: przymrozek w nocy, podlewanie dziś w mm i minutach, deszcz w ciągu najbliższych 24 godzin, wiarygodność pomiarów. Opcjonalne przekazywanie stacji z ioBroker do NuaSense; wartości agronomiczne dla gospodarstw na życzenie.",
69
+ "uk": "Що ваша метеостанція означає для дому й саду: заморозки вночі, полив сьогодні в мм і хвилинах, дощ у найближчі 24 години, правдоподібність вимірювань. Необов'язкове пересилання станції з ioBroker до NuaSense; агрономічні значення для господарств за бажанням.",
70
+ "zh-cn": "您的气象站对家居与花园意味着什么:今夜霜冻、今日浇水量(毫米与分钟)、未来 24 小时降雨、读数合理性。可选将气象站从 ioBroker 转发到 NuaSense;农场可按需启用农艺数值。"
45
71
  },
46
- "authors": ["NuaSense <manuel@nuasense.com>"],
47
- "keywords": ["weather", "weather station", "agriculture", "frost", "spray", "evapotranspiration", "nuasense"],
72
+ "authors": [
73
+ "NuaSense <manuel@nuasense.com>"
74
+ ],
75
+ "keywords": [
76
+ "weather",
77
+ "weather station",
78
+ "agriculture",
79
+ "frost",
80
+ "spray",
81
+ "evapotranspiration",
82
+ "nuasense"
83
+ ],
48
84
  "licenseInformation": {
49
85
  "type": "free",
50
86
  "license": "MIT"
@@ -66,12 +102,12 @@
66
102
  },
67
103
  "dependencies": [
68
104
  {
69
- "js-controller": ">=5.0.19"
105
+ "js-controller": ">=6.0.11"
70
106
  }
71
107
  ],
72
108
  "globalDependencies": [
73
109
  {
74
- "admin": ">=6.17.14"
110
+ "admin": ">=7.6.20"
75
111
  }
76
112
  ]
77
113
  },
@@ -93,10 +129,19 @@
93
129
  "windDirectionState": "",
94
130
  "rainTotalState": "",
95
131
  "solarState": "",
96
- "luxState": ""
132
+ "luxState": "",
133
+ "plant": "lawn",
134
+ "sprinklerRate": 10,
135
+ "advanced": false
97
136
  },
98
- "protectedNative": ["apiKey", "forwardToken"],
99
- "encryptedNative": ["apiKey", "forwardToken"],
137
+ "protectedNative": [
138
+ "apiKey",
139
+ "forwardToken"
140
+ ],
141
+ "encryptedNative": [
142
+ "apiKey",
143
+ "forwardToken"
144
+ ],
100
145
  "objects": [],
101
146
  "instanceObjects": [
102
147
  {
package/lib/ecowitt.js CHANGED
@@ -10,7 +10,7 @@
10
10
  * path to it. Everything here is pure, so it is tested without Node-RED.
11
11
  */
12
12
 
13
- const crypto = require("crypto");
13
+ const crypto = require("node:crypto");
14
14
 
15
15
  const INHG_PER_HPA = 1 / 33.8639;
16
16
  const MPH_PER_MS = 1 / 0.44704;
@@ -20,7 +20,9 @@ const IN_PER_MM = 1 / 25.4;
20
20
  const LUX_PER_WM2 = 120;
21
21
 
22
22
  const num = (v) => {
23
- if (v === null || v === undefined || v === "") return null;
23
+ if (v === null || v === undefined || v === "") {
24
+ return null;
25
+ }
24
26
  const n = Number(v);
25
27
  return Number.isFinite(n) ? n : null;
26
28
  };
@@ -29,13 +31,19 @@ const fix = (n, digits) => (n === null ? null : Number(n.toFixed(digits)));
29
31
  /** Ecowitt's `dateutc`: "YYYY-MM-DD HH:MM:SS", UTC. */
30
32
  function dateUtc(when) {
31
33
  const d = when instanceof Date ? when : when ? new Date(when) : new Date();
32
- if (Number.isNaN(d.getTime())) return dateUtc(new Date());
34
+ if (Number.isNaN(d.getTime())) {
35
+ return dateUtc(new Date());
36
+ }
33
37
  return d.toISOString().slice(0, 19).replace("T", " ");
34
38
  }
35
39
 
36
40
  /** A stable 32-hex PASSKEY from whatever names the device in the flow. */
37
41
  function passkeyFor(deviceId) {
38
- return crypto.createHash("md5").update(String(deviceId || "node-red"), "utf8").digest("hex").toUpperCase();
42
+ return crypto
43
+ .createHash("md5")
44
+ .update(String(deviceId || "node-red"), "utf8")
45
+ .digest("hex")
46
+ .toUpperCase();
39
47
  }
40
48
 
41
49
  /**
@@ -45,7 +53,10 @@ function passkeyFor(deviceId) {
45
53
  * solar_wm2 (W/m²) or light_lux, time (ISO or Date; now when absent)
46
54
  * @returns the form fields, as strings, in the order a console sends them
47
55
  */
48
- function toEcowitt(reading, { deviceId, stationType = "node-red-contrib-nuasense" } = {}) {
56
+ function toEcowitt(
57
+ reading,
58
+ { deviceId, stationType = "node-red-contrib-nuasense" } = {},
59
+ ) {
49
60
  const r = reading && typeof reading === "object" ? reading : {};
50
61
  const fields = {
51
62
  PASSKEY: passkeyFor(deviceId),
@@ -53,25 +64,44 @@ function toEcowitt(reading, { deviceId, stationType = "node-red-contrib-nuasense
53
64
  dateutc: dateUtc(r.time),
54
65
  };
55
66
  const t = num(r.temperature);
56
- if (t !== null) fields.tempf = String(fix(t * 9 / 5 + 32, 2));
67
+ if (t !== null) {
68
+ fields.tempf = String(fix((t * 9) / 5 + 32, 2));
69
+ }
57
70
  const h = num(r.humidity);
58
- if (h !== null) fields.humidity = String(Math.round(h));
71
+ if (h !== null) {
72
+ fields.humidity = String(Math.round(h));
73
+ }
59
74
  const p = num(r.pressure);
60
- if (p !== null) fields.baromabsin = String(fix(p * INHG_PER_HPA, 3));
75
+ if (p !== null) {
76
+ fields.baromabsin = String(fix(p * INHG_PER_HPA, 3));
77
+ }
61
78
  const ws = num(r.wind_speed);
62
- if (ws !== null) fields.windspeedmph = String(fix(ws * MPH_PER_MS, 2));
79
+ if (ws !== null) {
80
+ fields.windspeedmph = String(fix(ws * MPH_PER_MS, 2));
81
+ }
63
82
  const wg = num(r.wind_gusts);
64
- if (wg !== null) fields.windgustmph = String(fix(wg * MPH_PER_MS, 2));
83
+ if (wg !== null) {
84
+ fields.windgustmph = String(fix(wg * MPH_PER_MS, 2));
85
+ }
65
86
  const wd = num(r.wind_direction);
66
- if (wd !== null) fields.winddir = String(Math.round(((wd % 360) + 360) % 360));
87
+ if (wd !== null) {
88
+ fields.winddir = String(Math.round(((wd % 360) + 360) % 360));
89
+ }
67
90
  const rain = num(r.rain_total_mm);
68
- if (rain !== null) fields.yearlyrainin = String(fix(rain * IN_PER_MM, 3));
91
+ if (rain !== null) {
92
+ fields.yearlyrainin = String(fix(rain * IN_PER_MM, 3));
93
+ }
69
94
  const sol = num(r.solar_wm2);
70
95
  const lux = num(r.light_lux);
71
- if (sol !== null) fields.solarradiation = String(fix(sol, 2));
72
- else if (lux !== null) fields.solarradiation = String(fix(lux / LUX_PER_WM2, 2));
96
+ if (sol !== null) {
97
+ fields.solarradiation = String(fix(sol, 2));
98
+ } else if (lux !== null) {
99
+ fields.solarradiation = String(fix(lux / LUX_PER_WM2, 2));
100
+ }
73
101
  const uv = num(r.uv);
74
- if (uv !== null) fields.uv = String(Math.round(uv));
102
+ if (uv !== null) {
103
+ fields.uv = String(Math.round(uv));
104
+ }
75
105
  return fields;
76
106
  }
77
107
 
@@ -83,10 +113,26 @@ function encodeForm(fields) {
83
113
 
84
114
  /** The upload URL for a token as it is shown: kw7n-4hpd-x2vt (hyphens are fine on the wire). */
85
115
  function uploadUrl(server, token) {
86
- const host = String(server || "ingest.nuasense.com").trim().replace(/^https?:\/\//, "").replace(/\/+$/, "");
87
- const tok = String(token || "").trim().toLowerCase();
88
- if (!/^[a-z0-9-]{12,29}$/.test(tok)) throw new Error("the station path token looks wrong — copy it from the console");
116
+ const host = String(server || "ingest.nuasense.com")
117
+ .trim()
118
+ .replace(/^https?:\/\//, "")
119
+ .replace(/\/+$/, "");
120
+ const tok = String(token || "")
121
+ .trim()
122
+ .toLowerCase();
123
+ if (!/^[a-z0-9-]{12,29}$/.test(tok)) {
124
+ throw new Error(
125
+ "the station path token looks wrong — copy it from the console",
126
+ );
127
+ }
89
128
  return `http://${host}/station/${tok}`;
90
129
  }
91
130
 
92
- module.exports = { toEcowitt, encodeForm, uploadUrl, passkeyFor, dateUtc, LUX_PER_WM2 };
131
+ module.exports = {
132
+ toEcowitt,
133
+ encodeForm,
134
+ uploadUrl,
135
+ passkeyFor,
136
+ dateUtc,
137
+ LUX_PER_WM2,
138
+ };