Skip to content

Commit

Permalink
Merge pull request #1374 from proddy/dev2
Browse files Browse the repository at this point in the history
Dev2
  • Loading branch information
proddy authored Oct 31, 2023
2 parents 879df33 + 16a9bc4 commit 6853651
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
4 changes: 2 additions & 2 deletions interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"react-dom": "latest",
"react-dropzone": "^14.2.3",
"react-icons": "^4.11.0",
"react-router-dom": "^6.17.0",
"react-router-dom": "^6.18.0",
"react-toastify": "^9.1.3",
"sockette": "^2.0.6",
"typesafe-i18n": "^5.26.2",
Expand All @@ -68,7 +68,7 @@
"preact": "^10.18.1",
"prettier": "^3.0.3",
"rollup-plugin-visualizer": "^5.9.2",
"terser": "^5.23.0",
"terser": "^5.24.0",
"vite": "^4.5.0",
"vite-plugin-imagemin": "^0.6.1",
"vite-tsconfig-paths": "^4.2.1"
Expand Down
42 changes: 21 additions & 21 deletions interface/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1099,10 +1099,10 @@ __metadata:
languageName: node
linkType: hard

"@remix-run/router@npm:1.10.0":
version: 1.10.0
resolution: "@remix-run/router@npm:1.10.0"
checksum: 61f5e6374f2d0edd177a61c8a44715290d9197a61362505fb0784f948a39e8353d9604ce3747151f837fc7b950e1fbd71bc797b161643325c545037ffbedd134
"@remix-run/router@npm:1.11.0":
version: 1.11.0
resolution: "@remix-run/router@npm:1.11.0"
checksum: 629ec578b9dfd3c5cb5de64a0798dd7846ec5ba0351aa66f42b1c65efb43da8f30366be59b825303648965b0df55b638c110949b24ef94fd62e98117fdfb0c0f
languageName: node
linkType: hard

Expand Down Expand Up @@ -1576,11 +1576,11 @@ __metadata:
react-dom: "npm:latest"
react-dropzone: "npm:^14.2.3"
react-icons: "npm:^4.11.0"
react-router-dom: "npm:^6.17.0"
react-router-dom: "npm:^6.18.0"
react-toastify: "npm:^9.1.3"
rollup-plugin-visualizer: "npm:^5.9.2"
sockette: "npm:^2.0.6"
terser: "npm:^5.23.0"
terser: "npm:^5.24.0"
typesafe-i18n: "npm:^5.26.2"
typescript: "npm:^5.2.2"
vite: "npm:^4.5.0"
Expand Down Expand Up @@ -6828,27 +6828,27 @@ __metadata:
languageName: node
linkType: hard

"react-router-dom@npm:^6.17.0":
version: 6.17.0
resolution: "react-router-dom@npm:6.17.0"
"react-router-dom@npm:^6.18.0":
version: 6.18.0
resolution: "react-router-dom@npm:6.18.0"
dependencies:
"@remix-run/router": "npm:1.10.0"
react-router: "npm:6.17.0"
"@remix-run/router": "npm:1.11.0"
react-router: "npm:6.18.0"
peerDependencies:
react: ">=16.8"
react-dom: ">=16.8"
checksum: fc881346af12cdfc4f709c6ca91090d5ed62362154a398a0e8c2b19daabee1fbc8a3ddd0ab727e743ea4268b87f3b2ebc3251c730e2c190ee3ab286059f523e5
checksum: b0e72603d73172b6c6662afe2faed326753d5bbd9905aa560e3dade7996fc13d19e34e3ed668d2849efd685e2db2f711129c84b1439870e92c9cc91ddc343cf5
languageName: node
linkType: hard

"react-router@npm:6.17.0":
version: 6.17.0
resolution: "react-router@npm:6.17.0"
"react-router@npm:6.18.0":
version: 6.18.0
resolution: "react-router@npm:6.18.0"
dependencies:
"@remix-run/router": "npm:1.10.0"
"@remix-run/router": "npm:1.11.0"
peerDependencies:
react: ">=16.8"
checksum: 5c589c67b53cc1a210bd08285392e951a2c3d51a2502806f68d9ce604307944239b0a3b766d8390b484d707ace3068af858e999a1c242662b917ddcd4ab3c453
checksum: a00c8f347b7ffee575f4a7731782e688e3fca458ca5bd970fb41cef66a6851853caa24464155ab438d5879f367b1223a539642a405a865913ffe7e63e53b1245
languageName: node
linkType: hard

Expand Down Expand Up @@ -7912,17 +7912,17 @@ __metadata:
languageName: node
linkType: hard

"terser@npm:^5.23.0":
version: 5.23.0
resolution: "terser@npm:5.23.0"
"terser@npm:^5.24.0":
version: 5.24.0
resolution: "terser@npm:5.24.0"
dependencies:
"@jridgewell/source-map": "npm:^0.3.3"
acorn: "npm:^8.8.2"
commander: "npm:^2.20.0"
source-map-support: "npm:~0.5.20"
bin:
terser: bin/terser
checksum: 0a9ffc843cf9ee529b3cb85c4e961fd61dc1d484c462372a7158099c3147c28d8bfe9d57e49d4d7594a9c7deed0a7f28a30f79a9161152bd89791fe986e834f0
checksum: bd7ba6bfef58f8c179592894923c8c933d980e17287d3f2a9927550be853d1601beebb724cf015929599b32945641c44f9c3db8dd242c7933af3830bcb853510
languageName: node
linkType: hard

Expand Down
19 changes: 11 additions & 8 deletions src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,10 +848,11 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev

bool set_ha_classes = false; // set to true if we want to set the state class and device class

// create the topic, depending on the type and whether the device entity is writable (a command)
// create the topic
// depending on the type and whether the device entity is writable (a command)
// https://developers.home-assistant.io/docs/core/entity
char topic[MQTT_TOPIC_MAX_SIZE];
// if it's a command then we can use Number, Switch, Select. Otherwise stick to Sensor
// if it's a command then we can use Number, Switch, Select or Text. Otherwise stick to Sensor
if (has_cmd) {
switch (type) {
case DeviceValueType::INT:
Expand All @@ -878,6 +879,10 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
snprintf(topic, sizeof(topic), "sensor/%s", config_topic);
set_ha_classes = true;
break;
case DeviceValueType::STRING:
snprintf(topic, sizeof(topic), "text/%s", config_topic); // e.g. set_datetime, set_holiday, set_wwswitchtime
set_ha_classes = true;
break;
default:
// plain old sensor
snprintf(topic, sizeof(topic), "sensor/%s", config_topic);
Expand Down Expand Up @@ -911,20 +916,18 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev

char sample_val[30] = "0"; // sample, correct(!) entity value, used only to prevent warning/error in HA if real value is not published yet

// handle commands, which are device entities that are writable
// we add the command topic parameter
// note: there is no way to handle strings in HA so datetimes (e.g. set_datetime, set_holiday, set_wwswitchtime etc) are excluded
// we add the command topic parameter for commands
if (has_cmd) {
// command topic back to EMS-ESP
char command_topic[MQTT_TOPIC_MAX_SIZE];
// add command topic
if (tag >= DeviceValueTAG::TAG_HC1) {
snprintf(command_topic, sizeof(command_topic), "%s/%s/%s/%s", mqtt_basename_.c_str(), device_name, EMSdevice::tag_to_mqtt(tag), entity);
} else {
snprintf(command_topic, sizeof(command_topic), "%s/%s/%s", mqtt_basename_.c_str(), device_name, entity);
}
doc["cmd_t"] = command_topic;

// for enums, add options
// extend for enums, add options
if (type == DeviceValueType::ENUM) {
JsonArray option_list = doc.createNestedArray("ops"); // options
if (EMSESP::system_.enum_format() == ENUM_FORMAT_INDEX) {
Expand All @@ -942,7 +945,7 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
}

} else if (type != DeviceValueType::STRING && type != DeviceValueType::BOOL) {
// Must be Numeric....
// For numeric's add the range
doc["mode"] = "box"; // auto, slider or box
if (num_op > 0) {
doc["step"] = 1.0 / num_op;
Expand Down

0 comments on commit 6853651

Please sign in to comment.