iobroker.esphome 0.3.0 → 0.3.2

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.
@@ -0,0 +1,47 @@
1
+ # Older changes
2
+ ## 0.2.2 (2021-06-24)
3
+ * (DutchmanNL) [!!! Breaking !!!] Make YAML file persistent, backup your configuration before updating ! solves [#57](https://github.com/DrozmotiX/ioBroker.esphome/issues/57)
4
+ * (DutchmanNL) Update ESPHome Dashboard to 1.18.0, requires Python >=3.7 (and ensure <4.0!)
5
+ * (DutchmanNL) Bugfix : Reconnect to devices without autodiscovery / MDNS-Broadcast in network, solves [#66](https://github.com/DrozmotiX/ioBroker.esphome/issues/66)
6
+
7
+ ## 0.2.1-1 (2021-03-30)
8
+ * (DutchmanNL) add cover component
9
+ * (DutchmanNL) add transitionLength for lights
10
+
11
+ ## 0.2.1-0 (2021-03-30)
12
+ * (DutchmanNL) Logging improved, solves [#48](https://github.com/DrozmotiX/ioBroker.esphome/issues/48)
13
+ * (DutchmanNL) Name of states changed, solves [#49](https://github.com/DrozmotiX/ioBroker.esphome/issues/49)
14
+
15
+ ## 0.2.0 (2021-03-29)
16
+ * (DutchmanNL) Translations updated
17
+ * (DutchmanNL) Configuration page updated
18
+ * (DutchmanNL) Added to sentry error reporting
19
+ * (DutchmanNL) Native integration of ESPHome Dashboard added
20
+
21
+ ## 0.1.5 (2021-03-21)
22
+ * (DutchmanNL) Add Translations
23
+
24
+ ## 0.1.4 (2021-03-19)
25
+ * (DutchmanNL) Implemented RGBW
26
+ * (DutchmanNL) Ensure correct encryption and storage of passwords
27
+ * (DutchmanNL) Proper value ranges for type light (255 instead 100)
28
+ * (DutchmanNL) Implemented hex color state for type light (if RGB is available)
29
+
30
+ ## 0.1.2 (2021-03-02)
31
+ * (DutchmanNL) Type Fan added
32
+ * (DutchmanNL) Type Light added
33
+ * (DutchmanNL) Error messages optimized
34
+ * (DutchmanNL) Device reconnect handling improved
35
+ * (DutchmanNL) [Breaking!] Change state name to default "state" for type BinarySensor / Climate / Sensor / TextSensor & Switch
36
+ * (DutchmanNL) Autodiscovery improved, non-ESPHome devices excluded
37
+
38
+ ## 0.1.0 (2021-02-27)
39
+ * (DutchmanNL) Autodiscovery implemented
40
+ * (DutchmanNL) Type Climat added
41
+ * (DutchmanNL) Type TextSensor added
42
+ * (DutchmanNL) Solved reconnection issues
43
+ * (DutchmanNL) Optimized error messages for unknown types
44
+ * (DutchmanNL & @xXBJXx) Adapter configuration page optimized
45
+
46
+ ## 0.0.1
47
+ * (DutchmanNL) initial release
package/README.md CHANGED
@@ -112,6 +112,13 @@ If you like my work, please consider a personal donation
112
112
  ### __WORK IN PROGRESS__
113
113
  * (DutchmanNL)
114
114
  -->
115
+ ### 0.3.2 (2023-11-01)
116
+ * (DutchmanNL) Improved error handling if devices are not reachable/disconnected
117
+ * (DutchmanNL) Bugfix: Allow control of brightness and color for light component, fixes #173
118
+
119
+ ### 0.3.1 (2023-10-31)
120
+ * (DutchmanNL) Bugfix: Show online state of ESP Device correctly, Fixes #106
121
+
115
122
  ### 0.3.0 (2023-10-31) - Bugfixes & Improvements
116
123
  * (Dutchman & SimonFischer04) Several Bugfixes
117
124
  * (SimonFischer04) Support type "select device"
@@ -128,53 +135,6 @@ If you like my work, please consider a personal donation
128
135
  * (Jey-Cee) Bugfix : Light component state not changed [#74](https://github.com/DrozmotiX/ioBroker.esphome/issues/74)
129
136
  * (DutchmanNL) Update compatibility to version 1.19.4 of ESPHome Dashboard
130
137
 
131
- ### 0.2.2 (2021-06-24)
132
- * (DutchmanNL) [!!! Breaking !!!] Make YAML file persistent, backup your configuration before updating ! solves [#57](https://github.com/DrozmotiX/ioBroker.esphome/issues/57)
133
- * (DutchmanNL) Update ESPHome Dashboard to 1.18.0, requires Python >=3.7 (and ensure <4.0!)
134
- * (DutchmanNL) Bugfix : Reconnect to devices without autodiscovery / MDNS-Broadcast in network, solves [#66](https://github.com/DrozmotiX/ioBroker.esphome/issues/66)
135
-
136
- ### 0.2.1-1 (2021-03-30)
137
- * (DutchmanNL) add cover component
138
- * (DutchmanNL) add transitionLength for lights
139
-
140
- ### 0.2.1-0 (2021-03-30)
141
- * (DutchmanNL) Logging improved, solves [#48](https://github.com/DrozmotiX/ioBroker.esphome/issues/48)
142
- * (DutchmanNL) Name of states changed, solves [#49](https://github.com/DrozmotiX/ioBroker.esphome/issues/49)
143
-
144
- ### 0.2.0 (2021-03-29)
145
- * (DutchmanNL) Translations updated
146
- * (DutchmanNL) Configuration page updated
147
- * (DutchmanNL) Added to sentry error reporting
148
- * (DutchmanNL) Native integration of ESPHome Dashboard added
149
-
150
- ### 0.1.5 (2021-03-21)
151
- * (DutchmanNL) Add Translations
152
-
153
- ### 0.1.4 (2021-03-19)
154
- * (DutchmanNL) Implemented RGBW
155
- * (DutchmanNL) Ensure correct encryption and storage of passwords
156
- * (DutchmanNL) Proper value ranges for type light (255 instead 100)
157
- * (DutchmanNL) Implemented hex color state for type light (if RGB is available)
158
-
159
- ### 0.1.2 (2021-03-02)
160
- * (DutchmanNL) Type Fan added
161
- * (DutchmanNL) Type Light added
162
- * (DutchmanNL) Error messages optimized
163
- * (DutchmanNL) Device reconnect handling improved
164
- * (DutchmanNL) [Breaking!] Change state name to default "state" for type BinarySensor / Climate / Sensor / TextSensor & Switch
165
- * (DutchmanNL) Autodiscovery improved, non-ESPHome devices excluded
166
-
167
- ### 0.1.0 (2021-02-27)
168
- * (DutchmanNL) Autodiscovery implemented
169
- * (DutchmanNL) Type Climat added
170
- * (DutchmanNL) Type TextSensor added
171
- * (DutchmanNL) Solved reconnection issues
172
- * (DutchmanNL) Optimized error messages for unknown types
173
- * (DutchmanNL & @xXBJXx) Adapter configuration page optimized
174
-
175
- ### 0.0.1
176
- * (DutchmanNL) initial release
177
-
178
138
  ## License
179
139
  MIT License
180
140
 
package/io-package.json CHANGED
@@ -1,8 +1,34 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "esphome",
4
- "version": "0.3.0",
4
+ "version": "0.3.2",
5
5
  "news": {
6
+ "0.3.2": {
7
+ "en": "Improved error handling if devices are not reachable/disconnected\nBugfix: Allow control of brightness and color for light component, fixes #173",
8
+ "de": "Verbesserte Fehlerbehandlung, wenn Geräte nicht erreichbar/vernetzt sind\nBugfix: Erlauben Sie die Kontrolle von Helligkeit und Farbe für die Lichtkomponente, fixiert #173",
9
+ "ru": "Улучшена обработка ошибок, если устройства не доступны / отключены\nBugfix: Разрешить контроль яркости и цвета для легкой составляющей, исправляет #173",
10
+ "pt": "Melhor manuseio de erros se os dispositivos não forem acessíveis/desconectados\nBugfix: Permitir controle de brilho e cor para componente de luz, correções #173",
11
+ "nl": "Improviserende fouten als de apparatuur niet bereikbaar is\nBugfix: Controle van helderheid en kleur voor lichtcomonent, reparatie #173",
12
+ "fr": "Amélioration de la manipulation des erreurs si les dispositifs ne sont pas accessibles/déconnectés\nBugfix: Permettre le contrôle de la luminosité et de la couleur pour le composant de lumière, corrige #173",
13
+ "it": "Miglioramento della gestione degli errori se i dispositivi non sono raggiungibili/disconnessi\nBugfix: Consentire il controllo di luminosità e colore per componenti leggeri, correzioni #173",
14
+ "es": "Mejor manejo de errores si los dispositivos no son accesibles/desconectados\nBugfix: Permitir el control del brillo y el color para el componente de luz, fija #173",
15
+ "pl": "Poprawiona obsługa błędów, jeśli urządzenia nie są dosyć dopasowalne i rozproszone\nBugfix: Allow kontrola jasności i koloru dla komponentów świetlnych naprawia numer #173",
16
+ "uk": "Поліпшення обробки помилок, якщо пристрої не досягаються / відключені\nПомилки: Дозволяє контролювати яскравість і колір для легкого компонента, закріплює #173",
17
+ "zh-cn": "如果装置无法达到/无联系,改进错误处理\nBugfix: 允许控制光明和颜色,确定第173号行动。"
18
+ },
19
+ "0.3.1": {
20
+ "en": "Bugfix: Show online state of ESP Device correctly, Fixes #106",
21
+ "de": "Bugfix: Online-Zustand von ESP Device korrekt anzeigen, Fixes #106",
22
+ "ru": "Bugfix: Показать онлайн состояние ESP Device правильно, Fixes #106",
23
+ "pt": "Bugfix: Mostrar estado on-line de ESP dispositivo corretamente, correções #106",
24
+ "nl": "Bugfix: Vertoon online staat van ESP Device correct, Fixes 106",
25
+ "fr": "Bugfix: Afficher l'état en ligne de l'appareil ESP correctement, Fixes #106",
26
+ "it": "Bugfix: Mostrare lo stato online del dispositivo ESP correttamente, Fisse #106",
27
+ "es": "Bugfix: Mostrar el estado online del dispositivo ESP correctamente, Fijaciones #106",
28
+ "pl": "Bugfix: Programy internetowe ESP Device poprawnie ↓, s. 106",
29
+ "uk": "Помилки: Показати онлайн стан ESP Пристрої правильно, Виправлення #106",
30
+ "zh-cn": "Bugfix: ESP Device在线状况,Fixes #106"
31
+ },
6
32
  "0.3.0": {
7
33
  "en": "Several Bugfixes\nSupport type \"select device\"\nESPHome dashboard default disabled\nMigrate to @2colors/esphome-native-api\nAutomatically create needed directories, Fixes #168\nMigrate usage of python to new structure, should solve all ESPHome Dashboard related installation issues",
8
34
  "de": "Mehrere Bugfixes\nSupport-Typ \"Auswahlgerät\"\nESPHome Dashboard default deaktiviert\nMigration auf @2colors/esphome-native-api\nAutomatische Erstellung erforderlicher Verzeichnisse, Fixes #168\nMigration der Nutzung von Python zu neuer Struktur, sollte alle ESPHome Dashboard bezogene Installation Probleme lösen",
@@ -63,30 +89,6 @@
63
89
  "es": "agregar componente de portada\nagregar transiciónLength para luces",
64
90
  "pl": "dodaj komponent okładki\ndodaj długość przejścia dla świateł",
65
91
  "zh-cn": "添加封面组件\n为灯光添加transitionLength"
66
- },
67
- "0.2.1-0": {
68
- "en": "Logging improved, solves [#48](https://github.com/DrozmotiX/ioBroker.esphome/issues/48)\nName of states changed, solves [#49](https://github.com/DrozmotiX/ioBroker.esphome/issues/49)",
69
- "de": "Protokollierung verbessert, löst [# 48] (https://github.com/DrozmotiX/ioBroker.esphome/issues/48)\nName der Staaten geändert, löst [# 49] (https://github.com/DrozmotiX/ioBroker.esphome/issues/49)",
70
- "ru": "Ведение журнала улучшено, решает [# 48] (https://github.com/DrozmotiX/ioBroker.esphome/issues/48)\nНазвание состояний изменено, решает [# 49] (https://github.com/DrozmotiX/ioBroker.esphome/issues/49)",
71
- "pt": "Logging melhorado, resolve [# 48] (https://github.com/DrozmotiX/ioBroker.esphome/issues/48)\nNome dos estados alterados, resolve [# 49] (https://github.com/DrozmotiX/ioBroker.esphome/issues/49)",
72
- "nl": "Logboekregistratie verbeterd, lost op [# 48] (https://github.com/DrozmotiX/ioBroker.esphome/issues/48)\nNaam van staten gewijzigd, lost [# 49] op (https://github.com/DrozmotiX/ioBroker.esphome/issues/49)",
73
- "fr": "Journalisation améliorée, résout [# 48] (https://github.com/DrozmotiX/ioBroker.esphome/issues/48)\nLe nom des états a changé, résout [# 49] (https://github.com/DrozmotiX/ioBroker.esphome/issues/49)",
74
- "it": "Registrazione migliorata, risolve [# 48] (https://github.com/DrozmotiX/ioBroker.esphome/issues/48)\nIl nome degli stati è cambiato, risolve [# 49] (https://github.com/DrozmotiX/ioBroker.esphome/issues/49)",
75
- "es": "Registro mejorado, resuelve [# 48] (https://github.com/DrozmotiX/ioBroker.esphome/issues/48)\nNombre de los estados cambiado, resuelve [# 49] (https://github.com/DrozmotiX/ioBroker.esphome/issues/49)",
76
- "pl": "Logowanie poprawione, rozwiązuje [# 48] (https://github.com/DrozmotiX/ioBroker.esphome/issues/48)\nZmiana nazwy stanów, rozwiązuje [# 49] (https://github.com/DrozmotiX/ioBroker.esphome/issues/49)",
77
- "zh-cn": "日志记录得到改进,解决了[#48](https://github.com/DrozmotiX/ioBroker.esphome/issues/48)\n状态名称更改,解决[#49](https://github.com/DrozmotiX/ioBroker.esphome/issues/49)"
78
- },
79
- "0.2.0": {
80
- "en": "Translations updated\nConfiguration page updated\nAdded to sentry error reporting\nNative integration of ESPHome Dashboard added",
81
- "de": "Übersetzungen aktualisiert\nKonfigurationsseite aktualisiert\nZur Sentry-Fehlerberichterstattung hinzugefügt\nNative Integration von ESPHome Dashboard hinzugefügt",
82
- "ru": "Переводы обновлены\nСтраница конфигурации обновлена\nДобавлен в отчет об ошибках караула\nДобавлена встроенная интеграция ESPHome Dashboard.",
83
- "pt": "Traduções atualizadas\nPágina de configuração atualizada\nAdicionado ao relatório de erro de sentinela\nIntegração nativa do ESPHome Dashboard adicionada",
84
- "nl": "Vertalingen bijgewerkt\nConfiguratiepagina bijgewerkt\nToegevoegd aan sentry-foutrapportage\nNative integratie van ESPHome Dashboard toegevoegd",
85
- "fr": "Traductions mises à jour\nPage de configuration mise à jour\nAjouté au rapport d'erreurs de sentinelle\nAjout de l'intégration native du tableau de bord ESPHome",
86
- "it": "Traduzioni aggiornate\nPagina di configurazione aggiornata\nAggiunto alla segnalazione degli errori di sentinella\nAggiunta integrazione nativa di ESPHome Dashboard",
87
- "es": "Traducciones actualizadas\nPágina de configuración actualizada\nAgregado al informe de errores de centinela\nSe agregó la integración nativa de ESPHome Dashboard",
88
- "pl": "Zaktualizowano tłumaczenia\nStrona konfiguracji została zaktualizowana\nDodano do raportowania błędów wartowników\nDodano natywną integrację z ESPHome Dashboard",
89
- "zh-cn": "翻译已更新\n配置页面已更新\n已添加到哨兵错误报告中\nESPHome仪表板的本机集成已添加"
90
92
  }
91
93
  },
92
94
  "title": "Control ESPHome managed devices",
package/main.js CHANGED
@@ -50,6 +50,9 @@ class Esphome extends utils.Adapter {
50
50
  reconnectInterval = this.config.reconnectInterval * 1000;
51
51
  createConfigStates = this.config.configStates;
52
52
 
53
+ // Ensure all online states are set to false during adapter start
54
+ await this.resetOnlineStates();
55
+
53
56
  // Try connecting to already known devices
54
57
  await this.tryKnownDevices();
55
58
 
@@ -68,7 +71,7 @@ class Esphome extends utils.Adapter {
68
71
  }
69
72
 
70
73
  } catch (e) {
71
- this.log.error(`Connection issue ${e}`);
74
+ this.log.error(`[Adapter start] Fatal error occurred ${e}`);
72
75
  }
73
76
  }
74
77
 
@@ -116,7 +119,7 @@ class Esphome extends utils.Adapter {
116
119
  this.log.debug(`[ESPHome - Console] ${data}`);
117
120
  }
118
121
  } else {
119
- this.log.error(`[dashboardProcess ERROR] ${data}`);
122
+ console.debug(`[espHomeDashboard] Unknown logging data : ${JSON.stringify(data)}`);
120
123
  }
121
124
  });
122
125
 
@@ -151,11 +154,7 @@ class Esphome extends utils.Adapter {
151
154
 
152
155
  // Get basic data of known devices and start reading data
153
156
  for (const i in knownDevices) {
154
- this.deviceInfo[knownDevices[i].native.ip] = {
155
- ip: knownDevices[i].native.ip,
156
- passWord: this.decrypt(knownDevices[i].native.passWord),
157
- };
158
- this.connectDevices(knownDevices[i].native.ip, this.deviceInfo[knownDevices[i].native.ip].passWord);
157
+ this.connectDevices(knownDevices[i].native.ip, this.decrypt(knownDevices[i].native.passWord));
159
158
  }
160
159
  } catch (e) {
161
160
  this.sendSentry(`[tryKnownDevices] ${e}`);
@@ -173,12 +172,7 @@ class Esphome extends utils.Adapter {
173
172
  try {
174
173
  this.log.debug(`Discovery message ${JSON.stringify(message)}`);
175
174
  if (this.deviceInfo[message.address] == null) {
176
- this.log.info(`[AutoDiscovery] New ESPHome device found at IP ${message.address}`);
177
- // Store new Device information to device array in memory
178
- this.deviceInfo[message.address] = {
179
- ip: message.address,
180
- passWord: apiPass
181
- };
175
+ this.log.info(`[AutoDiscovery] New ESPHome device found at IP ${message.address}, trying to initialize`);
182
176
  this.connectDevices(`${message.address}`, `${apiPass}`);
183
177
  }
184
178
  } catch (e) {
@@ -203,7 +197,7 @@ class Esphome extends utils.Adapter {
203
197
  // Prepare connection attributes
204
198
  client[host] = new Client({
205
199
  host: host,
206
- password: pass,
200
+ password: apiPass,
207
201
  clientInfo: `${this.host}`,
208
202
  clearSession: true,
209
203
  initializeDeviceInfo: true,
@@ -220,6 +214,16 @@ class Esphome extends utils.Adapter {
220
214
  // Connection listener
221
215
  client[host].on('connected', async () => {
222
216
  try {
217
+ // Clear any existing memory information for this device
218
+ delete this.deviceInfo[host];
219
+
220
+ // Reserve basic memory information for this device
221
+ this.deviceInfo[host] = {
222
+ connected : true,
223
+ connectionError : false,
224
+ initialized: false,
225
+ ip : host
226
+ };
223
227
  this.log.info(`ESPHome client ${host} connected`);
224
228
  // Clear possible present warn messages for device from previous connection
225
229
  delete warnMessages[host];
@@ -228,13 +232,31 @@ class Esphome extends utils.Adapter {
228
232
  }
229
233
  });
230
234
 
231
- client[host].on('disconnected', () => {
235
+ client[host].on('disconnected', () => {
232
236
  try {
233
237
  if (this.deviceInfo[host].deviceName != null) {
234
238
  this.setState(`${this.deviceInfo[host].deviceName}.info._online`, {val: false, ack: true});
235
- this.log.warn(`ESPHome client ${this.deviceInfo[host].deviceInfo.name} disconnected`);
239
+
240
+ // Cache relevant data before clearing memory space of device
241
+ const cacheDeviceInformation = {
242
+ deviceName: this.deviceInfo[host].deviceName,
243
+ deviceInfoName: this.deviceInfo[host].deviceInfoName,
244
+ };
245
+
246
+ // Clear any existing memory information for this device
247
+ delete this.deviceInfo[host];
248
+
249
+ // Reserve basic memory information for this device
250
+ this.deviceInfo[host] = {
251
+ connected : false,
252
+ connectionError : true,
253
+ deviceName : cacheDeviceInformation.deviceName,
254
+ deviceInfoName : cacheDeviceInformation.deviceInfoName,
255
+ ip : host
256
+ };
257
+ this.log.warn(`ESPHome client ${this.deviceInfo[host].deviceInfoName} | ${this.deviceInfo[host].deviceName} | on ${host} disconnected`);
236
258
  } else {
237
- this.log.warn(`ESPHome client ${host} disconnected`);
259
+ this.log.warn(`ESPHome client ${host} disconnected`);
238
260
  }
239
261
  } catch (e) {
240
262
  this.log.debug(`ESPHome disconnect error : ${e}`);
@@ -242,20 +264,17 @@ class Esphome extends utils.Adapter {
242
264
  });
243
265
 
244
266
  client[host].on('initialized', () => {
245
- this.log.info(`ESPHome client ${this.deviceInfo[host].deviceInfo.name} on ip ${host} initialized`);
246
- });
247
-
248
- client[host].on('logs', (/** @type {object} */ messageObj) => {
249
- this.log.debug(`ESPHome client log : ${JSON.stringify(messageObj)}`);
267
+ this.log.info(`ESPHome client ${this.deviceInfo[host].deviceInfoName} on ip ${host} initialized`);
268
+ this.deviceInfo[host].initialized = true;
250
269
  });
251
270
 
252
271
  // Log message listener
253
272
  client[host].connection.on('message', (/** @type {object} */ message) => {
254
- this.log.debug(`${host} client log ${message}`);
273
+ this.log.debug(`[ESPHome Device Message] ${host} client log ${message}`);
255
274
  });
256
275
 
257
276
  client[host].connection.on('data', (/** @type {object} */ data) => {
258
- this.log.debug(`${host} client data ${data}`);
277
+ this.log.debug(`[ESPHome Device Data] ${host} client data ${data}`);
259
278
  });
260
279
 
261
280
  // Handle device information when connected or information updated
@@ -272,10 +291,11 @@ class Esphome extends utils.Adapter {
272
291
  deviceInfo: deviceInfo,
273
292
  deviceName: deviceName,
274
293
  deviceInfoName: deviceInfo.name,
275
- passWord: pass,
294
+ passWord: apiPass,
276
295
  };
277
296
 
278
- // Store MAC & IP relation
297
+ // Store MAC & IP relation, delete possible existing entry before
298
+ delete this.deviceStateRelation[deviceName];
279
299
  this.deviceStateRelation[deviceName] = {'ip': host};
280
300
 
281
301
  this.log.debug(`DeviceInfo ${this.deviceInfo[host].deviceInfo.name}: ${JSON.stringify(this.deviceInfo)}`);
@@ -285,13 +305,16 @@ class Esphome extends utils.Adapter {
285
305
  type: 'device',
286
306
  common: {
287
307
  name: deviceInfo.name,
308
+ statusStates: {
309
+ onlineId: `${this.namespace}.${deviceName}.info._online`
310
+ }
288
311
  },
289
312
  native: {
290
313
  ip: host,
291
314
  name: this.deviceInfo[host].deviceInfoName,
292
315
  mac: deviceInfo.macAddress,
293
316
  deviceName: deviceName,
294
- passWord: this.encrypt(pass),
317
+ passWord: this.encrypt(apiPass),
295
318
  },
296
319
  });
297
320
 
@@ -384,7 +407,7 @@ class Esphome extends utils.Adapter {
384
407
  await client[host].connection.subscribeStatesService();
385
408
  this.log.debug(`[DeviceInfoData] ${this.deviceInfo[host].deviceInfo.name} ${JSON.stringify(this.deviceInfo[host])}`);
386
409
 
387
- // Listen to state changes an write values to states (create state if not yet exists)
410
+ // Listen to state changes and write values to states (create state if not yet exists)
388
411
  entity.on(`state`, async (/** @type {object} */ state) => {
389
412
  this.log.debug(`StateData: ${JSON.stringify(state)}`);
390
413
  try {
@@ -477,23 +500,46 @@ class Esphome extends utils.Adapter {
477
500
  // Connection data handler
478
501
  client[host].on('error', (error) => {
479
502
  try {
503
+
504
+ // Reserve memory space for connection error if not already exist
505
+ if (!this.deviceInfo[host]){
506
+ this.deviceInfo[host] = {
507
+ ip : host,
508
+ connectError : false,
509
+ connected : false
510
+ };
511
+ }
512
+
480
513
  let optimisedError = error.message;
481
514
  // Optimise error messages
482
- if (error.message.includes('EHOSTUNREACH')) {
483
- optimisedError = `Client ${this.deviceInfo[host].ip} not reachable !`;
484
- if (!warnMessages[host].connectError) {
515
+ if (error.code === 'ETIMEDOUT') {
516
+ optimisedError = `Client ${host} not reachable !`;
517
+ if (!this.deviceInfo[host].connectError) {
485
518
  this.log.error(optimisedError);
486
- warnMessages[host].connectError = true;
519
+ this.deviceInfo[host].connectError = true;
487
520
  }
488
521
  } else if (error.message.includes('Invalid password')) {
489
522
  optimisedError = `Client ${host} incorrect password !`;
490
- this.log.error(optimisedError);
523
+ if (!this.deviceInfo[host].connectError) {
524
+ this.log.error(optimisedError);
525
+ this.deviceInfo[host].connectError = true;
526
+ }
491
527
  } else if (error.message.includes('ECONNRESET')) {
492
- optimisedError = `Client ${this.deviceInfo[host].ip} Connection Lost, will reconnect automatically when device is available!`;
493
- this.log.warn(optimisedError);
528
+ optimisedError = `Client ${host} Connection Lost, will reconnect automatically when device is available!`;
529
+ if (!this.deviceInfo[host].connectError) {
530
+ this.log.warn(optimisedError);
531
+ this.deviceInfo[host].connectError = true;
532
+ }
494
533
  } else if (error.message.includes('timeout')) {
495
- optimisedError = `Client ${host} Timeout, connection Lost, will reconnect automatically when device is available!`;
534
+ optimisedError = `Client ${host} Timeout, will reconnect automatically when device is available!`;
535
+ if (!this.deviceInfo[host].connectError) {
536
+ this.log.warn(optimisedError);
537
+ this.deviceInfo[host].connectError = true;
538
+ }
539
+ } else if (error.message.includes('ECONNREFUSED')) {
540
+ optimisedError = `Client ${host} not yet ready to connect, will try again!`;
496
541
  this.log.warn(optimisedError);
542
+
497
543
  } else if (error.message.includes('write after end')) {
498
544
  // Ignore error
499
545
  } else {
@@ -521,10 +567,6 @@ class Esphome extends utils.Adapter {
521
567
  // connect to socket
522
568
  try {
523
569
  this.log.debug(`trying to connect to ${host}`);
524
- // Reserve memory for warn messages
525
- warnMessages[host] = {
526
- connectError: false
527
- };
528
570
  client[host].connect();
529
571
  } catch (e) {
530
572
  this.log.error(`Client ${host} connect error ${e}`);
@@ -907,6 +949,13 @@ class Esphome extends utils.Adapter {
907
949
  try {
908
950
  this.log.debug(JSON.stringify(this.deviceInfo));
909
951
  for (const device in this.deviceInfo) {
952
+
953
+ // Ensure all known online states are set to false
954
+ if (this.deviceInfo[device].mac != null) {
955
+ const deviceName = this.replaceAll(this.deviceInfo[device].mac, `:`, ``);
956
+ this.setState(`${deviceName}.info._online`, {val: false, ack: true});
957
+ }
958
+
910
959
  try {
911
960
  client[device].disconnect();
912
961
  } catch (e) {
@@ -979,8 +1028,8 @@ class Esphome extends utils.Adapter {
979
1028
  } else {
980
1029
  this.log.info(`Valid IP address received`);
981
1030
  this.messageResponse[obj.message['device-ip']] = obj;
982
- const pass = this.decrypt(obj.message['device-pass']);
983
- await this.connectDevices(obj.message['device-ip'], pass);
1031
+ // const pass = this.decrypt(obj.message['device-pass']);
1032
+ await this.connectDevices(obj.message['device-ip'], apiPass);
984
1033
  }
985
1034
  break;
986
1035
  }
@@ -1113,18 +1162,18 @@ class Esphome extends utils.Adapter {
1113
1162
  state: this.deviceInfo[deviceIP][device[4]].states.state,
1114
1163
  transitionLength: this.deviceInfo[deviceIP][device[4]].states.transitionLength
1115
1164
  };
1116
- if (this.deviceInfo[deviceIP][device[4]].config.supportsBrightness === true) {
1165
+ if (this.deviceInfo[deviceIP][device[4]].config.legacySupportsBrightness === true) {
1117
1166
  data.brightness = this.deviceInfo[deviceIP][device[4]].states.brightness;
1118
1167
  }
1119
- if (this.deviceInfo[deviceIP][device[4]].config.supportsRgb === true) {
1168
+ if (this.deviceInfo[deviceIP][device[4]].config.legacySupportsRgb === true) {
1120
1169
  data.red = this.deviceInfo[deviceIP][device[4]].states.red;
1121
1170
  data.green = this.deviceInfo[deviceIP][device[4]].states.green;
1122
1171
  data.blue = this.deviceInfo[deviceIP][device[4]].states.blue;
1123
1172
  }
1124
- if (this.deviceInfo[deviceIP][device[4]].config.supportsWhiteValue === true) {
1173
+ if (this.deviceInfo[deviceIP][device[4]].config.legacySupportsWhiteValue === true) {
1125
1174
  data.white = this.deviceInfo[deviceIP][device[4]].states.white;
1126
1175
  }
1127
- if (this.deviceInfo[deviceIP][device[4]].config.supportsColorTemperature === true) {
1176
+ if (this.deviceInfo[deviceIP][device[4]].config.legacySupportsColorTemperature === true) {
1128
1177
  data.colorTemperature = this.deviceInfo[deviceIP][device[4]].states.colorTemperature;
1129
1178
  }
1130
1179
  const effect = this.deviceInfo[deviceIP][device[4]].states.effect;
@@ -1153,6 +1202,37 @@ class Esphome extends utils.Adapter {
1153
1202
  }
1154
1203
  }
1155
1204
  }
1205
+
1206
+ async resetOnlineStates(){
1207
+ try {
1208
+ // Set parameters for object view to only include objects within adapter namespace
1209
+ const params = {
1210
+ startkey : `${this.namespace}.`,
1211
+ endkey : `${this.namespace}.\u9999`,
1212
+ };
1213
+
1214
+ // Get all current devices in adapter tree
1215
+ const _devices = await this.getObjectViewAsync('system', 'device', params);
1216
+ // List all found devices & set online state to false
1217
+ for (const currDevice in _devices.rows) {
1218
+
1219
+ // Extend online state to device (to ensure migration of version < 0.3.1
1220
+ await this.extendObjectAsync(_devices.rows[currDevice].id, {
1221
+ common: {
1222
+ statusStates: {
1223
+ onlineId: `${_devices.rows[currDevice].id}.info._online`
1224
+ }
1225
+ },
1226
+ });
1227
+
1228
+ // Set online state to false, will be set to true at successfully connected
1229
+ this.setState(`${_devices.rows[currDevice].id}.info._online`, {val: false, ack: true});
1230
+ }
1231
+
1232
+ } catch (e) {
1233
+ this.log.error(`[resetOnlineState] ${e}`);
1234
+ }
1235
+ }
1156
1236
  }
1157
1237
 
1158
1238
  if (require.main !== module) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.esphome",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Control your ESP8266/ESP32 with simple yet powerful configuration files created and managed by ESPHome",
5
5
  "author": {
6
6
  "name": "DutchmanNL",
@@ -28,6 +28,8 @@
28
28
  "@alcalzone/release-script-plugin-iobroker": "^3.6.0",
29
29
  "@alcalzone/release-script-plugin-license": "^3.5.9",
30
30
  "@alcalzone/release-script-plugin-manual-review": "^3.5.9",
31
+ "@iobroker/adapter-dev": "^1.2.0",
32
+ "@iobroker/dev-server": "^0.6.0",
31
33
  "@iobroker/testing": "^4.1.0",
32
34
  "@types/chai": "^4.3.6",
33
35
  "@types/chai-as-promised": "^7.1.6",
@@ -52,6 +54,7 @@
52
54
  "main": "main.js",
53
55
  "scripts": {
54
56
  "release": "release-script",
57
+ "dev-server": "dev-server",
55
58
  "test:js": "mocha --config test/mocharc.custom.json \"{!(node_modules|test)/**/*.test.js,*.test.js,test/**/test!(PackageFiles|Startup).js}\"",
56
59
  "test:package": "mocha test/package --exit",
57
60
  "test:unit": "mocha test/unit --exit",