Merge pull request #1383 from proddy/dev

no commands for nrgheat & nrgww - #1382
This commit is contained in:
Proddy
2023-11-04 14:11:13 +01:00
committed by GitHub
3 changed files with 108 additions and 106 deletions

View File

@@ -29,7 +29,7 @@
"@types/imagemin": "^8.0.3", "@types/imagemin": "^8.0.3",
"@types/lodash-es": "^4.17.10", "@types/lodash-es": "^4.17.10",
"@types/node": "^20.8.10", "@types/node": "^20.8.10",
"@types/react": "^18.2.33", "@types/react": "^18.2.34",
"@types/react-dom": "^18.2.14", "@types/react-dom": "^18.2.14",
"@types/react-router-dom": "^5.3.3", "@types/react-router-dom": "^5.3.3",
"alova": "^2.13.1", "alova": "^2.13.1",
@@ -54,18 +54,18 @@
"@typescript-eslint/eslint-plugin": "^6.9.1", "@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1", "@typescript-eslint/parser": "^6.9.1",
"concurrently": "^8.2.2", "concurrently": "^8.2.2",
"eslint": "^8.52.0", "eslint": "^8.53.0",
"eslint-config-airbnb": "^19.0.4", "eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^17.1.0", "eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-prettier": "^9.0.0", "eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-typescript": "^3.6.1", "eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-autofix": "^1.1.0", "eslint-plugin-autofix": "^1.1.0",
"eslint-plugin-import": "^2.29.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-prettier": "alpha",
"eslint-plugin-react": "^7.33.2", "eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-hooks": "^4.6.0",
"preact": "^10.18.1", "preact": "^10.18.2",
"prettier": "^3.0.3", "prettier": "^3.0.3",
"rollup-plugin-visualizer": "^5.9.2", "rollup-plugin-visualizer": "^5.9.2",
"terser": "^5.24.0", "terser": "^5.24.0",

View File

@@ -267,7 +267,7 @@ __metadata:
languageName: node languageName: node
linkType: hard 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 version: 7.23.2
resolution: "@babel/runtime@npm:7.23.2" resolution: "@babel/runtime@npm:7.23.2"
dependencies: dependencies:
@@ -641,9 +641,9 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@eslint/eslintrc@npm:^2.1.2": "@eslint/eslintrc@npm:^2.1.3":
version: 2.1.2 version: 2.1.3
resolution: "@eslint/eslintrc@npm:2.1.2" resolution: "@eslint/eslintrc@npm:2.1.3"
dependencies: dependencies:
ajv: "npm:^6.12.4" ajv: "npm:^6.12.4"
debug: "npm:^4.3.2" debug: "npm:^4.3.2"
@@ -654,14 +654,14 @@ __metadata:
js-yaml: "npm:^4.1.0" js-yaml: "npm:^4.1.0"
minimatch: "npm:^3.1.2" minimatch: "npm:^3.1.2"
strip-json-comments: "npm:^3.1.1" strip-json-comments: "npm:^3.1.1"
checksum: fa25638f2666cac6810f98ee7d0f4b912f191806467c1b40d72bac759fffef0b3357f12a1869817286837b258e4de3517e0c7408520e156ca860fc53a1fbaed9 checksum: 77b70a89232fe702c2f765b5b92970f5e4224b55363b923238b996c66fcd991504f40d3663c0543ae17d6c5049ab9b07ab90b65d7601e6f25e8bcd4caf69ac75
languageName: node languageName: node
linkType: hard linkType: hard
"@eslint/js@npm:8.52.0": "@eslint/js@npm:8.53.0":
version: 8.52.0 version: 8.53.0
resolution: "@eslint/js@npm:8.52.0" resolution: "@eslint/js@npm:8.53.0"
checksum: 86beff213d0ae4ced203a922b74e2cc4d767d109e7815f985bf648946ba072198977102e32afc9fa04f7825a6de83a831874f6b6675ba0c1d0743ade2dc2d53d checksum: a372d55aa2bbe0d9399acc8de3c892dcfe507fd914d29fde6826ae54a13452619be626aa7eb70b1ec4d4da5302b6ed8e8ac9bf1f830003f15c0ad56c30b4f520
languageName: node languageName: node
linkType: hard linkType: hard
@@ -1359,7 +1359,7 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@types/react@npm:*, @types/react@npm:^18.2.33": "@types/react@npm:*":
version: 18.2.33 version: 18.2.33
resolution: "@types/react@npm:18.2.33" resolution: "@types/react@npm:18.2.33"
dependencies: dependencies:
@@ -1370,6 +1370,17 @@ __metadata:
languageName: node languageName: node
linkType: hard 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": "@types/responselike@npm:^1.0.0":
version: 1.0.2 version: 1.0.2
resolution: "@types/responselike@npm:1.0.2" resolution: "@types/responselike@npm:1.0.2"
@@ -1547,7 +1558,7 @@ __metadata:
"@types/imagemin": "npm:^8.0.3" "@types/imagemin": "npm:^8.0.3"
"@types/lodash-es": "npm:^4.17.10" "@types/lodash-es": "npm:^4.17.10"
"@types/node": "npm:^20.8.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-dom": "npm:^18.2.14"
"@types/react-router-dom": "npm:^5.3.3" "@types/react-router-dom": "npm:^5.3.3"
"@typescript-eslint/eslint-plugin": "npm:^6.9.1" "@typescript-eslint/eslint-plugin": "npm:^6.9.1"
@@ -1555,14 +1566,14 @@ __metadata:
alova: "npm:^2.13.1" alova: "npm:^2.13.1"
async-validator: "npm:^4.2.5" async-validator: "npm:^4.2.5"
concurrently: "npm:^8.2.2" 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: "npm:^19.0.4"
eslint-config-airbnb-typescript: "npm:^17.1.0" eslint-config-airbnb-typescript: "npm:^17.1.0"
eslint-config-prettier: "npm:^9.0.0" eslint-config-prettier: "npm:^9.0.0"
eslint-import-resolver-typescript: "npm:^3.6.1" eslint-import-resolver-typescript: "npm:^3.6.1"
eslint-plugin-autofix: "npm:^1.1.0" eslint-plugin-autofix: "npm:^1.1.0"
eslint-plugin-import: "npm:^2.29.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-prettier: "npm:alpha"
eslint-plugin-react: "npm:^7.33.2" eslint-plugin-react: "npm:^7.33.2"
eslint-plugin-react-hooks: "npm:^4.6.0" eslint-plugin-react-hooks: "npm:^4.6.0"
@@ -1570,7 +1581,7 @@ __metadata:
jwt-decode: "npm:^4.0.0" jwt-decode: "npm:^4.0.0"
lodash-es: "npm:^4.17.21" lodash-es: "npm:^4.17.21"
mime-types: "npm:^2.1.35" mime-types: "npm:^2.1.35"
preact: "npm:^10.18.1" preact: "npm:^10.18.2"
prettier: "npm:^3.0.3" prettier: "npm:^3.0.3"
react: "npm:latest" react: "npm:latest"
react-dom: "npm:latest" react-dom: "npm:latest"
@@ -1754,7 +1765,7 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"aria-query@npm:^5.1.3": "aria-query@npm:^5.3.0":
version: 5.3.0 version: 5.3.0
resolution: "aria-query@npm:5.3.0" resolution: "aria-query@npm:5.3.0"
dependencies: dependencies:
@@ -1865,10 +1876,10 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"ast-types-flow@npm:^0.0.7": "ast-types-flow@npm:^0.0.8":
version: 0.0.7 version: 0.0.8
resolution: "ast-types-flow@npm:0.0.7" resolution: "ast-types-flow@npm:0.0.8"
checksum: 663b90e99b56ee2d7f736a6b6fff8b3c5404f28fa1860bb8d83ee5a9bff9e687520d0d6d9db6edff5a34fd4d3c0c11a3beb1cf75e43c9a880cca04371cc99808 checksum: 85a1c24af4707871c27cfe456bd2ff7fcbe678f3d1c878ac968c9557735a171a17bdcc8c8f903ceab3fc3c49d5b3da2194e6ab0a6be7fec0e133fa028f21ba1b
languageName: node languageName: node
linkType: hard linkType: hard
@@ -1902,14 +1913,14 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"axe-core@npm:^4.6.2": "axe-core@npm:=4.7.0":
version: 4.8.2 version: 4.7.0
resolution: "axe-core@npm:4.8.2" resolution: "axe-core@npm:4.7.0"
checksum: 3e8dbf264a57767713daa77fe04bbabd71a956b08b99c2eb0ec61b75852f21190653f557d2da623dea9e0a7555460deaac71d9f6a9125c0b52576f8581bfbe52 checksum: 615c0f7722c3c9fcf353dbd70b00e2ceae234d4c17cbc839dd85c01d16797c4e4da45f8d27c6118e9e6b033fb06efd196106e13651a1b2f3a10e0f11c7b2f660
languageName: node languageName: node
linkType: hard linkType: hard
"axobject-query@npm:^3.1.1": "axobject-query@npm:^3.2.1":
version: 3.2.1 version: 3.2.1
resolution: "axobject-query@npm:3.2.1" resolution: "axobject-query@npm:3.2.1"
dependencies: dependencies:
@@ -3034,7 +3045,7 @@ __metadata:
languageName: node languageName: node
linkType: hard 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 version: 1.0.15
resolution: "es-iterator-helpers@npm:1.0.15" resolution: "es-iterator-helpers@npm:1.0.15"
dependencies: dependencies:
@@ -3539,29 +3550,29 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"eslint-plugin-jsx-a11y@npm:^6.7.1": "eslint-plugin-jsx-a11y@npm:^6.8.0":
version: 6.7.1 version: 6.8.0
resolution: "eslint-plugin-jsx-a11y@npm:6.7.1" resolution: "eslint-plugin-jsx-a11y@npm:6.8.0"
dependencies: dependencies:
"@babel/runtime": "npm:^7.20.7" "@babel/runtime": "npm:^7.23.2"
aria-query: "npm:^5.1.3" aria-query: "npm:^5.3.0"
array-includes: "npm:^3.1.6" array-includes: "npm:^3.1.7"
array.prototype.flatmap: "npm:^1.3.1" array.prototype.flatmap: "npm:^1.3.2"
ast-types-flow: "npm:^0.0.7" ast-types-flow: "npm:^0.0.8"
axe-core: "npm:^4.6.2" axe-core: "npm:=4.7.0"
axobject-query: "npm:^3.1.1" axobject-query: "npm:^3.2.1"
damerau-levenshtein: "npm:^1.0.8" damerau-levenshtein: "npm:^1.0.8"
emoji-regex: "npm:^9.2.2" emoji-regex: "npm:^9.2.2"
has: "npm:^1.0.3" es-iterator-helpers: "npm:^1.0.15"
jsx-ast-utils: "npm:^3.3.3" hasown: "npm:^2.0.0"
language-tags: "npm:=1.0.5" jsx-ast-utils: "npm:^3.3.5"
language-tags: "npm:^1.0.9"
minimatch: "npm:^3.1.2" minimatch: "npm:^3.1.2"
object.entries: "npm:^1.1.6" object.entries: "npm:^1.1.7"
object.fromentries: "npm:^2.0.6" object.fromentries: "npm:^2.0.7"
semver: "npm:^6.3.0"
peerDependencies: peerDependencies:
eslint: ^3 || ^4 || ^5 || ^6 || ^7 || ^8 eslint: ^3 || ^4 || ^5 || ^6 || ^7 || ^8
checksum: b7eb451304dc27c9552649a716be1de3b5d577f39e53f6da6a2dac084b84b349b0224be3020439f99c2b3bf417a13c5591326f1ce6af8d74f1cb5d5d95c4222b checksum: 7a8e4498531a43d988ce2f12502a3f5ce96eacfec13f956cf927f24bb041b724fb7fc0f0306ea19d143bfc79e138bf25e25acca0822847206ac6bf5ce095e846
languageName: node languageName: node
linkType: hard linkType: hard
@@ -3643,14 +3654,14 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"eslint@npm:^8.52.0": "eslint@npm:^8.53.0":
version: 8.52.0 version: 8.53.0
resolution: "eslint@npm:8.52.0" resolution: "eslint@npm:8.53.0"
dependencies: dependencies:
"@eslint-community/eslint-utils": "npm:^4.2.0" "@eslint-community/eslint-utils": "npm:^4.2.0"
"@eslint-community/regexpp": "npm:^4.6.1" "@eslint-community/regexpp": "npm:^4.6.1"
"@eslint/eslintrc": "npm:^2.1.2" "@eslint/eslintrc": "npm:^2.1.3"
"@eslint/js": "npm:8.52.0" "@eslint/js": "npm:8.53.0"
"@humanwhocodes/config-array": "npm:^0.11.13" "@humanwhocodes/config-array": "npm:^0.11.13"
"@humanwhocodes/module-importer": "npm:^1.0.1" "@humanwhocodes/module-importer": "npm:^1.0.1"
"@nodelib/fs.walk": "npm:^1.2.8" "@nodelib/fs.walk": "npm:^1.2.8"
@@ -3687,7 +3698,7 @@ __metadata:
text-table: "npm:^0.2.0" text-table: "npm:^0.2.0"
bin: bin:
eslint: bin/eslint.js eslint: bin/eslint.js
checksum: 01784ab15351d749bc95446039ed7acd5124f7cc84acdbf98c7199272eae06212a8f3ea4a9b47e7cc54ab17ca094c3a664bbfc3002c7de27936220e278b5028a checksum: e305a71ce2b9a8631b293266fe53e346c76f28bc8d004af33f10e537cf133db1fb87af3599376e70ed6e0f89a78be10c4f08ddd0c1c9c0c497cd143b4a270420
languageName: node languageName: node
linkType: hard linkType: hard
@@ -4625,13 +4636,6 @@ __metadata:
languageName: node languageName: node
linkType: hard 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": "hasown@npm:^2.0.0":
version: 2.0.0 version: 2.0.0
resolution: "hasown@npm:2.0.0" resolution: "hasown@npm:2.0.0"
@@ -5493,7 +5497,7 @@ __metadata:
languageName: node languageName: node
linkType: hard 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 version: 3.3.5
resolution: "jsx-ast-utils@npm:3.3.5" resolution: "jsx-ast-utils@npm:3.3.5"
dependencies: dependencies:
@@ -5544,19 +5548,19 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"language-subtag-registry@npm:~0.3.2": "language-subtag-registry@npm:^0.3.20":
version: 0.3.22 version: 0.3.22
resolution: "language-subtag-registry@npm:0.3.22" resolution: "language-subtag-registry@npm:0.3.22"
checksum: 5591f4abd775d1ab5945355a5ba894327d2d94c900607bdb69aac1bc5bb921dbeeeb5f616df95e8c0ae875501d19c1cfa0e852ece822121e95048deb34f2b4d2 checksum: 5591f4abd775d1ab5945355a5ba894327d2d94c900607bdb69aac1bc5bb921dbeeeb5f616df95e8c0ae875501d19c1cfa0e852ece822121e95048deb34f2b4d2
languageName: node languageName: node
linkType: hard linkType: hard
"language-tags@npm:=1.0.5": "language-tags@npm:^1.0.9":
version: 1.0.5 version: 1.0.9
resolution: "language-tags@npm:1.0.5" resolution: "language-tags@npm:1.0.9"
dependencies: dependencies:
language-subtag-registry: "npm:~0.3.2" language-subtag-registry: "npm:^0.3.20"
checksum: 2161292ddae73ff2f5a15fd2d753b21096b81324337dff4ad78d702c63210d5beb18892cd53a3455ee6e88065807c8e285e82c40503678951d2071d101a473b4 checksum: d3a7c14b694e67f519153d6df6cb200681648d38d623c3bfa9d6a66a5ec5493628acb88e9df5aceef3cf1902ab263a205e7d59ee4cf1d6bb67e707b83538bd6d
languageName: node languageName: node
linkType: hard linkType: hard
@@ -6196,7 +6200,7 @@ __metadata:
languageName: node languageName: node
linkType: hard 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 version: 1.1.7
resolution: "object.entries@npm:1.1.7" resolution: "object.entries@npm:1.1.7"
dependencies: dependencies:
@@ -6657,10 +6661,10 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"preact@npm:^10.18.1": "preact@npm:^10.18.2":
version: 10.18.1 version: 10.18.2
resolution: "preact@npm:10.18.1" resolution: "preact@npm:10.18.2"
checksum: 587c4634b310efc306ef9315f849b8e4ff538435087a1dca626e1394b98570af1ecdc254b7f0bb3060fc7ab87456c5f891f9b8a167d5c34dbbcfcf60b6e993f4 checksum: c7dcd6ea812adb0bdc215366b14aadc44724b6dd6c4e9aadd986126d94abde62f3e02e18d6157a9984873be9877f206c0afa10a09346178c4c828a103a66a0e1
languageName: node languageName: node
linkType: hard linkType: hard

View File

@@ -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 // 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 // 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, return publish_ha_sensor_config(dv.type,
dv.tag, dv.tag,
@@ -846,7 +847,7 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
char config_topic[70]; char config_topic[70];
snprintf(config_topic, sizeof(config_topic), "%s/%s_%s/config", mqtt_basename_.c_str(), device_name, entity_with_tag); 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 // create the topic
// depending on the type and whether the device entity is writable (a command) // depending on the type and whether the device entity is writable (a command)
@@ -859,43 +860,41 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
case DeviceValueType::UINT: case DeviceValueType::UINT:
case DeviceValueType::SHORT: case DeviceValueType::SHORT:
case DeviceValueType::USHORT: 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) { if (discovery_type() == discoveryType::HOMEASSISTANT) {
// number - https://www.home-assistant.io/integrations/number.mqtt
snprintf(topic, sizeof(topic), "number/%s", config_topic); snprintf(topic, sizeof(topic), "number/%s", config_topic);
readonly_sensors = false;
} else { } else {
// Domoticz does not support number, use sensor
snprintf(topic, sizeof(topic), "sensor/%s", config_topic); snprintf(topic, sizeof(topic), "sensor/%s", config_topic);
} }
break; break;
case DeviceValueType::BOOL: case DeviceValueType::BOOL:
// switch - https://www.home-assistant.io/integrations/switch.mqtt // switch - https://www.home-assistant.io/integrations/switch.mqtt
snprintf(topic, sizeof(topic), "switch/%s", config_topic); snprintf(topic, sizeof(topic), "switch/%s", config_topic);
readonly_sensors = false;
break; break;
case DeviceValueType::ENUM: case DeviceValueType::ENUM:
// select - https://www.home-assistant.io/integrations/select.mqtt // select - https://www.home-assistant.io/integrations/select.mqtt
snprintf(topic, sizeof(topic), "select/%s", config_topic); snprintf(topic, sizeof(topic), "select/%s", config_topic);
break; readonly_sensors = false;
case DeviceValueType::ULONG:
snprintf(topic, sizeof(topic), "sensor/%s", config_topic);
set_ha_classes = true;
break; break;
case DeviceValueType::STRING: 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 snprintf(topic, sizeof(topic), "text/%s", config_topic); // e.g. set_datetime, set_holiday, set_wwswitchtime
set_ha_classes = true; readonly_sensors = false;
break; break;
default: default:
// plain old sensor // plain old sensor, and make read-only
snprintf(topic, sizeof(topic), "sensor/%s", config_topic);
break; 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 // For read-only sensors there are either sensor or binary_sensor
if (type == DeviceValueType::BOOL) { // for both we also set the device class and state class
snprintf(topic, sizeof(topic), "binary_sensor/%s", config_topic); // binary sensor (for booleans) if (readonly_sensors) {
} else { snprintf(topic, sizeof(topic), (type == DeviceValueType::BOOL) ? "binary_sensor/%s" : "sensor/%s", config_topic); // binary sensor (for booleans)
snprintf(topic, sizeof(topic), "sensor/%s", config_topic); // normal HA sensor
}
} }
// if we're asking to remove this topic, send an empty payload and exit // if we're asking to remove this topic, send an empty payload and exit
@@ -911,13 +910,15 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
doc["obj_id"] = uniq_id; // same as unique_id 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 * 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 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 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 // we add the command topic parameter for commands
if (has_cmd) { if (has_cmd) {
// add category
doc["ent_cat"] = "config"; // for writeable entities, like switch, number, text, select
char command_topic[MQTT_TOPIC_MAX_SIZE]; char command_topic[MQTT_TOPIC_MAX_SIZE];
// add command topic // add command topic
if (tag >= DeviceValueTAG::TAG_HC1) { if (tag >= DeviceValueTAG::TAG_HC1) {
@@ -1039,12 +1040,16 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
doc[uom_ha] = EMSdevice::uom_to_string(uom); // default doc[uom_ha] = EMSdevice::uom_to_string(uom); // default
} }
} }
doc["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else " + sample_val + "}}"; 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 // Add the state class, device class and sometimes the icon. Used only for read-only sensors Sensor and Binary Sensor
// used for Sensor and Binary Sensor Entities in HA if (readonly_sensors) {
if (set_ha_classes) { // first set the catagory
const char * dc_ha = "dev_cla"; // device class doc["ent_cat"] = "diagnostic";
const char * dc_ha = "dev_cla"; // device class
const char * sc_ha = "stat_cla"; // state class
switch (uom) { switch (uom) {
case DeviceValueUOM::DEGREES: case DeviceValueUOM::DEGREES:
@@ -1080,11 +1085,11 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
} else { } else {
doc[sc_ha] = F_(measurement); doc[sc_ha] = F_(measurement);
} }
doc[dc_ha] = "energy"; // no icon needed doc[dc_ha] = "energy";
break; break;
case DeviceValueUOM::KWH: case DeviceValueUOM::KWH:
doc[sc_ha] = F_(total_increasing); doc[sc_ha] = F_(total_increasing);
doc[dc_ha] = "energy"; // no icon needed doc[dc_ha] = "energy";
break; break;
case DeviceValueUOM::UA: case DeviceValueUOM::UA:
doc[ic_ha] = F_(iconua); doc[ic_ha] = F_(iconua);
@@ -1128,15 +1133,8 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
} }
} }
// add category "diagnostic" for system entities doc["dev"] = dev_json; // add the dev json object to the end
// config for writeable entities, like switches. diagnostic for read only sensors. add_avty_to_doc(stat_t, doc.as<JsonObject>(), val_cond); // add "availability" section
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<JsonObject>(), val_cond);
return queue_ha(topic, doc.as<JsonObject>()); return queue_ha(topic, doc.as<JsonObject>());
} }