Skip to content

Commit

Permalink
make creation of "config" folder and states optional
Browse files Browse the repository at this point in the history
  • Loading branch information
DutchmanNL committed Aug 24, 2021
1 parent 1646702 commit 81d8727
Show file tree
Hide file tree
Showing 17 changed files with 173 additions and 95 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ If you like my work, please consider a personal donation
* (DutchmanNL)
-->

### __WORK IN PROGRESS__
* (DutchmanNL) Add option if config of ESPHome device should be shown as states (default = FALSE, safes 8 states for each sensor)

### 0.2.3 (2021-06-29)
* (Jey-Cee) Bugfix : Light component state not changed [#74](https://github.com/DrozmotiX/ioBroker.esphome/issues/74)
* (DutchmanNL) Update compatibility to version 1.19.4 of ESPHome Dashboard
Expand Down
3 changes: 2 additions & 1 deletion admin/i18n/de/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"IP": "IP",
"IP-Address": "IP Adresse",
"Name": "Name",
"Show configuration as states": "Konfiguration als Zustände anzeigen",
"device-pass": "Passwort",
"reconnect interval": "Intervall für erneutes Verbinden"
}
}
3 changes: 2 additions & 1 deletion admin/i18n/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"IP": "IP",
"IP-Address": "IP-Address",
"Name": "Name",
"Show configuration as states": "Show configuration as states",
"device-pass": "Password",
"reconnect interval": "Reconnect Interval"
}
}
1 change: 1 addition & 0 deletions admin/i18n/es/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"IP": "IP",
"IP-Address": "Dirección IP",
"Name": "Nombre",
"Show configuration as states": "Mostrar configuración como estados",
"device-pass": "Contraseña",
"reconnect interval": "intervalo de reconexión"
}
1 change: 1 addition & 0 deletions admin/i18n/fr/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"IP": "IP",
"IP-Address": "Adresse IP",
"Name": "Nom",
"Show configuration as states": "Afficher la configuration sous forme d'états",
"device-pass": "Mot de passe",
"reconnect interval": "intervalle de reconnexion"
}
1 change: 1 addition & 0 deletions admin/i18n/it/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"IP": "IP",
"IP-Address": "Indirizzo IP",
"Name": "Nome",
"Show configuration as states": "Mostra configurazione come stati",
"device-pass": "Parola d'ordine",
"reconnect interval": "ricollegare l'intervallo"
}
3 changes: 2 additions & 1 deletion admin/i18n/nl/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"IP": "IP",
"IP-Address": "IP adres",
"Name": "Naam",
"Show configuration as states": "Configuratie weergeven als toestanden",
"device-pass": "Wachtwoord",
"reconnect interval": "interval voor opnieuw verbinden"
}
}
1 change: 1 addition & 0 deletions admin/i18n/pl/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"IP": "IP",
"IP-Address": "Adres IP",
"Name": "Nazwa",
"Show configuration as states": "Pokaż konfigurację jako stany",
"device-pass": "Hasło",
"reconnect interval": "interwał ponownego łączenia"
}
1 change: 1 addition & 0 deletions admin/i18n/pt/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"IP": "IP",
"IP-Address": "Endereço de IP",
"Name": "Nome",
"Show configuration as states": "Mostrar configuração como estados",
"device-pass": "Senha",
"reconnect interval": "intervalo de reconexão"
}
3 changes: 2 additions & 1 deletion admin/i18n/ru/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"IP": "IP",
"IP-Address": "IP адрес",
"Name": "Имя",
"Show configuration as states": "Показать конфигурацию как состояния",
"device-pass": "Пароль",
"reconnect interval": "Интервал повторного соединения"
}
}
1 change: 1 addition & 0 deletions admin/i18n/zh-cn/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"IP": "知识产权",
"IP-Address": "IP地址",
"Name": "姓名",
"Show configuration as states": "将配置显示为状态",
"device-pass": "密码",
"reconnect interval": "重新连接间隔"
}
4 changes: 4 additions & 0 deletions admin/index_m.html
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ <h5 class="center ${data.type}">${data.type}</h5>
<span class="translate">Automatic device detection activated</span>
</div>
<!-- end Auto Discovery -->
<div class="col s4 input-field">
<label for="autodiscovery"></label><input type="checkbox" class="value" id="configStates" checked/>
<span class="translate">Show configuration as states</span>
</div>
</div>

<!-- <p class="translate title">Devices</p>-->
Expand Down
1 change: 1 addition & 0 deletions admin/words.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions io-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
"reconnectInterval": 30,
"apiPass": "",
"autodiscovery": true,
"configStates": false,
"ESPHomeDashboardEnabled": true,
"ESPHomeDashboardPort": 6052,
"ESPHomeDashboardIP": "localhost"
Expand Down
37 changes: 25 additions & 12 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const stateAttr = require(__dirname + '/lib/stateAttr.js'); // Load attribute li
const disableSentry = false; // Ensure to set to true during development!
const warnMessages = {}; // Store warn messages to avoid multiple sending to sentry
const client = {};
let reconnectTimer, reconnectInterval, apiPass, autodiscovery, dashboardProcess;
let reconnectTimer, reconnectInterval, apiPass, autodiscovery, dashboardProcess, createConfigStates;

// const exec = require('child_process').exec;
const { fork, spawn } = require('child_process');
Expand Down Expand Up @@ -51,6 +51,7 @@ class Esphome extends utils.Adapter {
apiPass = this.config.apiPass;
autodiscovery = this.config.autodiscovery;
reconnectInterval = this.config.reconnectInterval * 1000;
createConfigStates = this.config.configStates;

// Try connecting to already knwon devices
await this.tryKnownDevices();
Expand Down Expand Up @@ -337,17 +338,29 @@ class Esphome extends utils.Adapter {
native: {},
});

// Create config channel
await this.extendObjectAsync(`${this.deviceInfo[host].deviceName}.${entity.type}.${entity.id}.config`, {
type: 'channel',
common: {
name: 'Configuration data'
},
native: {},
});

// Handle Entity JSON structure and write related config channel data
await this.TraverseJson(entity.config, `${this.deviceInfo[host].deviceName}.${entity.type}.${entity.id}.config`);
//Check if config channel should be created
if (!createConfigStates){
// Delete folder structure if already present
try {
const obj = await this.getObjectAsync(`${this.deviceInfo[host].deviceName}.${entity.type}.${entity.id}.config`);
if (obj) {
await this.delObjectAsync(`${this.deviceInfo[host].deviceName}.${entity.type}.${entity.id}.config`, {recursive: true});
}
} catch (error) {
// do nothing
}
} else {
// Create config channel
await this.extendObjectAsync(`${this.deviceInfo[host].deviceName}.${entity.type}.${entity.id}.config`, {
type: 'channel',
common: {
name: 'Configuration data'
},
native: {},
});
// Handle Entity JSON structure and write related config channel data
await this.TraverseJson(entity.config, `${this.deviceInfo[host].deviceName}.${entity.type}.${entity.id}.config`);
}

// Request current state values
await client[host].connection.subscribeStatesService();
Expand Down
Loading

0 comments on commit 81d8727

Please sign in to comment.