From a9a2e189bac1ef1fb57912d6efd2e1daaa03b5b6 Mon Sep 17 00:00:00 2001 From: jbouwh Date: Tue, 20 May 2025 08:02:33 +0000 Subject: [PATCH] Fix prometheus --- homeassistant/components/prometheus/__init__.py | 4 ++++ tests/components/prometheus/test_init.py | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/prometheus/__init__.py b/homeassistant/components/prometheus/__init__.py index 3adc33e9935..ac0e8f249f5 100644 --- a/homeassistant/components/prometheus/__init__.py +++ b/homeassistant/components/prometheus/__init__.py @@ -366,6 +366,7 @@ class PrometheusMetrics: @staticmethod def _sanitize_metric_name(metric: str) -> str: + metric.replace("\u03bc", "\u00b5") return "".join( [c if c in ALLOWED_METRIC_CHARS else f"u{hex(ord(c))}" for c in metric] ) @@ -747,6 +748,9 @@ class PrometheusMetrics: PERCENTAGE: "percent", } default = unit.replace("/", "_per_") + # Unit conversion for CONCENTRATION_MICROGRAMS_PER_CUBIC_METER "μg/m³" + # "μ" == "\u03bc" but the API uses "\u00b5" + default = default.replace("\u03bc", "\u00b5") default = default.lower() return units.get(unit, default) diff --git a/tests/components/prometheus/test_init.py b/tests/components/prometheus/test_init.py index b197acd3c37..bbd58619b12 100644 --- a/tests/components/prometheus/test_init.py +++ b/tests/components/prometheus/test_init.py @@ -610,7 +610,7 @@ async def test_sensor_unit( EntityMetric( metric_name="sensor_unit_u0xb5g_per_mu0xb3", domain="sensor", - friendly_name="SPS30 PM <1μm Weight concentration", + friendly_name="SPS30 PM <1µm Weight concentration", entity="sensor.sps30_pm_1um_weight_concentration", ).withValue(3.7069).assert_in_metrics(body) @@ -1920,7 +1920,7 @@ async def sensor_fixture( unique_id="sensor_7", unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, suggested_object_id="sps30_pm_1um_weight_concentration", - original_name="SPS30 PM <1μm Weight concentration", + original_name="SPS30 PM <1µm Weight concentration", ) set_state_with_entry(hass, sensor_7, 3.7069) data["sensor_7"] = sensor_7