Fix Fahrenheit to Celsius conversion in Prometheus exporter (#52212)

const.TEMP_FAHRENHEIT is "°F", but _unit_string converts this to "c",
so the comparison never succeeds and we end up with temperatures in F
but labeled C.
This commit is contained in:
Christopher Masto 2021-06-28 03:19:49 -04:00 committed by GitHub
parent 5c5e43afc1
commit 5d3f3c756f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -397,7 +397,7 @@ class PrometheusMetrics:
try:
value = self.state_as_number(state)
if unit == TEMP_FAHRENHEIT:
if state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_FAHRENHEIT:
value = fahrenheit_to_celsius(value)
_metric.labels(**self._labels(state)).set(value)
except ValueError: