* (Apollon77) Further optimize sending data to HASS and allow to set values like numbers as normal states if the service has one attribute and it can be mapped
This commit is contained in:
@@ -93,6 +93,10 @@ Please check it https://www.smarthomejetzt.de/mit-iobroker-auf-eine-home-assista
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
|
### __WORK IN PROGRESS__
|
||||||
|
* (Apollon77) Further optimize sending data to HASS and allow to set values like numbers as normal states if the service has one attribute and it can be mapped
|
||||||
|
|
||||||
### 1.2.0 (2022-06-17)
|
### 1.2.0 (2022-06-17)
|
||||||
* (Apollon77) IMPORTANT: Replace special characters in entity attribute names with an underscore! Object IDs might change!
|
* (Apollon77) IMPORTANT: Replace special characters in entity attribute names with an underscore! Object IDs might change!
|
||||||
* (Apollon77) make sure a "null" value in state changes is not crashing
|
* (Apollon77) make sure a "null" value in state changes is not crashing
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ function startAdapter(options) {
|
|||||||
const target = {};
|
const target = {};
|
||||||
|
|
||||||
let requestFields = {};
|
let requestFields = {};
|
||||||
if (typeof state.val === 'string') {
|
if (typeof state.val === 'string' && state.val.startsWith('{') && state.val.endsWith('}')) {
|
||||||
try {
|
try {
|
||||||
requestFields = JSON.parse(state.val) || {};
|
requestFields = JSON.parse(state.val) || {};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -49,6 +49,16 @@ function startAdapter(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If a non-JSON value was set and we only have one relevant field, use this field as value
|
||||||
|
if (Object.keys(requestFields).length === 0) {
|
||||||
|
const fieldList = Object.keys(fields);
|
||||||
|
if (fieldList.length === 1 && fieldList[0] !== 'entity_id') {
|
||||||
|
requestFields[fieldList[0]] = state.val;
|
||||||
|
} else if (fieldList.length === 2 && fields.entity_id) {
|
||||||
|
requestFields[fieldList[1 - fields.indexOf('entity_id')]] = state.val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const field in fields) {
|
for (const field in fields) {
|
||||||
if (!fields.hasOwnProperty(field)) {
|
if (!fields.hasOwnProperty(field)) {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user