mirror of
https://github.com/home-assistant/core.git
synced 2025-08-05 03:28:18 +00:00
Fix prometheus
This commit is contained in:
parent
eaf536b52e
commit
a9a2e189ba
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user