Skip to content

Commit

Permalink
fix(mqtt): Fix unit_of_measurement for current statistics and consuma…
Browse files Browse the repository at this point in the history
…bles
  • Loading branch information
Hypfer committed Nov 23, 2021
1 parent 4c01842 commit 7f052dc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class ConsumableMonitoringCapabilityMqttHandle extends CapabilityMqttHandle {
baseTopicReference: HassAnchor.getTopicReference(HassAnchor.REFERENCE.HASS_CONSUMABLE_STATE + topicId),
autoconf: {
state_topic: HassAnchor.getTopicReference(HassAnchor.REFERENCE.HASS_CONSUMABLE_STATE + topicId),
unit_of_measurement: unit === stateAttrs.ConsumableStateAttribute.UNITS.PERCENT ? "Percent" : "Minutes",
unit_of_measurement: unit === stateAttrs.ConsumableStateAttribute.UNITS.PERCENT ? Unit.PERCENT : Unit.MINUTES,
icon: "mdi:progress-wrench",
entity_category: EntityCategory.DIAGNOSTIC
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CurrentStatisticsCapabilityMqttHandle extends CapabilityMqttHandle {
topicName: "time",
friendlyName: "Current Statistics Time",
datatype: DataType.INTEGER,
unit: Unit.SECONDS,
getter: async () => {
return HassAnchor.getAnchor(HassAnchor.ANCHOR.CURRENT_STATISTICS_TIME).getValue();
},
Expand All @@ -63,7 +64,8 @@ class CurrentStatisticsCapabilityMqttHandle extends CapabilityMqttHandle {
autoconf: {
state_topic: prop.getBaseTopic(),
icon: "mdi:equalizer",
entity_category: EntityCategory.DIAGNOSTIC
entity_category: EntityCategory.DIAGNOSTIC,
unit_of_measurement: Unit.SECONDS
}
})
);
Expand Down Expand Up @@ -96,7 +98,8 @@ class CurrentStatisticsCapabilityMqttHandle extends CapabilityMqttHandle {
autoconf: {
state_topic: prop.getBaseTopic(),
icon: "mdi:equalizer",
entity_category: EntityCategory.DIAGNOSTIC
entity_category: EntityCategory.DIAGNOSTIC,
unit_of_measurement: Unit.SQUARE_CENTIMETER
}
})
);
Expand Down
2 changes: 2 additions & 0 deletions backend/lib/mqtt/common/Unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const Unit = Object.freeze({
PSI: "psi",
AMOUNT: "#",
// Not part of the specification, but useful
SECONDS: "seconds",
MINUTES: "minutes",
SQUARE_CENTIMETER: "cm²",
SQUARE_METER: "m²",
CUBE_METER: "m³",
Expand Down

0 comments on commit 7f052dc

Please sign in to comment.