From 8eba09fea6521fdece0fae4b8bf01a3eb3cee003 Mon Sep 17 00:00:00 2001 From: Proddy Date: Sat, 4 Nov 2023 11:46:16 +0100 Subject: [PATCH 1/3] package update --- interface/package.json | 8 +-- interface/yarn.lock | 138 +++++++++++++++++++++-------------------- 2 files changed, 75 insertions(+), 71 deletions(-) diff --git a/interface/package.json b/interface/package.json index 51078e8e3..702e68c46 100644 --- a/interface/package.json +++ b/interface/package.json @@ -29,7 +29,7 @@ "@types/imagemin": "^8.0.3", "@types/lodash-es": "^4.17.10", "@types/node": "^20.8.10", - "@types/react": "^18.2.33", + "@types/react": "^18.2.34", "@types/react-dom": "^18.2.14", "@types/react-router-dom": "^5.3.3", "alova": "^2.13.1", @@ -54,18 +54,18 @@ "@typescript-eslint/eslint-plugin": "^6.9.1", "@typescript-eslint/parser": "^6.9.1", "concurrently": "^8.2.2", - "eslint": "^8.52.0", + "eslint": "^8.53.0", "eslint-config-airbnb": "^19.0.4", "eslint-config-airbnb-typescript": "^17.1.0", "eslint-config-prettier": "^9.0.0", "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-autofix": "^1.1.0", "eslint-plugin-import": "^2.29.0", - "eslint-plugin-jsx-a11y": "^6.7.1", + "eslint-plugin-jsx-a11y": "^6.8.0", "eslint-plugin-prettier": "alpha", "eslint-plugin-react": "^7.33.2", "eslint-plugin-react-hooks": "^4.6.0", - "preact": "^10.18.1", + "preact": "^10.18.2", "prettier": "^3.0.3", "rollup-plugin-visualizer": "^5.9.2", "terser": "^5.24.0", diff --git a/interface/yarn.lock b/interface/yarn.lock index eb1bf057d..8d8492cc3 100644 --- a/interface/yarn.lock +++ b/interface/yarn.lock @@ -267,7 +267,7 @@ __metadata: languageName: node linkType: hard -"@babel/runtime@npm:^7.0.0, @babel/runtime@npm:^7.12.5, @babel/runtime@npm:^7.18.3, @babel/runtime@npm:^7.20.7, @babel/runtime@npm:^7.21.0, @babel/runtime@npm:^7.23.2, @babel/runtime@npm:^7.5.5, @babel/runtime@npm:^7.7.6, @babel/runtime@npm:^7.8.7": +"@babel/runtime@npm:^7.0.0, @babel/runtime@npm:^7.12.5, @babel/runtime@npm:^7.18.3, @babel/runtime@npm:^7.21.0, @babel/runtime@npm:^7.23.2, @babel/runtime@npm:^7.5.5, @babel/runtime@npm:^7.7.6, @babel/runtime@npm:^7.8.7": version: 7.23.2 resolution: "@babel/runtime@npm:7.23.2" dependencies: @@ -641,9 +641,9 @@ __metadata: languageName: node linkType: hard -"@eslint/eslintrc@npm:^2.1.2": - version: 2.1.2 - resolution: "@eslint/eslintrc@npm:2.1.2" +"@eslint/eslintrc@npm:^2.1.3": + version: 2.1.3 + resolution: "@eslint/eslintrc@npm:2.1.3" dependencies: ajv: "npm:^6.12.4" debug: "npm:^4.3.2" @@ -654,14 +654,14 @@ __metadata: js-yaml: "npm:^4.1.0" minimatch: "npm:^3.1.2" strip-json-comments: "npm:^3.1.1" - checksum: fa25638f2666cac6810f98ee7d0f4b912f191806467c1b40d72bac759fffef0b3357f12a1869817286837b258e4de3517e0c7408520e156ca860fc53a1fbaed9 + checksum: 77b70a89232fe702c2f765b5b92970f5e4224b55363b923238b996c66fcd991504f40d3663c0543ae17d6c5049ab9b07ab90b65d7601e6f25e8bcd4caf69ac75 languageName: node linkType: hard -"@eslint/js@npm:8.52.0": - version: 8.52.0 - resolution: "@eslint/js@npm:8.52.0" - checksum: 86beff213d0ae4ced203a922b74e2cc4d767d109e7815f985bf648946ba072198977102e32afc9fa04f7825a6de83a831874f6b6675ba0c1d0743ade2dc2d53d +"@eslint/js@npm:8.53.0": + version: 8.53.0 + resolution: "@eslint/js@npm:8.53.0" + checksum: a372d55aa2bbe0d9399acc8de3c892dcfe507fd914d29fde6826ae54a13452619be626aa7eb70b1ec4d4da5302b6ed8e8ac9bf1f830003f15c0ad56c30b4f520 languageName: node linkType: hard @@ -1359,7 +1359,7 @@ __metadata: languageName: node linkType: hard -"@types/react@npm:*, @types/react@npm:^18.2.33": +"@types/react@npm:*": version: 18.2.33 resolution: "@types/react@npm:18.2.33" dependencies: @@ -1370,6 +1370,17 @@ __metadata: languageName: node linkType: hard +"@types/react@npm:^18.2.34": + version: 18.2.34 + resolution: "@types/react@npm:18.2.34" + dependencies: + "@types/prop-types": "npm:*" + "@types/scheduler": "npm:*" + csstype: "npm:^3.0.2" + checksum: 6d16f86b384e829edc3710b1dd9ec4eb1d6b26bc079c5cf605bd0cbf77ae6224f15c76949afadb7f53df4544cfe4025c1111fbe36732cd7f660a320fbc2e5866 + languageName: node + linkType: hard + "@types/responselike@npm:^1.0.0": version: 1.0.2 resolution: "@types/responselike@npm:1.0.2" @@ -1547,7 +1558,7 @@ __metadata: "@types/imagemin": "npm:^8.0.3" "@types/lodash-es": "npm:^4.17.10" "@types/node": "npm:^20.8.10" - "@types/react": "npm:^18.2.33" + "@types/react": "npm:^18.2.34" "@types/react-dom": "npm:^18.2.14" "@types/react-router-dom": "npm:^5.3.3" "@typescript-eslint/eslint-plugin": "npm:^6.9.1" @@ -1555,14 +1566,14 @@ __metadata: alova: "npm:^2.13.1" async-validator: "npm:^4.2.5" concurrently: "npm:^8.2.2" - eslint: "npm:^8.52.0" + eslint: "npm:^8.53.0" eslint-config-airbnb: "npm:^19.0.4" eslint-config-airbnb-typescript: "npm:^17.1.0" eslint-config-prettier: "npm:^9.0.0" eslint-import-resolver-typescript: "npm:^3.6.1" eslint-plugin-autofix: "npm:^1.1.0" eslint-plugin-import: "npm:^2.29.0" - eslint-plugin-jsx-a11y: "npm:^6.7.1" + eslint-plugin-jsx-a11y: "npm:^6.8.0" eslint-plugin-prettier: "npm:alpha" eslint-plugin-react: "npm:^7.33.2" eslint-plugin-react-hooks: "npm:^4.6.0" @@ -1570,7 +1581,7 @@ __metadata: jwt-decode: "npm:^4.0.0" lodash-es: "npm:^4.17.21" mime-types: "npm:^2.1.35" - preact: "npm:^10.18.1" + preact: "npm:^10.18.2" prettier: "npm:^3.0.3" react: "npm:latest" react-dom: "npm:latest" @@ -1754,7 +1765,7 @@ __metadata: languageName: node linkType: hard -"aria-query@npm:^5.1.3": +"aria-query@npm:^5.3.0": version: 5.3.0 resolution: "aria-query@npm:5.3.0" dependencies: @@ -1865,10 +1876,10 @@ __metadata: languageName: node linkType: hard -"ast-types-flow@npm:^0.0.7": - version: 0.0.7 - resolution: "ast-types-flow@npm:0.0.7" - checksum: 663b90e99b56ee2d7f736a6b6fff8b3c5404f28fa1860bb8d83ee5a9bff9e687520d0d6d9db6edff5a34fd4d3c0c11a3beb1cf75e43c9a880cca04371cc99808 +"ast-types-flow@npm:^0.0.8": + version: 0.0.8 + resolution: "ast-types-flow@npm:0.0.8" + checksum: 85a1c24af4707871c27cfe456bd2ff7fcbe678f3d1c878ac968c9557735a171a17bdcc8c8f903ceab3fc3c49d5b3da2194e6ab0a6be7fec0e133fa028f21ba1b languageName: node linkType: hard @@ -1902,14 +1913,14 @@ __metadata: languageName: node linkType: hard -"axe-core@npm:^4.6.2": - version: 4.8.2 - resolution: "axe-core@npm:4.8.2" - checksum: 3e8dbf264a57767713daa77fe04bbabd71a956b08b99c2eb0ec61b75852f21190653f557d2da623dea9e0a7555460deaac71d9f6a9125c0b52576f8581bfbe52 +"axe-core@npm:=4.7.0": + version: 4.7.0 + resolution: "axe-core@npm:4.7.0" + checksum: 615c0f7722c3c9fcf353dbd70b00e2ceae234d4c17cbc839dd85c01d16797c4e4da45f8d27c6118e9e6b033fb06efd196106e13651a1b2f3a10e0f11c7b2f660 languageName: node linkType: hard -"axobject-query@npm:^3.1.1": +"axobject-query@npm:^3.2.1": version: 3.2.1 resolution: "axobject-query@npm:3.2.1" dependencies: @@ -3034,7 +3045,7 @@ __metadata: languageName: node linkType: hard -"es-iterator-helpers@npm:^1.0.12": +"es-iterator-helpers@npm:^1.0.12, es-iterator-helpers@npm:^1.0.15": version: 1.0.15 resolution: "es-iterator-helpers@npm:1.0.15" dependencies: @@ -3539,29 +3550,29 @@ __metadata: languageName: node linkType: hard -"eslint-plugin-jsx-a11y@npm:^6.7.1": - version: 6.7.1 - resolution: "eslint-plugin-jsx-a11y@npm:6.7.1" +"eslint-plugin-jsx-a11y@npm:^6.8.0": + version: 6.8.0 + resolution: "eslint-plugin-jsx-a11y@npm:6.8.0" dependencies: - "@babel/runtime": "npm:^7.20.7" - aria-query: "npm:^5.1.3" - array-includes: "npm:^3.1.6" - array.prototype.flatmap: "npm:^1.3.1" - ast-types-flow: "npm:^0.0.7" - axe-core: "npm:^4.6.2" - axobject-query: "npm:^3.1.1" + "@babel/runtime": "npm:^7.23.2" + aria-query: "npm:^5.3.0" + array-includes: "npm:^3.1.7" + array.prototype.flatmap: "npm:^1.3.2" + ast-types-flow: "npm:^0.0.8" + axe-core: "npm:=4.7.0" + axobject-query: "npm:^3.2.1" damerau-levenshtein: "npm:^1.0.8" emoji-regex: "npm:^9.2.2" - has: "npm:^1.0.3" - jsx-ast-utils: "npm:^3.3.3" - language-tags: "npm:=1.0.5" + es-iterator-helpers: "npm:^1.0.15" + hasown: "npm:^2.0.0" + jsx-ast-utils: "npm:^3.3.5" + language-tags: "npm:^1.0.9" minimatch: "npm:^3.1.2" - object.entries: "npm:^1.1.6" - object.fromentries: "npm:^2.0.6" - semver: "npm:^6.3.0" + object.entries: "npm:^1.1.7" + object.fromentries: "npm:^2.0.7" peerDependencies: eslint: ^3 || ^4 || ^5 || ^6 || ^7 || ^8 - checksum: b7eb451304dc27c9552649a716be1de3b5d577f39e53f6da6a2dac084b84b349b0224be3020439f99c2b3bf417a13c5591326f1ce6af8d74f1cb5d5d95c4222b + checksum: 7a8e4498531a43d988ce2f12502a3f5ce96eacfec13f956cf927f24bb041b724fb7fc0f0306ea19d143bfc79e138bf25e25acca0822847206ac6bf5ce095e846 languageName: node linkType: hard @@ -3643,14 +3654,14 @@ __metadata: languageName: node linkType: hard -"eslint@npm:^8.52.0": - version: 8.52.0 - resolution: "eslint@npm:8.52.0" +"eslint@npm:^8.53.0": + version: 8.53.0 + resolution: "eslint@npm:8.53.0" dependencies: "@eslint-community/eslint-utils": "npm:^4.2.0" "@eslint-community/regexpp": "npm:^4.6.1" - "@eslint/eslintrc": "npm:^2.1.2" - "@eslint/js": "npm:8.52.0" + "@eslint/eslintrc": "npm:^2.1.3" + "@eslint/js": "npm:8.53.0" "@humanwhocodes/config-array": "npm:^0.11.13" "@humanwhocodes/module-importer": "npm:^1.0.1" "@nodelib/fs.walk": "npm:^1.2.8" @@ -3687,7 +3698,7 @@ __metadata: text-table: "npm:^0.2.0" bin: eslint: bin/eslint.js - checksum: 01784ab15351d749bc95446039ed7acd5124f7cc84acdbf98c7199272eae06212a8f3ea4a9b47e7cc54ab17ca094c3a664bbfc3002c7de27936220e278b5028a + checksum: e305a71ce2b9a8631b293266fe53e346c76f28bc8d004af33f10e537cf133db1fb87af3599376e70ed6e0f89a78be10c4f08ddd0c1c9c0c497cd143b4a270420 languageName: node linkType: hard @@ -4625,13 +4636,6 @@ __metadata: languageName: node linkType: hard -"has@npm:^1.0.3": - version: 1.0.4 - resolution: "has@npm:1.0.4" - checksum: c245f332fe78c7b6b8753857240ac12b3286f995f656a33c77e0f5baab7d0157e6ddb1c34940ffd2bffc51f75ede50cd8b29ff65c13e336376aca8cf3df58043 - languageName: node - linkType: hard - "hasown@npm:^2.0.0": version: 2.0.0 resolution: "hasown@npm:2.0.0" @@ -5493,7 +5497,7 @@ __metadata: languageName: node linkType: hard -"jsx-ast-utils@npm:^2.4.1 || ^3.0.0, jsx-ast-utils@npm:^3.3.3": +"jsx-ast-utils@npm:^2.4.1 || ^3.0.0, jsx-ast-utils@npm:^3.3.5": version: 3.3.5 resolution: "jsx-ast-utils@npm:3.3.5" dependencies: @@ -5544,19 +5548,19 @@ __metadata: languageName: node linkType: hard -"language-subtag-registry@npm:~0.3.2": +"language-subtag-registry@npm:^0.3.20": version: 0.3.22 resolution: "language-subtag-registry@npm:0.3.22" checksum: 5591f4abd775d1ab5945355a5ba894327d2d94c900607bdb69aac1bc5bb921dbeeeb5f616df95e8c0ae875501d19c1cfa0e852ece822121e95048deb34f2b4d2 languageName: node linkType: hard -"language-tags@npm:=1.0.5": - version: 1.0.5 - resolution: "language-tags@npm:1.0.5" +"language-tags@npm:^1.0.9": + version: 1.0.9 + resolution: "language-tags@npm:1.0.9" dependencies: - language-subtag-registry: "npm:~0.3.2" - checksum: 2161292ddae73ff2f5a15fd2d753b21096b81324337dff4ad78d702c63210d5beb18892cd53a3455ee6e88065807c8e285e82c40503678951d2071d101a473b4 + language-subtag-registry: "npm:^0.3.20" + checksum: d3a7c14b694e67f519153d6df6cb200681648d38d623c3bfa9d6a66a5ec5493628acb88e9df5aceef3cf1902ab263a205e7d59ee4cf1d6bb67e707b83538bd6d languageName: node linkType: hard @@ -6196,7 +6200,7 @@ __metadata: languageName: node linkType: hard -"object.entries@npm:^1.1.5, object.entries@npm:^1.1.6": +"object.entries@npm:^1.1.5, object.entries@npm:^1.1.6, object.entries@npm:^1.1.7": version: 1.1.7 resolution: "object.entries@npm:1.1.7" dependencies: @@ -6657,10 +6661,10 @@ __metadata: languageName: node linkType: hard -"preact@npm:^10.18.1": - version: 10.18.1 - resolution: "preact@npm:10.18.1" - checksum: 587c4634b310efc306ef9315f849b8e4ff538435087a1dca626e1394b98570af1ecdc254b7f0bb3060fc7ab87456c5f891f9b8a167d5c34dbbcfcf60b6e993f4 +"preact@npm:^10.18.2": + version: 10.18.2 + resolution: "preact@npm:10.18.2" + checksum: c7dcd6ea812adb0bdc215366b14aadc44724b6dd6c4e9aadd986126d94abde62f3e02e18d6157a9984873be9877f206c0afa10a09346178c4c828a103a66a0e1 languageName: node linkType: hard From cd564f0c5429ba3a2e8cd5cab5008a593ea3d688 Mon Sep 17 00:00:00 2001 From: Proddy Date: Sat, 4 Nov 2023 11:46:42 +0100 Subject: [PATCH 2/3] no commands for nrgheat & nrgww - #1382 --- src/mqtt.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/mqtt.cpp b/src/mqtt.cpp index dc5b3f133..1cb53908a 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -753,7 +753,8 @@ bool Mqtt::publish_ha_sensor_config(DeviceValue & dv, const char * model, const // determine if we're creating the command topics which we use special HA configs // unless the entity has been marked as read-only and so it'll default to using the sensor/ type - bool has_cmd = dv.has_cmd && !dv.has_state(DeviceValueState::DV_READONLY); + // or we're dealing with Energy sensors that must have "diagnostic" as an entity category (e.g. negheat & nrgww) + bool has_cmd = dv.has_cmd && !dv.has_state(DeviceValueState::DV_READONLY) && (dv.uom != DeviceValueUOM::KWH); return publish_ha_sensor_config(dv.type, dv.tag, @@ -1080,11 +1081,11 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev } else { doc[sc_ha] = F_(measurement); } - doc[dc_ha] = "energy"; // no icon needed + doc[dc_ha] = "energy"; break; case DeviceValueUOM::KWH: doc[sc_ha] = F_(total_increasing); - doc[dc_ha] = "energy"; // no icon needed + doc[dc_ha] = "energy"; break; case DeviceValueUOM::UA: doc[ic_ha] = F_(iconua); @@ -1128,8 +1129,9 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev } } - // add category "diagnostic" for system entities - // config for writeable entities, like switches. diagnostic for read only sensors. + // add category + // "config" for writeable entities, like switch, number, text, select + // "diagnostic" for read only sensors doc["ent_cat"] = (has_cmd) ? "config" : "diagnostic"; // add the dev json object to the end From a449ebd0ea85c830d0563af0c5e8a5d42e6ab7db Mon Sep 17 00:00:00 2001 From: Proddy Date: Sat, 4 Nov 2023 13:13:52 +0100 Subject: [PATCH 3/3] improvements to #1382 --- src/mqtt.cpp | 62 ++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 1cb53908a..bf9a9fad9 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -847,7 +847,7 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev char config_topic[70]; snprintf(config_topic, sizeof(config_topic), "%s/%s_%s/config", mqtt_basename_.c_str(), device_name, entity_with_tag); - bool set_ha_classes = false; // set to true if we want to set the state class and device class + bool readonly_sensors = true; // create the topic // depending on the type and whether the device entity is writable (a command) @@ -860,43 +860,41 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev case DeviceValueType::UINT: case DeviceValueType::SHORT: case DeviceValueType::USHORT: + case DeviceValueType::ULONG: + // number - https://www.home-assistant.io/integrations/number.mqtt + // Domoticz does not support number, use sensor if (discovery_type() == discoveryType::HOMEASSISTANT) { - // number - https://www.home-assistant.io/integrations/number.mqtt snprintf(topic, sizeof(topic), "number/%s", config_topic); + readonly_sensors = false; } else { - // Domoticz does not support number, use sensor snprintf(topic, sizeof(topic), "sensor/%s", config_topic); } break; case DeviceValueType::BOOL: // switch - https://www.home-assistant.io/integrations/switch.mqtt snprintf(topic, sizeof(topic), "switch/%s", config_topic); + readonly_sensors = false; break; case DeviceValueType::ENUM: // select - https://www.home-assistant.io/integrations/select.mqtt snprintf(topic, sizeof(topic), "select/%s", config_topic); - break; - case DeviceValueType::ULONG: - snprintf(topic, sizeof(topic), "sensor/%s", config_topic); - set_ha_classes = true; + readonly_sensors = false; break; case DeviceValueType::STRING: + // text - https://www.home-assistant.io/integrations/text.mqtt snprintf(topic, sizeof(topic), "text/%s", config_topic); // e.g. set_datetime, set_holiday, set_wwswitchtime - set_ha_classes = true; + readonly_sensors = false; break; default: - // plain old sensor - snprintf(topic, sizeof(topic), "sensor/%s", config_topic); + // plain old sensor, and make read-only break; } - } else { - set_ha_classes = true; // these are Read only sensors. We can set the device class and state class - // plain old read only device entity - if (type == DeviceValueType::BOOL) { - snprintf(topic, sizeof(topic), "binary_sensor/%s", config_topic); // binary sensor (for booleans) - } else { - snprintf(topic, sizeof(topic), "sensor/%s", config_topic); // normal HA sensor - } + } + + // For read-only sensors there are either sensor or binary_sensor + // for both we also set the device class and state class + if (readonly_sensors) { + snprintf(topic, sizeof(topic), (type == DeviceValueType::BOOL) ? "binary_sensor/%s" : "sensor/%s", config_topic); // binary sensor (for booleans) } // if we're asking to remove this topic, send an empty payload and exit @@ -912,13 +910,15 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev doc["obj_id"] = uniq_id; // same as unique_id const char * ic_ha = "ic"; // icon - only set this if there is no device class - const char * sc_ha = "stat_cla"; // state class const char * uom_ha = "unit_of_meas"; // unit of measure char sample_val[30] = "0"; // sample, correct(!) entity value, used only to prevent warning/error in HA if real value is not published yet // we add the command topic parameter for commands if (has_cmd) { + // add category + doc["ent_cat"] = "config"; // for writeable entities, like switch, number, text, select + char command_topic[MQTT_TOPIC_MAX_SIZE]; // add command topic if (tag >= DeviceValueTAG::TAG_HC1) { @@ -1040,12 +1040,16 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev doc[uom_ha] = EMSdevice::uom_to_string(uom); // default } } + doc["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else " + sample_val + "}}"; - // this next section is adding the state class, device class and sometimes the icon - // used for Sensor and Binary Sensor Entities in HA - if (set_ha_classes) { - const char * dc_ha = "dev_cla"; // device class + // Add the state class, device class and sometimes the icon. Used only for read-only sensors Sensor and Binary Sensor + if (readonly_sensors) { + // first set the catagory + doc["ent_cat"] = "diagnostic"; + + const char * dc_ha = "dev_cla"; // device class + const char * sc_ha = "stat_cla"; // state class switch (uom) { case DeviceValueUOM::DEGREES: @@ -1129,16 +1133,8 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev } } - // add category - // "config" for writeable entities, like switch, number, text, select - // "diagnostic" for read only sensors - doc["ent_cat"] = (has_cmd) ? "config" : "diagnostic"; - - // add the dev json object to the end - doc["dev"] = dev_json; - - // add "availability" section - add_avty_to_doc(stat_t, doc.as(), val_cond); + doc["dev"] = dev_json; // add the dev json object to the end + add_avty_to_doc(stat_t, doc.as(), val_cond); // add "availability" section return queue_ha(topic, doc.as()); }