Skip to content

Commit

Permalink
Set device_class to duration in HA sensor definitions #822
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Dec 23, 2022
1 parent 9802581 commit 3c91ac2
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 130 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG_LATEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@
- reload page after restart button is pressed
- analog/dallas values command as list like ems-devices
- analog/dallas HA-entities based on id
- MQTT Base is a mandatory field. Removed MQTT topic length from settings.
- MQTT Base is a mandatory field. Removed MQTT topic length from settings
- HA duration class for time entities [[#822](https://github.com/emsesp/EMS-ESP32/issues/822
8 changes: 4 additions & 4 deletions interface/.typesafe-i18n.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"adapter": "react",
"baseLocale": "pl",
"$schema": "https://unpkg.com/typesafe-i18n@5.17.2/schema/typesafe-i18n.json"
}
"adapter": "react",
"baseLocale": "pl",
"$schema": "https://unpkg.com/typesafe-i18n@5.18.0/schema/typesafe-i18n.json"
}
184 changes: 92 additions & 92 deletions interface/package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"@emotion/styled": "^11.10.5",
"@msgpack/msgpack": "^2.8.0",
"@mui/icons-material": "^5.11.0",
"@mui/material": "^5.11.0",
"@mui/material": "^5.11.1",
"@table-library/react-table-library": "4.0.23",
"@types/lodash": "^4.14.191",
"@types/node": "^18.11.17",
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.9",
"@types/react-dom": "^18.0.10",
"@types/react-router-dom": "^5.3.3",
"async-validator": "^4.2.5",
"axios": "^1.2.1",
Expand All @@ -27,10 +27,10 @@
"react-dom": "^18.2.0",
"react-dropzone": "^14.2.3",
"react-icons": "^4.7.1",
"react-router-dom": "^6.5.0",
"react-router-dom": "^6.6.0",
"react-scripts": "5.0.1",
"sockette": "^2.0.6",
"typesafe-i18n": "^5.17.2",
"typesafe-i18n": "^5.18.0",
"typescript": "^4.9.4"
},
"scripts": {
Expand Down
30 changes: 15 additions & 15 deletions src/emsdevicevalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,28 @@ class DeviceValue {
// also used with HA as uom
enum DeviceValueUOM : uint8_t {
NONE = 0, // 0
DEGREES, // 1
DEGREES_R, // 2 - relative temperature
PERCENT, // 3
DEGREES, // 1 - °C
DEGREES_R, // 2 - °C (relative temperature)
PERCENT, // 3 - %
LMIN, // 4 - l/min
KWH, // 5 - kWh
WH, // 6 - Wh
HOURS, // 7
MINUTES, // 8
HOURS, // 7 - h
MINUTES, // 8 - m
UA, // 9 - µA
BAR, // 10
BAR, // 10 - bar
KW, // 11 - kW
W, // 12
KB, // 13
SECONDS, // 14
W, // 12 - W
KB, // 13 - kB
SECONDS, // 14 - s
DBM, // 15 - dBm
FAHRENHEIT, // 16
FAHRENHEIT, // 16 - °F
MV, // 17 - mV
SQM, // 18 - square meter
M3, // 19 - cubic meter
L, // 20 - liter
KMIN, // 21 - Kelvin * minutes
K, // 22 - Kelvin
SQM, // 18 -
M3, // 19 -
L, // 20 - L
KMIN, // 21 - K*min
K, // 22 - K
CONNECTIVITY // 23 - used in HA
};

Expand Down
6 changes: 3 additions & 3 deletions src/locale_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ MAKE_PSTR_LIST(tpl_input, "Format: <inv>[<evu1><evu2><evu3><comp><aux><cool><hea
MAKE_PSTR_LIST(tpl_input4, "Format: <inv>[<comp><aux><cool><heat><dhw><pv>]")

// Unit Of Measurement mapping - maps to DeviceValueUOM_s in emsdevice.cpp
// Translating hours/minute/seconds in emsdevice.cpp
// Translating hours/minute/seconds are done in emsdevice.cpp (uom_to_string())
MAKE_PSTR(uom_blank, " ")
MAKE_PSTR(uom_percent, "%")
MAKE_PSTR(uom_degrees, "°C")
Expand All @@ -208,13 +208,13 @@ MAKE_PSTR(uom_ua, "µA")
MAKE_PSTR(uom_lmin, "l/min")
MAKE_PSTR(uom_kw, "kW")
MAKE_PSTR(uom_w, "W")
MAKE_PSTR(uom_kb, "KB")
MAKE_PSTR(uom_kb, "kB")
MAKE_PSTR(uom_dbm, "dBm")
MAKE_PSTR(uom_fahrenheit, "°F")
MAKE_PSTR(uom_mv, "mV")
MAKE_PSTR(uom_sqm, "m²")
MAKE_PSTR(uom_m3, "m³")
MAKE_PSTR(uom_l, "l")
MAKE_PSTR(uom_l, "L")
MAKE_PSTR(uom_kmin, "K*min")
MAKE_PSTR(uom_k, "K")

Expand Down
24 changes: 13 additions & 11 deletions src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,10 @@ MAKE_PSTR_WORD(measurement)
MAKE_PSTR_WORD(total_increasing)
MAKE_PSTR(icondegrees, "mdi:coolant-temperature") // DeviceValueUOM::DEGREES
MAKE_PSTR(iconpercent, "mdi:percent-outline") // DeviceValueUOM::PERCENT
MAKE_PSTR(icontime, "mdi:clock-outline") // DeviceValueUOM::SECONDS MINUTES & HOURS
MAKE_PSTR(iconkb, "mdi:memory") // DeviceValueUOM::KB
MAKE_PSTR(iconlmin, "mdi:water-boiler") // DeviceValueUOM::LMIN
// MAKE_PSTR(iconkwh, "mdi:transmission-tower") // DeviceValueUOM::KWH & WH
MAKE_PSTR(iconua, "mdi:lightning-bolt-circle") // DeviceValueUOM::UA
// MAKE_PSTR(iconbar, "mdi:gauge") // DeviceValueUOM::BAR
// MAKE_PSTR(iconkw, "mdi:omega") // DeviceValueUOM::KW & W
// MAKE_PSTR(icondbm, "mdi:wifi-strength-2") // DeviceValueUOM::DBM
MAKE_PSTR(iconnum, "mdi:counter") // DeviceValueUOM::NONE
// MAKE_PSTR(icondevice, "mdi:home-automation") // for devices in HA
MAKE_PSTR(iconua, "mdi:lightning-bolt-circle") // DeviceValueUOM::UA
MAKE_PSTR(iconnum, "mdi:counter") // DeviceValueUOM::NONE

uuid::log::Logger Mqtt::logger_{F_(mqtt), uuid::log::Facility::DAEMON};

Expand Down Expand Up @@ -1171,8 +1165,16 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
doc["payload_off"] = Helpers::render_boolean(result, false);
doc[sc_ha] = F_(measurement);
} else {
// always set the uom
if (uom != DeviceValueUOM::NONE) {
// always set the uom, using the standards except for hours/minutes/seconds
// using HA specific codes from https://github.com/home-assistant/core/blob/dev/homeassistant/const.py
if (uom == DeviceValueUOM::HOURS) {
doc[uom_ha] = "h";
} else if (uom == DeviceValueUOM::MINUTES) {
doc[uom_ha] = "min";
} else if (uom == DeviceValueUOM::SECONDS) {
doc[uom_ha] = "s";
} else if (uom != DeviceValueUOM::NONE) {
// default
doc[uom_ha] = EMSdevice::uom_to_string(uom);
}
}
Expand All @@ -1196,12 +1198,12 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
case DeviceValueUOM::SECONDS:
case DeviceValueUOM::MINUTES:
case DeviceValueUOM::HOURS:
doc[ic_ha] = F_(icontime);
if (type == DeviceValueType::TIME) {
doc[sc_ha] = F_(total_increasing);
} else {
doc[sc_ha] = F_(measurement);
}
doc[dc_ha] = "duration"; // https://github.com/emsesp/EMS-ESP32/issues/822
break;
case DeviceValueUOM::KB:
doc[ic_ha] = F_(iconkb);
Expand Down

0 comments on commit 3c91ac2

Please sign in to comment.