Skip to content

Commit b45baaf

Browse files
committed
Small refactor and better comment
1 parent a1b56c6 commit b45baaf

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

custom_components/victron_mqtt/number.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ def __init__(
8787
installation_id,
8888
)
8989
self._attr_device_class = METRIC_TYPE_TO_DEVICE_CLASS.get(metric.metric_type)
90-
if self._attr_device_class is not None:
91-
self._attr_native_unit_of_measurement = metric.unit_of_measurement
92-
elif metric.metric_type == MetricType.DYNAMIC:
93-
# Dynamic units come from user-configured MQTT topics (e.g.
90+
if self._attr_device_class is not None or metric.metric_type == MetricType.DYNAMIC:
91+
# We need to set the _attr_native_unit_of_measurement in two cases:
92+
# 1. When there known device class which support multiple units. In this case
93+
# we publish what we have and HA will allow convertion to other supported units.
94+
# 2. Dynamic units come from user-configured MQTT topics (e.g.
9495
# SwitchableOutput Settings/Unit) and have no translation file
9596
# entry, so we must set the unit programmatically.
9697
self._attr_native_unit_of_measurement = metric.unit_of_measurement

0 commit comments

Comments
 (0)