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.
pull/52295/head
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
1 changed files with 1 additions and 1 deletions

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: