iobroker.shelly
Advanced tools
Comparing version 3.0.2 to 3.0.3
@@ -6,3 +6,8 @@ /*global systemDictionary:true */ | ||
"Auto": { "en": "Auto", "de": "Auto", "ru": "Автоматически", "pt": "Auto", "nl": "Auto", "fr": "Auto", "it": "Auto", "es": "Auto", "pl": "Auto", "zh-cn": "汽车"}, | ||
"Confirm Password": { "en": "Confim Password", "de": "Bestätige das Passwort", "ru": "Подтвердите Пароль", "pt": "Confirme a Senha", "nl": "bevestig wachtwoord", "fr": "Confirmez le mot de passe", "it": "conferma password", "es": "Confirmar contraseña", "pl": "Potwierdź hasło", "zh-cn": "Confim密码"}, | ||
"Confirm Password": { "en": "Confim Password", "de": "Passwort bestätigen", "ru": "Подтвердите Пароль", "pt": "Confirme a Senha", "nl": "bevestig wachtwoord", "fr": "Confirmez le mot de passe", "it": "conferma password", "es": "Confirmar contraseña", "pl": "Potwierdź hasło", "zh-cn": "Confim密码"}, | ||
"Http Password": { "en": "Http Password", "de": "HTTP-Passwort", "ru": "Пароль Http", "pt": "Senha Http", "nl": "Http Wachtwoord", "fr": "Mot de passe Http", "it": "Http Password", "es": "Contraseña http", "pl": "Hasło HTTP", "zh-cn": "Http密码"}, | ||
"Http Username": { "en": "Http Username", "de": "HTTP-Benutzername", "ru": "Http имя пользователя", "pt": "Nome de Usuário Http", "nl": "Http gebruikersnaam", "fr": "Nom d'utilisateur Http", "it": "Http Username", "es": "Nombre de usuario http", "pl": "Nazwa użytkownika HTTP", "zh-cn": "Http用户名"}, | ||
"MQTT Listen IP": { "en": "MQTT Listen IP", "de": "MQTT-Listen-IP", "ru": "MQTT Listen IP", "pt": "MQTT Listen IP", "nl": "MQTT Listen IP", "fr": "MQTT Listen IP", "it": "MQTT Ascolta IP", "es": "MQTT Listen IP", "pl": "MQTT Słuchaj IP", "zh-cn": "MQTT监听IP"}, | ||
"MQTT Password": { "en": "MQTT Password", "de": "MQTT-Passwort", "ru": "MQTT пароль", "pt": "Senha MQTT", "nl": "MQTT-wachtwoord", "fr": "Mot de passe MQTT", "it": "Password MQTT", "es": "Contraseña MQTT", "pl": "Hasło MQTT", "zh-cn": "MQTT密码"}, | ||
"MQTT Username": { "en": "MQTT Username", "de": "MQTT-Benutzername", "ru": "Имя пользователя MQTT", "pt": "Nome de Usuário MQTT", "nl": "MQTT-gebruikersnaam", "fr": "Nom d'utilisateur MQTT", "it": "Nome utente MQTT", "es": "Nombre de usuario de MQTT", "pl": "Nazwa użytkownika MQTT", "zh-cn": "MQTT用户名"}, | ||
"Manual": { "en": "Manual", "de": "Manual", "ru": "Вручную", "pt": "Manual", "nl": "Met de hand", "fr": "Manuel", "it": "Manuale", "es": "Manual", "pl": "Manual", "zh-cn": "手册"}, | ||
@@ -12,9 +17,5 @@ "Password": { "en": "Password", "de": "Passwort", "ru": "пароль", "pt": "Senha", "nl": "Wachtwoord", "fr": "Mot de passe", "it": "Parola d'ordine", "es": "Contraseña", "pl": "Hasło", "zh-cn": "密码"}, | ||
"User": { "en": "User", "de": "Benutzer", "ru": "пользователь", "pt": "Do utilizador", "nl": "Gebruiker", "fr": "Utilisateur", "it": "Utente", "es": "Usuario", "pl": "Użytkownik", "zh-cn": "用户"}, | ||
"Http Password": { "en": "Http Password", "de": "HTTP-Passwort", "ru": "Пароль Http", "pt": "Senha Http", "nl": "Http Wachtwoord", "fr": "Mot de passe Http", "it": "Http Password", "es": "Contraseña http", "pl": "Hasło HTTP", "zh-cn": "Http密码"}, | ||
"Http Username": { "en": "Http Username", "de": "HTTP-Benutzername", "ru": "Http имя пользователя", "pt": "Nome de Usuário Http", "nl": "Http gebruikersnaam", "fr": "Nom d'utilisateur Http", "it": "Http Username", "es": "Nombre de usuario http", "pl": "Nazwa użytkownika HTTP", "zh-cn": "Http用户名"}, | ||
"MQTT Username": { "en": "MQTT Username", "de": "MQTT-Benutzername", "ru": "Имя пользователя MQTT", "pt": "Nome de Usuário MQTT", "nl": "MQTT-gebruikersnaam", "fr": "Nom d'utilisateur MQTT", "it": "Nome utente MQTT", "es": "Nombre de usuario de MQTT", "pl": "Nazwa użytkownika MQTT", "zh-cn": "MQTT用户名"}, | ||
"MQTT Password": { "en": "MQTT Password", "de": "MQTT-Passwort", "ru": "MQTT пароль", "pt": "Senha MQTT", "nl": "MQTT-wachtwoord", "fr": "Mot de passe MQTT", "it": "Password MQTT", "es": "Contraseña MQTT", "pl": "Hasło MQTT", "zh-cn": "MQTT密码"}, | ||
"MQTT Listen IP": { "en": "MQTT Listen IP", "de": "MQTT-Listen-IP", "ru": "MQTT Listen IP", "pt": "MQTT Listen IP", "nl": "MQTT Listen IP", "fr": "MQTT Listen IP", "it": "MQTT Ascolta IP", "es": "MQTT Listen IP", "pl": "MQTT Słuchaj IP", "zh-cn": "MQTT监听IP"}, | ||
"on save adapter restarts with new config immediately": {"en": "on save adapter restarts with new config immediately", "de": "Beim Speichern von Einstellungen der Adapter wird sofort neu gestartet.", "ru": "При сохранении настроек адаптера он сразу же перезапускается", "pt": "no adaptador de salvar reinicia com nova configuração imediatamente", "nl": "on save-adapter wordt onmiddellijk opnieuw opgestart met nieuwe config", "fr": "sur l'adaptateur de sauvegarde redémarre avec la nouvelle config immédiatement", "it": "su save adapter si riavvia immediatamente con la nuova configurazione", "es": "en el adaptador de guardar se reinicia con nueva configuración de inmediato", "pl": "on save adapter restarts with new config immediately", "zh-cn": "在保存适配器重新启动与新的配置立即"}, | ||
"shellydescription": { "en": "Shelly devices must be in the same subnet as ioBroker for working with ioBroker. ioBroker finds Shelly devices by his own. If there are not recognized, please reboot Shelly devices once.", "de": "Shelly Device muss sich im gleichen Subnetz wie ioBroker befinden. Die Shelly Devices werden automatisch von ioBroker erkannt. Sollte das nicht der Fall sein, bitte Shelly Device rebooten.", "ru": "Шелли устройства должны быть в той же подсети, что ioBroker для работы с ioBroker. ioBroker находит устройства Шелли его собственного. Если не признаются, пожалуйста, перезагрузите устройств Шелли раз.", "pt": "Shelly dispositivos devem estar na mesma sub-rede como ioBroker para trabalhar com ioBroker. ioBroker encontrar Shelly dispositivos pelo seu próprio. Se lá não são reconhecidos, por favor, reinicie Shelly dispositivos de uma vez.", "nl": "Shelly apparaten moeten zich in hetzelfde subnet bevindt als ioBroker voor het werken met ioBroker. ioBroker vindt Shelly apparaten door zijn eigen. Als er niet wordt herkend, kunt u opnieuw opstarten Shelly apparaten ooit.", "fr": "Shelly, les appareils doivent être dans le même sous-réseau que ioBroker pour travailler avec ioBroker. ioBroker trouve Shelly appareils par son propre. Si il ne sont pas reconnu, s'il vous plaît redémarrer Shelly appareils une fois.", "it": "Shelly dispositivi devono essere nella stessa sottorete ioBroker per lavorare con ioBroker. ioBroker trova Shelly dispositivi dai suoi. Se ci non sono riconosciute, si prega di riavviare Shelly dispositivi di una volta.", "es": "Shelly los dispositivos deben estar en la misma subred que ioBroker para trabajar con ioBroker. ioBroker encuentra Shelly dispositivos por su cuenta. Si no se reconoce, por favor reinicie Shelly los dispositivos de una vez.", "pl": "Shelley urządzenia muszą być w tej samej podsieci, co ioBroker do pracy z ioBroker. ioBroker wyszukuje urządzenia Shelley jego własnego. Jeśli nie przyznają, proszę ponownie uruchomić urządzeń Shelley razy.", "zh-cn": "雪莉设备必须在同一网作为ioBroker工作ioBroker的。 ioBroker找到雪莉设备由他自己的。 如果没有认识到,请重新启动Shelly设备的一次。"}, | ||
"Auto update of new firmware": { "en": "Auto update of new firmware", "de": "Automatisches Update der neuen Firmware", "ru": "Автообновление новой прошивки", "pt": "Atualização automática de novo firmware", "nl": "Automatische update van nieuwe firmware", "fr": "Mise à jour automatique du nouveau firmware", "it": "Aggiornamento automatico del nuovo firmware", "es": "Actualización automática de nuevo firmware", "pl": "Automatyczna aktualizacja nowego oprogramowania układowego", "zh-cn": "自动更新新固件"}, | ||
"on save adapter restarts with new config immediately": {"en": "on save adapter restarts with new config immediately", "de": "Beim Speichern von Einstellungen wird der Adapter sofort neu gestartet.", "ru": "При сохранении настроек адаптера он сразу же перезапускается", "pt": "no adaptador de salvar reinicia com nova configuração imediatamente", "nl": "on save-adapter wordt onmiddellijk opnieuw opgestart met nieuwe config", "fr": "sur l'adaptateur de sauvegarde redémarre avec la nouvelle config immédiatement", "it": "su save adapter si riavvia immediatamente con la nuova configurazione", "es": "en el adaptador de guardar se reinicia con nueva configuración de inmediato", "pl": "on save adapter restarts with new config immediately", "zh-cn": "在保存适配器重新启动与新的配置立即"}, | ||
"shellydescription": { "en": "Shelly devices must be in the same subnet as ioBroker for working with ioBroker. ioBroker finds Shelly devices by his own. If there are not recognized, please reboot Shelly devices once.", "de": "Shelly Geräte müssen sich im gleichen Subnetz wie ioBroker befinden und werden automatisch von ioBroker erkannt. Sollte das nicht der Fall sein, bitte Shelly Gerät rebooten.", "ru": "Шелли устройства должны быть в той же подсети, что ioBroker для работы с ioBroker. ioBroker находит устройства Шелли его собственного. Если не признаются, пожалуйста, перезагрузите устройств Шелли раз.", "pt": "Shelly dispositivos devem estar na mesma sub-rede como ioBroker para trabalhar com ioBroker. ioBroker encontrar Shelly dispositivos pelo seu próprio. Se lá não são reconhecidos, por favor, reinicie Shelly dispositivos de uma vez.", "nl": "Shelly apparaten moeten zich in hetzelfde subnet bevindt als ioBroker voor het werken met ioBroker. ioBroker vindt Shelly apparaten door zijn eigen. Als er niet wordt herkend, kunt u opnieuw opstarten Shelly apparaten ooit.", "fr": "Shelly, les appareils doivent être dans le même sous-réseau que ioBroker pour travailler avec ioBroker. ioBroker trouve Shelly appareils par son propre. Si il ne sont pas reconnu, s'il vous plaît redémarrer Shelly appareils une fois.", "it": "Shelly dispositivi devono essere nella stessa sottorete ioBroker per lavorare con ioBroker. ioBroker trova Shelly dispositivi dai suoi. Se ci non sono riconosciute, si prega di riavviare Shelly dispositivi di una volta.", "es": "Shelly los dispositivos deben estar en la misma subred que ioBroker para trabajar con ioBroker. ioBroker encuentra Shelly dispositivos por su cuenta. Si no se reconoce, por favor reinicie Shelly los dispositivos de una vez.", "pl": "Shelley urządzenia muszą być w tej samej podsieci, co ioBroker do pracy z ioBroker. ioBroker wyszukuje urządzenia Shelley jego własnego. Jeśli nie przyznają, proszę ponownie uruchomić urządzeń Shelley razy.", "zh-cn": "雪莉设备必须在同一网作为ioBroker工作ioBroker的。 ioBroker找到雪莉设备由他自己的。 如果没有认识到,请重新启动Shelly设备的一次。"}, | ||
}; |
{ | ||
"common": { | ||
"name": "shelly", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"news": { | ||
"3.0.3": { | ||
"en": "MQTT QoS 1 and 2 support", | ||
"de": "MQTT QoS 1 und 2", | ||
"ru": "Поддержка MQTT QoS 1 и 2", | ||
"pt": "Suporte MQTT QoS 1 e 2", | ||
"nl": "MQTT QoS 1 en 2 ondersteuning", | ||
"fr": "Prise en charge de MQTT QoS 1 et 2", | ||
"it": "MQTT QoS 1 e 2 supporto", | ||
"es": "MQTT QoS 1 y 2 soporte", | ||
"pl": "Obsługa MQTT QoS 1 i 2", | ||
"zh-cn": "MQTT QoS 1和2支持" | ||
}, | ||
"3.0.2": { | ||
"en": "Bugfixing", | ||
"de": "Fehlerbehebung" | ||
"de": "Fehlerbehebung", | ||
"ru": "Исправление ошибок", | ||
"pt": "Corrigindo erro", | ||
"nl": "bugfixing", | ||
"fr": "Correction de bugs", | ||
"it": "bugfixing", | ||
"es": "Corrección de errores", | ||
"pl": "Naprawa błędów", | ||
"zh-cn": "Bugfixing" | ||
}, | ||
@@ -263,2 +283,3 @@ "3.0.1": { | ||
"protocol": "coap", | ||
"auto_update": false, | ||
"keys": [ | ||
@@ -265,0 +286,0 @@ { |
@@ -315,3 +315,3 @@ /* jshint -W097 */ | ||
body = await requestAsync(params); | ||
this.adapter.info.log('Create Object body : ' + body); | ||
// this.adapter.log.debug('Create Object body : ' + body); | ||
} catch (error) { | ||
@@ -359,2 +359,3 @@ if (body && body === '401 Unauthorized') { | ||
async createIoBrokerState(payload) { | ||
this.adapter.log.debug('CoAP Message for ' + this.getDeviceName() + ' : ' + JSON.stringify(payload)); | ||
let dps = this.getDevices(); | ||
@@ -366,8 +367,9 @@ for (let i in dps) { | ||
let value = payload; | ||
this.adapter.log.debug('createIoBrokerState(), State : ' + stateid + ', Payload: ' + JSON.stringify(payload)); | ||
this.adapter.log.debug('Create State : ' + stateid + ', Payload: ' + JSON.stringify(payload) + 'for ' + this.getDeviceName()); | ||
try { | ||
if (dp.coap && dp.coap.coap_publish_funct) { | ||
value = isAsync(dp.coap.coap_publish_funct) ? await dp.coap.coap_publish_funct(value, this) : dp.coap.coap_publish_funct(value, this); | ||
this.adapter.log.debug('createIoBrokerState(), State : ' + stateid + ', Value: ' + JSON.stringify(value)); | ||
// this.adapter.log.debug('createIoBrokerState(), State : ' + stateid + ', Value: ' + JSON.stringify(value)); | ||
if (value !== undefined && (!this.states.hasOwnProperty(stateid) || this.states[stateid] !== value)) { | ||
this.adapter.log.debug('State change : ' + stateid + ', Value: ' + JSON.stringify(value) + ' for ' + this.getName()); | ||
this.states[stateid] = value; | ||
@@ -408,3 +410,3 @@ this.objectHelper.setOrUpdateObject(stateid, { | ||
} | ||
this.adapter.log.debug('Call url ' + JSON.stringify(params) + ' for ' + this.getName()); | ||
// this.adapter.log.debug('Call url ' + JSON.stringify(params) + ' for ' + this.getName()); | ||
let body = await requestAsync(params); | ||
@@ -420,4 +422,5 @@ for (let j in states) { | ||
value = isAsync(state.coap.http_publish_funct) ? await state.coap.http_publish_funct(value, this) : state.coap.http_publish_funct(value, this); | ||
this.adapter.log.debug('httpIoBrokerState(), State : ' + stateid + ', Value: ' + JSON.stringify(value)); | ||
// this.adapter.log.debug('httpIoBrokerState(), State : ' + stateid + ', Value: ' + JSON.stringify(value)); | ||
if (value !== undefined && (!this.states.hasOwnProperty(stateid) || this.states[stateid] !== value)) { | ||
this.adapter.log.debug('Set state ' + stateid + ', Value: ' + JSON.stringify(value) + ' for ' + this.getName()); | ||
this.states[stateid] = value; | ||
@@ -453,2 +456,30 @@ this.objectHelper.setOrUpdateObject(stateid, { | ||
async firmwareUpdate(firmwareavailable) { | ||
if (firmwareavailable && this.adapter.config.auto_update) { | ||
let body; | ||
try { | ||
let params; | ||
if (this.auth) { | ||
params = { | ||
url: 'http://' + this.getIP() + '/ota', | ||
update: true, | ||
headers: { | ||
'Authorization': this.auth | ||
} | ||
}; | ||
} else { | ||
params = { | ||
url: 'http://' + this.getIP() + '/ota', | ||
update: true | ||
}; | ||
} | ||
this.adapter.log.debug('Call url ' + JSON.stringify(params) + ' for ' + this.getName()); | ||
body = await requestAsync(params); | ||
this.adapter.log.info('Executing Firmwareupdate for ' + this.getName()); | ||
} catch (error) { | ||
// | ||
} | ||
} | ||
} | ||
start(payload) { | ||
@@ -521,8 +552,5 @@ if (this.deviceExist()) { | ||
}); | ||
shelly.on('error', (err) => { | ||
this.adapter.log.info('Error handling Shelly data: ' + err); | ||
}); | ||
shelly.on('disconnect', () => { | ||
@@ -529,0 +557,0 @@ for (let i in this.clients) { |
@@ -9,2 +9,16 @@ /* jshint -W097 */ | ||
/** | ||
* get the value of the key | ||
* @param {integer} key - like 112 | ||
* @param {array} array - [[0,111,0],[0,112,1]] | ||
*/ | ||
function getCoapValue(key, array) { | ||
if (array) { | ||
for (let k in array) { | ||
if (array[k][1] === key) return array[k][2]; | ||
} | ||
} | ||
return undefined; | ||
} | ||
/** | ||
* Shelly 1 | ||
@@ -15,3 +29,4 @@ */ | ||
coap: { | ||
coap_publish_funct: (value) => { return value.G[0][2] === 1 ? true : false; }, | ||
// coap_publish_funct: (value) => { return value.G[0][2] === 1 ? true : false; }, | ||
coap_publish_funct: (value) => { return getCoapValue(112, value.G) == 1 ? true : false; }, | ||
http_cmd: '/relay/0', | ||
@@ -132,7 +147,11 @@ http_cmd_funct: (value) => { return value === true ? { turn: 'on' } : { turn: 'off' }; }, | ||
http_publish: '/status', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).update.has_update : undefined; } | ||
http_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).update.has_update); | ||
return value ? JSON.parse(value).update.has_update : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: (value) => { return value ? JSON.parse(value).new_fw : false; } | ||
mqtt_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).new_fw); | ||
return value ? JSON.parse(value).new_fw : false; } | ||
}, | ||
@@ -147,2 +166,19 @@ common: { | ||
}, | ||
'version': { | ||
coap: { | ||
http_publish: '/settings', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).fw : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: async (value) => { return value ? JSON.parse(value).fw_ver : undefined; } | ||
}, | ||
common: { | ||
'name': 'Firmware version', | ||
'type': 'string', | ||
'role': 'state', | ||
'read': true, | ||
'write': false | ||
} | ||
}, | ||
'hostname': { | ||
@@ -149,0 +185,0 @@ coap: { |
@@ -8,6 +8,22 @@ /* jshint -W097 */ | ||
/** | ||
* get the value of the key | ||
* @param {integer} key - like 112 | ||
* @param {array} array - [[0,111,0],[0,112,1]] | ||
*/ | ||
function getCoapValue(key, array) { | ||
if (array) { | ||
for (let k in array) { | ||
if (array[k][1] === key) return array[k][2]; | ||
} | ||
} | ||
return undefined; | ||
} | ||
let shelly1pm = { | ||
'Relay0.Switch': { | ||
coap: { | ||
coap_publish_funct: (value) => { return value.G[0][2] === 1 ? true : false; }, | ||
// coap_publish_funct: (value, self) => { return value.G[0][2] == 1 ? true : false; }, | ||
coap_publish_funct: (value) => { return getCoapValue(112, value.G) === 1 ? true : false; }, | ||
http_cmd: '/relay/0', | ||
@@ -185,7 +201,11 @@ http_cmd_funct: (value) => { return value === true ? { turn: 'on' } : { turn: 'off' }; }, | ||
http_publish: '/status', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).update.has_update : undefined; } | ||
http_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).update.has_update); | ||
return value ? JSON.parse(value).update.has_update : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: (value) => { return value ? JSON.parse(value).new_fw : false; } | ||
mqtt_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).new_fw); | ||
return value ? JSON.parse(value).new_fw : false; } | ||
}, | ||
@@ -200,2 +220,19 @@ common: { | ||
}, | ||
'version': { | ||
coap: { | ||
http_publish: '/settings', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).fw : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: async (value) => { return value ? JSON.parse(value).fw_ver : undefined; } | ||
}, | ||
common: { | ||
'name': 'Firmware version', | ||
'type': 'string', | ||
'role': 'state', | ||
'read': true, | ||
'write': false | ||
} | ||
}, | ||
'hostname': { | ||
@@ -202,0 +239,0 @@ coap: { |
@@ -343,7 +343,11 @@ | ||
http_publish: '/status', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).update.has_update : undefined; } | ||
http_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).update.has_update); | ||
return value ? JSON.parse(value).update.has_update : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: (value) => { return value ? JSON.parse(value).new_fw : false; } | ||
mqtt_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).new_fw); | ||
return value ? JSON.parse(value).new_fw : false; } | ||
}, | ||
@@ -358,2 +362,19 @@ common: { | ||
}, | ||
'version': { | ||
coap: { | ||
http_publish: '/settings', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).fw : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: async (value) => { return value ? JSON.parse(value).fw_ver : undefined; } | ||
}, | ||
common: { | ||
'name': 'Firmware version', | ||
'type': 'string', | ||
'role': 'state', | ||
'read': true, | ||
'write': false | ||
} | ||
}, | ||
'hostname': { | ||
@@ -360,0 +381,0 @@ coap: { |
@@ -378,7 +378,11 @@ /* jshint -W097 */ | ||
http_publish: '/status', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).update.has_update : undefined; } | ||
http_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).update.has_update); | ||
return value ? JSON.parse(value).update.has_update : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: (value) => { return value ? JSON.parse(value).new_fw : false; } | ||
mqtt_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).new_fw); | ||
return value ? JSON.parse(value).new_fw : false; } | ||
}, | ||
@@ -393,2 +397,19 @@ common: { | ||
}, | ||
'version': { | ||
coap: { | ||
http_publish: '/settings', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).fw : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: async (value) => { return value ? JSON.parse(value).fw_ver : undefined; } | ||
}, | ||
common: { | ||
'name': 'Firmware version', | ||
'type': 'string', | ||
'role': 'state', | ||
'read': true, | ||
'write': false | ||
} | ||
}, | ||
'hostname': { | ||
@@ -395,0 +416,0 @@ coap: { |
@@ -399,7 +399,11 @@ | ||
http_publish: '/status', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).update.has_update : undefined; } | ||
http_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).update.has_update); | ||
return value ? JSON.parse(value).update.has_update : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: (value) => { return value ? JSON.parse(value).new_fw : false; } | ||
mqtt_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).new_fw); | ||
return value ? JSON.parse(value).new_fw : false; } | ||
}, | ||
@@ -414,2 +418,19 @@ common: { | ||
}, | ||
'version': { | ||
coap: { | ||
http_publish: '/settings', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).fw : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: async (value) => { return value ? JSON.parse(value).fw_ver : undefined; } | ||
}, | ||
common: { | ||
'name': 'Firmware version', | ||
'type': 'string', | ||
'role': 'state', | ||
'read': true, | ||
'write': false | ||
} | ||
}, | ||
'hostname': { | ||
@@ -416,0 +437,0 @@ coap: { |
@@ -82,7 +82,11 @@ /* jshint -W097 */ | ||
http_publish: '/status', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).update.has_update : undefined; } | ||
http_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).update.has_update); | ||
return value ? JSON.parse(value).update.has_update : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: (value) => { return value ? JSON.parse(value).new_fw : false; } | ||
mqtt_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).new_fw); | ||
return value ? JSON.parse(value).new_fw : false; } | ||
}, | ||
@@ -97,2 +101,19 @@ common: { | ||
}, | ||
'version': { | ||
coap: { | ||
http_publish: '/settings', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).fw : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: async (value) => { return value ? JSON.parse(value).fw_ver : undefined; } | ||
}, | ||
common: { | ||
'name': 'Firmware version', | ||
'type': 'string', | ||
'role': 'state', | ||
'read': true, | ||
'write': false | ||
} | ||
}, | ||
'hostname': { | ||
@@ -99,0 +120,0 @@ coap: { |
@@ -132,7 +132,11 @@ /* jshint -W097 */ | ||
http_publish: '/status', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).update.has_update : undefined; } | ||
http_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).update.has_update); | ||
return value ? JSON.parse(value).update.has_update : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: (value) => { return value ? JSON.parse(value).new_fw : false; } | ||
mqtt_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).new_fw); | ||
return value ? JSON.parse(value).new_fw : false; } | ||
}, | ||
@@ -147,2 +151,19 @@ common: { | ||
}, | ||
'version': { | ||
coap: { | ||
http_publish: '/settings', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).fw : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: async (value) => { return value ? JSON.parse(value).fw_ver : undefined; } | ||
}, | ||
common: { | ||
'name': 'Firmware version', | ||
'type': 'string', | ||
'role': 'state', | ||
'read': true, | ||
'write': false | ||
} | ||
}, | ||
'hostname': { | ||
@@ -149,0 +170,0 @@ coap: { |
@@ -150,7 +150,11 @@ /* jshint -W097 */ | ||
http_publish: '/status', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).update.has_update : undefined; } | ||
http_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).update.has_update); | ||
return value ? JSON.parse(value).update.has_update : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: (value) => { return value ? JSON.parse(value).new_fw : false; } | ||
mqtt_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).new_fw); | ||
return value ? JSON.parse(value).new_fw : false; } | ||
}, | ||
@@ -165,2 +169,19 @@ common: { | ||
}, | ||
'version': { | ||
coap: { | ||
http_publish: '/settings', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).fw : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: async (value) => { return value ? JSON.parse(value).fw_ver : undefined; } | ||
}, | ||
common: { | ||
'name': 'Firmware version', | ||
'type': 'string', | ||
'role': 'state', | ||
'read': true, | ||
'write': false | ||
} | ||
}, | ||
'hostname': { | ||
@@ -167,0 +188,0 @@ coap: { |
@@ -529,7 +529,11 @@ /* jshint -W097 */ | ||
http_publish: '/status', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).update.has_update : undefined; } | ||
http_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).update.has_update); | ||
return value ? JSON.parse(value).update.has_update : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: (value) => { return value ? JSON.parse(value).new_fw : false; } | ||
mqtt_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).new_fw); | ||
return value ? JSON.parse(value).new_fw : false; } | ||
}, | ||
@@ -544,2 +548,19 @@ common: { | ||
}, | ||
'version': { | ||
coap: { | ||
http_publish: '/settings', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).fw : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: async (value) => { return value ? JSON.parse(value).fw_ver : undefined; } | ||
}, | ||
common: { | ||
'name': 'Firmware version', | ||
'type': 'string', | ||
'role': 'state', | ||
'read': true, | ||
'write': false | ||
} | ||
}, | ||
'hostname': { | ||
@@ -546,0 +567,0 @@ coap: { |
@@ -336,7 +336,11 @@ /* jshint -W097 */ | ||
http_publish: '/status', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).update.has_update : undefined; } | ||
http_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).update.has_update); | ||
return value ? JSON.parse(value).update.has_update : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: (value) => { return value ? JSON.parse(value).new_fw : false; } | ||
mqtt_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).new_fw); | ||
return value ? JSON.parse(value).new_fw : false; } | ||
}, | ||
@@ -351,2 +355,19 @@ common: { | ||
}, | ||
'version': { | ||
coap: { | ||
http_publish: '/settings', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).fw : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: async (value) => { return value ? JSON.parse(value).fw_ver : undefined; } | ||
}, | ||
common: { | ||
'name': 'Firmware version', | ||
'type': 'string', | ||
'role': 'state', | ||
'read': true, | ||
'write': false | ||
} | ||
}, | ||
'hostname': { | ||
@@ -353,0 +374,0 @@ coap: { |
@@ -128,7 +128,11 @@ /* jshint -W097 */ | ||
http_publish: '/status', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).update.has_update : undefined; } | ||
http_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).update.has_update); | ||
return value ? JSON.parse(value).update.has_update : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: (value) => { return value ? JSON.parse(value).new_fw : false; } | ||
mqtt_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).new_fw); | ||
return value ? JSON.parse(value).new_fw : false; } | ||
}, | ||
@@ -143,2 +147,19 @@ common: { | ||
}, | ||
'version': { | ||
coap: { | ||
http_publish: '/settings', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).fw : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: async (value) => { return value ? JSON.parse(value).fw_ver : undefined; } | ||
}, | ||
common: { | ||
'name': 'Firmware version', | ||
'type': 'string', | ||
'role': 'state', | ||
'read': true, | ||
'write': false | ||
} | ||
}, | ||
'hostname': { | ||
@@ -145,0 +166,0 @@ coap: { |
@@ -82,7 +82,11 @@ /* jshint -W097 */ | ||
http_publish: '/status', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).update.has_update : undefined; } | ||
http_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).update.has_update); | ||
return value ? JSON.parse(value).update.has_update : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: (value) => { return value ? JSON.parse(value).new_fw : false; } | ||
mqtt_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).new_fw); | ||
return value ? JSON.parse(value).new_fw : false; } | ||
}, | ||
@@ -97,2 +101,19 @@ common: { | ||
}, | ||
'version': { | ||
coap: { | ||
http_publish: '/settings', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).fw : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: async (value) => { return value ? JSON.parse(value).fw_ver : undefined; } | ||
}, | ||
common: { | ||
'name': 'Firmware version', | ||
'type': 'string', | ||
'role': 'state', | ||
'read': true, | ||
'write': false | ||
} | ||
}, | ||
'hostname': { | ||
@@ -99,0 +120,0 @@ coap: { |
@@ -9,2 +9,15 @@ /* jshint -W097 */ | ||
/** | ||
* get the value of the key | ||
* @param {integer} key - like 112 | ||
* @param {array} array - [[0,111,0],[0,112,1]] | ||
*/ | ||
function getCoapValue(key, array) { | ||
if (array) { | ||
for (let k in array) { | ||
if (array[k][1] === key) return array[k][2]; | ||
} | ||
} | ||
return undefined; | ||
} | ||
@@ -27,3 +40,4 @@ async function shuterDuration(self) { | ||
coap: { | ||
coap_publish_funct: (value) => { return value.G[0][2] === 1 ? true : false; }, | ||
// coap_publish_funct: (value) => { return value.G[0][2] === 1 ? true : false; }, | ||
coap_publish_funct: (value) => { return getCoapValue(112, value.G) == 1 ? true : false; }, | ||
http_cmd: '/relay/0', | ||
@@ -95,3 +109,4 @@ http_cmd_funct: (value) => { return value === true ? { turn: 'on' } : { turn: 'off' }; }, | ||
coap: { | ||
coap_publish_funct: (value) => { return (Math.round(value.G[2][2] * 2) / 2); } | ||
// coap_publish_funct: (value) => { return (Math.round(value.G[2][2] * 2) / 2); } | ||
coap_publish_funct: (value) => { return (Math.round(getCoapValue(111, value.G) * 2) / 2); } | ||
}, | ||
@@ -166,3 +181,4 @@ mqtt: { | ||
coap: { | ||
coap_publish_funct: (value) => { return value.G[1][2] === 1 ? true : false; }, | ||
// coap_publish_funct: (value) => { return value.G[1][2] === 1 ? true : false; }, | ||
coap_publish_funct: (value) => { return getCoapValue(122, value.G) == 1 ? true : false; }, | ||
http_cmd: '/relay/1', | ||
@@ -234,3 +250,4 @@ http_cmd_funct: (value) => { return value === true ? { turn: 'on' } : { turn: 'off' }; }, | ||
coap: { | ||
coap_publish_funct: (value) => { return (Math.round(value.G[2][2] * 2) / 2); } | ||
// coap_publish_funct: (value) => { return (Math.round(value.G[2][2] * 2) / 2); } | ||
coap_publish_funct: (value) => { return (Math.round(getCoapValue(111, value.G) * 2) / 2); } | ||
}, | ||
@@ -305,3 +322,4 @@ mqtt: { | ||
coap: { | ||
coap_publish_funct: (value) => { return value.G[0][2] === 1 ? 'open' : value.G[1][2] === 1 ? 'close' : 'stop'; }, | ||
// coap_publish_funct: (value) => { return value.G[0][2] === 1 ? 'open' : value.G[1][2] === 1 ? 'close' : 'stop'; }, // 112 u. 122 | ||
coap_publish_funct: (value) => { return getCoapValue(112, value.G) === 1 ? 'open' : getCoapValue(122, value.G) === 1 ? 'close' : 'stop'; }, | ||
http_cmd: '/roller/0', | ||
@@ -411,3 +429,4 @@ http_cmd_funct: (value) => { return { go: value }; }, | ||
coap: { | ||
coap_publish_funct: (value) => { return value.G[2][2] == -1 ? 101 : value.G[2][2]; }, | ||
// coap_publish_funct: (value) => { return value.G[2][2] == -1 ? 101 : value.G[2][2]; }, // 113 | ||
coap_publish_funct: (value) => { return getCoapValue(113, value.G) == -1 ? 101 : getCoapValue(113, value.G); }, | ||
http_cmd: '/roller/0', | ||
@@ -450,7 +469,11 @@ http_cmd_funct: (value) => { return { 'go': 'to_pos', 'roller_pos': value }; } | ||
http_publish: '/status', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).update.has_update : undefined; } | ||
http_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).update.has_update); | ||
return value ? JSON.parse(value).update.has_update : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: (value) => { return value ? JSON.parse(value).new_fw : false; } | ||
mqtt_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).new_fw); | ||
return value ? JSON.parse(value).new_fw : false; } | ||
}, | ||
@@ -465,2 +488,19 @@ common: { | ||
}, | ||
'version': { | ||
coap: { | ||
http_publish: '/settings', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).fw : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: async (value) => { return value ? JSON.parse(value).fw_ver : undefined; } | ||
}, | ||
common: { | ||
'name': 'Firmware version', | ||
'type': 'string', | ||
'role': 'state', | ||
'read': true, | ||
'write': false | ||
} | ||
}, | ||
'hostname': { | ||
@@ -467,0 +507,0 @@ coap: { |
@@ -9,2 +9,15 @@ /* jshint -W097 */ | ||
/** | ||
* get the value of the key | ||
* @param {integer} key - like 112 | ||
* @param {array} array - [[0,111,0],[0,112,1]] | ||
*/ | ||
function getCoapValue(key, array) { | ||
if (array) { | ||
for (let k in array) { | ||
if (array[k][1] === key) return array[k][2]; | ||
} | ||
} | ||
return undefined; | ||
} | ||
@@ -20,8 +33,7 @@ async function shuterDuration(self) { | ||
let shellyswitch25 = { | ||
'Relay0.Switch': { | ||
coap: { | ||
coap_publish_funct: (value) => { return value.G[0][2] === 1 ? true : false; }, | ||
// coap_publish_funct: (value) => { return value.G[0][2] === 1 ? true : false; }, | ||
coap_publish_funct: (value) => { return getCoapValue(112, value.G) == 1 ? true : false; }, | ||
http_cmd: '/relay/0', | ||
@@ -48,4 +60,4 @@ http_cmd_funct: (value) => { return value === true ? { turn: 'on' } : { turn: 'off' }; }, | ||
http_publish: '/settings', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).relays[0].auto_off : undefined; }, | ||
http_cmd: '/settings/relay/0', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).relays[0].auto_off : undefined; }, | ||
http_cmd_funct: (value) => { return { auto_off: value }; } | ||
@@ -55,4 +67,4 @@ }, | ||
http_publish: '/settings', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).relays[0].auto_off : undefined; }, | ||
http_cmd: '/settings/relay/0', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).relays[0].auto_off : undefined; }, | ||
http_cmd_funct: (value) => { return { auto_off: value }; } | ||
@@ -95,3 +107,4 @@ }, | ||
coap: { | ||
coap_publish_funct: (value) => { return (Math.round(value.G[2][2] * 2) / 2); } | ||
// coap_publish_funct: (value) => { return (Math.round(value.G[2][2] * 2) / 2); } | ||
coap_publish_funct: (value) => { return (Math.round(getCoapValue(111, value.G) * 2) / 2); } | ||
}, | ||
@@ -166,3 +179,4 @@ mqtt: { | ||
coap: { | ||
coap_publish_funct: (value) => { return value.G[1][2] === 1 ? true : false; }, | ||
// coap_publish_funct: (value) => { return value.G[1][2] === 1 ? true : false; }, | ||
coap_publish_funct: (value) => { return getCoapValue(122, value.G) == 1 ? true : false; }, | ||
http_cmd: '/relay/1', | ||
@@ -234,3 +248,4 @@ http_cmd_funct: (value) => { return value === true ? { turn: 'on' } : { turn: 'off' }; }, | ||
coap: { | ||
coap_publish_funct: (value) => { return (Math.round(value.G[3][2] * 2) / 2); } | ||
// coap_publish_funct: (value) => { return (Math.round(value.G[3][2] * 2) / 2); } | ||
coap_publish_funct: (value) => { return (Math.round(getCoapValue(121, value.G) * 2) / 2); } | ||
}, | ||
@@ -305,3 +320,4 @@ mqtt: { | ||
coap: { | ||
coap_publish_funct: (value) => { return value.G[0][2] === 1 ? 'open' : value.G[1][2] === 1 ? 'close' : 'stop'; }, | ||
// coap_publish_funct: (value) => { return value.G[0][2] === 1 ? 'open' : value.G[1][2] === 1 ? 'close' : 'stop'; }, | ||
coap_publish_funct: (value) => { return getCoapValue(112, value.G) === 1 ? 'open' : getCoapValue(122, value.G) === 1 ? 'close' : 'stop'; }, | ||
http_cmd: '/roller/0', | ||
@@ -390,3 +406,4 @@ http_cmd_funct: (value) => { return { go: value }; }, | ||
coap: { | ||
coap_publish_funct: (value) => { return value.G[2][2] == -1 ? 101 : value.G[2][2]; }, | ||
// coap_publish_funct: (value) => { return value.G[2][2] == -1 ? 101 : value.G[2][2]; }, | ||
coap_publish_funct: (value) => { return getCoapValue(113, value.G) == -1 ? 101 : getCoapValue(113, value.G); }, | ||
http_cmd: '/roller/0', | ||
@@ -447,7 +464,11 @@ http_cmd_funct: (value) => { return { 'go': 'to_pos', 'roller_pos': value }; } | ||
http_publish: '/status', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).update.has_update : undefined; } | ||
http_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).update.has_update); | ||
return value ? JSON.parse(value).update.has_update : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: (value) => { return value ? JSON.parse(value).new_fw : false; } | ||
mqtt_publish_funct: async (value, self) => { | ||
await self.firmwareUpdate(value && JSON.parse(value).new_fw); | ||
return value ? JSON.parse(value).new_fw : false; } | ||
}, | ||
@@ -462,2 +483,19 @@ common: { | ||
}, | ||
'version': { | ||
coap: { | ||
http_publish: '/settings', | ||
http_publish_funct: (value) => { return value ? JSON.parse(value).fw : undefined; } | ||
}, | ||
mqtt: { | ||
mqtt_publish: 'shellies/announce', | ||
mqtt_publish_funct: async (value) => { return value ? JSON.parse(value).fw_ver : undefined; } | ||
}, | ||
common: { | ||
'name': 'Firmware version', | ||
'type': 'string', | ||
'role': 'state', | ||
'read': true, | ||
'write': false | ||
} | ||
}, | ||
'hostname': { | ||
@@ -464,0 +502,0 @@ coap: { |
206
lib/mqtt.js
@@ -222,3 +222,4 @@ /* jshint -W097 */ | ||
clearTimeout(this.timerid); | ||
this.qos = []; | ||
clearInterval(this.resendid); | ||
this.qos = {}; | ||
this.messageId = 1; | ||
@@ -302,7 +303,73 @@ this.states = {}; | ||
qos = qos ? Number.parseInt(qos) : 0; | ||
this.adapter.log.debug('Send to ' + this.getName() + ' : ' + topic + ' = ' + state); | ||
this.client.publish({ topic: topic, payload: state, qos: qos, retain: retain, messageId: this.messageId++ }, cb); | ||
this.messageId &= 0xFFFFFFFF; | ||
this.messageId++; | ||
this.adapter.log.debug('Send state to ' + this.getName() + ' : ' + topic + ' = ' + state + ' (' + this.messageId + ')'); | ||
this.client.publish({ topic: topic, payload: state, qos: qos, retain: retain, messageId: this.messageId }, cb); | ||
// if qos > 0 recognize message | ||
if (qos > 0) { | ||
this.deleteResendState2ClientFromTopic(topic); | ||
this.resendState2Client('publish', this.messageId, { topic: topic, payload: state, qos: qos, dup: true, retain: retain, messageId: this.messageId }); | ||
} | ||
} | ||
resendState2Client(cmd, messageId, message) { | ||
let retaintime = 5 * 1000; | ||
if (!this.qos[messageId] || this.qos[messageId].cmd !== cmd || this.qos[messageId].message !== message) { | ||
this.qos[messageId] = { | ||
ts: Date.now(), | ||
cmd: cmd, | ||
count: 0, | ||
message: message | ||
}; | ||
} | ||
if (this.qos[messageId] && this.qos[messageId].count < 10) { | ||
clearTimeout(this.qos[messageId].resendid); | ||
this.qos[messageId].resendid = setTimeout(() => { | ||
if (this.qos[messageId]) { | ||
let ts = Date.now(); | ||
this.qos[messageId].count++; | ||
this.qos[messageId].ts = ts; | ||
switch (this.qos[messageId].cmd) { | ||
case 'publish': | ||
this.client.publish(this.qos[messageId].message); | ||
break; | ||
case 'pubrel': | ||
this.client.pubrel({ messageId: messageId }); | ||
break; | ||
case 'pubrec': | ||
this.client.pubrec({ messageId: messageId }); | ||
break; | ||
case 'pubcomp': | ||
this.client.pubcomp({ messageId: messageId }); | ||
break; | ||
default: | ||
break; | ||
} | ||
this.resendState2Client(cmd, messageId, message); | ||
} | ||
}, retaintime); | ||
} | ||
} | ||
deleteResendState2Client(messageId) { | ||
if (this.qos[messageId]) { | ||
clearTimeout(this.qos[messageId].resendid); | ||
delete this.qos[messageId]; | ||
} | ||
} | ||
deleteResendState2ClientFromTopic(topic) { | ||
for (let messageId in this.qos) { | ||
if (this.qos[messageId].message && this.qos[messageId].cmd === 'publish' && this.qos[messageId].message.topic === topic) { | ||
clearTimeout(this.qos[messageId].resendid); | ||
delete this.qos[messageId]; | ||
} | ||
} | ||
} | ||
getResendState2Client(messageId) { | ||
return this.qos[messageId]; | ||
} | ||
/** | ||
@@ -412,3 +479,3 @@ * delete old states in objects unter shelly.X. | ||
body = await requestAsync(params); | ||
this.adapter.info.log('Create Object body : ' + body); | ||
// this.adapter.log.debug('Create Object body : ' + body); | ||
} catch (error) { | ||
@@ -456,2 +523,3 @@ if (body && body === '401 Unauthorized') { | ||
async createIoBrokerState(topic, payload) { | ||
this.adapter.log.debug('MQTT Message for ' + this.getId() + ' : ' + topic + ' / ' + JSON.stringify(payload)); | ||
let dps = this.getDevices(topic); | ||
@@ -463,3 +531,3 @@ for (let i in dps) { | ||
let value = payload.toString(); | ||
this.adapter.log.debug('createIoBrokerState(), State : ' + stateid + ', Topic: ' + topic + ', Payload: ' + JSON.stringify(payload)); | ||
this.adapter.log.debug('Create State : ' + stateid + ', Payload: ' + JSON.stringify(payload) + 'for ' + this.getId()); | ||
try { | ||
@@ -469,4 +537,5 @@ if (dp.mqtt && dp.mqtt.mqtt_publish === topic) { | ||
value = isAsync(dp.mqtt.mqtt_publish_funct) ? await dp.mqtt.mqtt_publish_funct(value, this) : dp.mqtt.mqtt_publish_funct(value, this); | ||
this.adapter.log.debug('createIoBrokerState(), State : ' + stateid + ', Value: ' + JSON.stringify(value)); | ||
// this.adapter.log.debug('createIoBrokerState(), State : ' + stateid + ', Value: ' + JSON.stringify(value)); | ||
if (value !== undefined && (!this.states.hasOwnProperty(stateid) || this.states[stateid] !== value)) { | ||
this.adapter.log.debug('State change : ' + stateid + ', Value: ' + JSON.stringify(value) + ' for ' + this.getName()); | ||
this.states[stateid] = value; | ||
@@ -506,3 +575,3 @@ this.objectHelper.setOrUpdateObject(stateid, { | ||
} | ||
this.adapter.log.debug('Call url ' + JSON.stringify(params) + ' for ' + this.getName()); | ||
// this.adapter.log.debug('Call url ' + JSON.stringify(params) + ' for ' + this.getName()); | ||
let body = await requestAsync(params); | ||
@@ -518,4 +587,4 @@ for (let j in states) { | ||
value = isAsync(state.mqtt.http_publish_funct) ? await state.mqtt.http_publish_funct(value, this) : state.mqtt.http_publish_funct(value, this); | ||
this.adapter.log.debug('httpIoBrokerState(), State : ' + stateid + ', Value: ' + JSON.stringify(value)); | ||
if (value !== undefined && (!this.states.hasOwnProperty(stateid) || this.states[stateid] !== value)) { | ||
this.adapter.log.debug('Set state ' + stateid + ', Value: ' + JSON.stringify(value) + ' for ' + this.getName()); | ||
this.states[stateid] = value; | ||
@@ -551,2 +620,31 @@ this.objectHelper.setOrUpdateObject(stateid, { | ||
async firmwareUpdate(firmwareavailable) { | ||
if (firmwareavailable && this.adapter.config.auto_update) { | ||
let body; | ||
try { | ||
let params; | ||
if (this.auth) { | ||
params = { | ||
url: 'http://' + this.getIP() + '/ota?update=true', | ||
// update: true, | ||
headers: { | ||
'Authorization': this.auth | ||
} | ||
}; | ||
} else { | ||
params = { | ||
url: 'http://' + this.getIP() + '/ota?update=true', | ||
// update: true | ||
}; | ||
} | ||
this.adapter.log.debug('Call url ' + JSON.stringify(params) + ' for ' + this.getName()); | ||
body = await requestAsync(params); | ||
this.adapter.log.info('Executing Firmwareupdate for ' + this.getName()); | ||
} catch (error) { | ||
// | ||
} | ||
let a = body; | ||
} | ||
} | ||
start() { | ||
@@ -576,3 +674,3 @@ this.client = mqtt(this.stream); | ||
} else { | ||
this.adapter.log.error('Wrong authentification for : ' + this.getName()); | ||
this.adapter.log.error('Wrong MQTT authentification for : ' + this.getName()); | ||
this.client.connack({ returnCode: 4 }); | ||
@@ -601,33 +699,13 @@ } | ||
}); | ||
this.client.on('publish', (packet) => { | ||
this.adapter.log.debug('publish: ' + JSON.stringify(packet)); | ||
if (packet.payload) this.adapter.log.debug('publish payload: ' + packet.topic + ' = ' + packet.payload.toString()); | ||
// this.adapter.log.debug('Publish packet for ' + this.getName() + ' : ' + JSON.stringify(packet)); | ||
if (packet.payload) this.adapter.log.debug('Publish ' + this.getName() + ' payload: ' + packet.topic + ' = ' + packet.payload.toString()); | ||
this.createIoBrokerState(packet.topic, packet.payload); | ||
let pack; | ||
switch (packet.qos) { | ||
case 1: | ||
this.client.puback({ | ||
messageId: packet.messageId | ||
}); | ||
this.client.puback({ messageId: packet.messageId }); | ||
break; | ||
case 2: | ||
pack = this.messageIds.find((p) => { | ||
return p.messageId === packet.messageId; | ||
}); | ||
if (pack) { | ||
this.adapter.log.warn('Client ' + this.getName() + ' Ignored duplicate message with ID: ' + packet.messageId); | ||
return; | ||
} else { | ||
pack = { | ||
ts: Date.now(), | ||
cmd: 'pubrel', | ||
count: 0, | ||
messageId: packet.messageId | ||
}; | ||
this.messageIds.push(pack); | ||
this.client.pubrec({ | ||
messageId: packet.messageId | ||
}); | ||
} | ||
this.client.pubrec({ messageId: packet.messageId }); | ||
this.resendState2Client('pubrec', packet.messageId); | ||
break; | ||
@@ -645,29 +723,18 @@ default: | ||
this.client.on('pubrec', (packet) => { | ||
for (let i in this.messageIds) { | ||
if (this.messageIds[i].messageId === packet.messageId) { | ||
this.qos[packet.messageId] = { | ||
ts: Date.now(), | ||
cmd: 'pubrec', | ||
count: 0, | ||
messageId: packet.messageId | ||
}; | ||
this.client.pubrel({ | ||
messageId: packet.messageId | ||
}); | ||
return; | ||
} | ||
let qosmsg = this.getResendState2Client(packet.messageId); | ||
if (qosmsg && qosmsg.cmd === 'publish') { | ||
this.client.pubrel({ messageId: packet.messageId }); | ||
this.resendState2Client('pubrel', packet.messageId); | ||
} else { | ||
this.adapter.log.warn('Client ' + this.getName() + ' received pubrec for unknown messageId ' + packet.messageId); | ||
} | ||
this.adapter.log.warn('Client ' + this.getName() + ' received pubrec for unknown messageId ' + packet.messageId); | ||
}); | ||
// response for QoS2 | ||
this.client.on('pubcomp', (packet) => { | ||
/* | ||
let pos = null; | ||
if (pos !== null) { | ||
// remove this message from queue | ||
let qosmsg = this.getResendState2Client(packet.messageId); | ||
if (qosmsg && qosmsg.cmd === 'pubrec') { | ||
this.deleteResendState2Client(packet.messageId); | ||
} else { | ||
this.adapter.log.warn(`Client [${this.client.id}] Received pubcomp for unknown message ID: ${packet.messageId}`); | ||
this.adapter.log.warn('Client ' + this.getName() + ' received pubcomp for unknown messageId ' + packet.messageId); | ||
} | ||
*/ | ||
}); | ||
@@ -678,2 +745,9 @@ | ||
this.client.on('pubrel', (packet) => { | ||
let qosmsg = this.getResendState2Client(packet.messageId); | ||
if (qosmsg && qosmsg.cmd === 'pubrec') { | ||
this.deleteResendState2Client(packet.messageId); | ||
this.client.pubcomp({ messageId: packet.messageId }); | ||
} else { | ||
this.adapter.log.warn('Client ' + this.getName() + ' received pubrel for unknown messageId ' + packet.messageId); | ||
} | ||
}); | ||
@@ -684,2 +758,8 @@ | ||
// remove this message from queue | ||
let qosmsg = this.getResendState2Client(packet.messageId); | ||
if (qosmsg && qosmsg.cmd === 'publish') { | ||
this.deleteResendState2Client(packet.messageId); | ||
} else { | ||
this.adapter.log.warn('Client ' + this.getName() + ' received puback for unknown messageId ' + packet.messageId); | ||
} | ||
}); | ||
@@ -694,14 +774,12 @@ | ||
this.client.on('subscribe', (packet) => { | ||
// send a suback with messageId and granted QoS le^el | ||
this.adapter.log.debug('subscribe: ' + JSON.stringify(packet)); | ||
// send a suback with messageId and granted QoS level | ||
this.adapter.log.debug('Subscribe for ' + this.getName() + ' : ' + JSON.stringify(packet)); | ||
const granted = []; | ||
for (let i = 0; i < packet.subscriptions.length; i++) { | ||
for (let i in packet.subscriptions) { | ||
granted.push(packet.subscriptions[i].qos); | ||
let topic = packet.subscriptions[i].topic; | ||
this.adapter.log.debug('publish topic: ' + topic); | ||
// this.adapter.log.debug('publish topic: ' + topic); | ||
} | ||
if (packet.topic) this.adapter.log.debug('subscribe topic: ' + packet.topic); | ||
// this.adapter.log.info('Will: ' + packet.will); | ||
// this.client.suback({ granted: [packet.qos], messageId: packet.messageId }); | ||
this.client.suback({ granted: granted, messageId: packet.messageId }); | ||
@@ -731,8 +809,6 @@ }); | ||
let client = new MQTTClient(this.adapter, this.objectHelper, stream); | ||
// let name = stream.remoteAddress; | ||
// if (name && clientlist[name]) clientlist[name].destroy(); | ||
// clientlist[name] = client; | ||
stream.on('timeout', () => { | ||
this.adapter.log.info('Server Timeout for ' + stream.remoteAddress + ' (' + client.getName() + ')'); | ||
// client.destroy(); | ||
client.destroy(); | ||
stream.destroy(); | ||
}); | ||
@@ -739,0 +815,0 @@ stream.on('unload', () => { |
{ | ||
"name": "iobroker.shelly", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"description": "Shelly", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -42,2 +42,5 @@ ![Logo](admin/shelly.png) | ||
### 3.0.3 (02.06.2019) | ||
* (Stübi) - Support of MQTT QoS 1 and 2. Add auto firmware update to the menu | ||
### 3.0.2 (25.05.2019) | ||
@@ -44,0 +47,0 @@ * (Stübi) - Bugfixing and longpush and input states for Shelly 1, 2, 1pm, 2.5 and Shelly RGBWW2 added. Add state temperature to Shelly 1pm, 2.5 and Plug S. |
Sorry, the diff of this file is not supported yet
3138751
6921
121