Fix mqt sensor unit validation, fix openweather snapshot

This commit is contained in:
jbouwh 2025-06-01 19:55:41 +00:00
parent 4b0db92a2a
commit 1c666150aa
2 changed files with 19 additions and 20 deletions

View File

@ -128,15 +128,14 @@ def validate_sensor_state_and_device_class_config(config: ConfigType) -> ConfigT
f"together with state class '{state_class}'"
)
if (device_class := config.get(CONF_DEVICE_CLASS)) is None or (
unit_of_measurement := config.get(CONF_UNIT_OF_MEASUREMENT)
) in EQUIVALENT_UNITS:
unit_of_measurement = EQUIVALENT_UNITS[unit_of_measurement]
config[CONF_UNIT_OF_MEASUREMENT] = unit_of_measurement
if (unit_of_measurement := config.get(CONF_UNIT_OF_MEASUREMENT)) is None:
return config
if (
device_class := config.get(CONF_DEVICE_CLASS)
) is None or unit_of_measurement is None:
config[CONF_UNIT_OF_MEASUREMENT] = EQUIVALENT_UNITS.get(
unit_of_measurement, unit_of_measurement
)
if (device_class := config.get(CONF_DEVICE_CLASS)) is None:
return config
if (

View File

@ -140,7 +140,7 @@
'supported_features': 0,
'translation_key': None,
'unique_id': '12.34-56.78-no2',
'unit_of_measurement': 'µg/m³',
'unit_of_measurement': 'μg/m³',
})
# ---
# name: test_sensor_states[air_pollution][sensor.openweathermap_nitrogen_dioxide-state]
@ -150,7 +150,7 @@
'device_class': 'nitrogen_dioxide',
'friendly_name': 'openweathermap Nitrogen dioxide',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': 'µg/m³',
'unit_of_measurement': 'μg/m³',
}),
'context': <ANY>,
'entity_id': 'sensor.openweathermap_nitrogen_dioxide',
@ -194,7 +194,7 @@
'supported_features': 0,
'translation_key': None,
'unique_id': '12.34-56.78-no',
'unit_of_measurement': 'µg/m³',
'unit_of_measurement': 'μg/m³',
})
# ---
# name: test_sensor_states[air_pollution][sensor.openweathermap_nitrogen_monoxide-state]
@ -204,7 +204,7 @@
'device_class': 'nitrogen_monoxide',
'friendly_name': 'openweathermap Nitrogen monoxide',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': 'µg/m³',
'unit_of_measurement': 'μg/m³',
}),
'context': <ANY>,
'entity_id': 'sensor.openweathermap_nitrogen_monoxide',
@ -248,7 +248,7 @@
'supported_features': 0,
'translation_key': None,
'unique_id': '12.34-56.78-o3',
'unit_of_measurement': 'µg/m³',
'unit_of_measurement': 'μg/m³',
})
# ---
# name: test_sensor_states[air_pollution][sensor.openweathermap_ozone-state]
@ -258,7 +258,7 @@
'device_class': 'ozone',
'friendly_name': 'openweathermap Ozone',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': 'µg/m³',
'unit_of_measurement': 'μg/m³',
}),
'context': <ANY>,
'entity_id': 'sensor.openweathermap_ozone',
@ -302,7 +302,7 @@
'supported_features': 0,
'translation_key': None,
'unique_id': '12.34-56.78-pm10',
'unit_of_measurement': 'µg/m³',
'unit_of_measurement': 'μg/m³',
})
# ---
# name: test_sensor_states[air_pollution][sensor.openweathermap_pm10-state]
@ -312,7 +312,7 @@
'device_class': 'pm10',
'friendly_name': 'openweathermap PM10',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': 'µg/m³',
'unit_of_measurement': 'μg/m³',
}),
'context': <ANY>,
'entity_id': 'sensor.openweathermap_pm10',
@ -356,7 +356,7 @@
'supported_features': 0,
'translation_key': None,
'unique_id': '12.34-56.78-pm2_5',
'unit_of_measurement': 'µg/m³',
'unit_of_measurement': 'μg/m³',
})
# ---
# name: test_sensor_states[air_pollution][sensor.openweathermap_pm2_5-state]
@ -366,7 +366,7 @@
'device_class': 'pm25',
'friendly_name': 'openweathermap PM2.5',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': 'µg/m³',
'unit_of_measurement': 'μg/m³',
}),
'context': <ANY>,
'entity_id': 'sensor.openweathermap_pm2_5',
@ -410,7 +410,7 @@
'supported_features': 0,
'translation_key': None,
'unique_id': '12.34-56.78-so2',
'unit_of_measurement': 'µg/m³',
'unit_of_measurement': 'μg/m³',
})
# ---
# name: test_sensor_states[air_pollution][sensor.openweathermap_sulphur_dioxide-state]
@ -420,7 +420,7 @@
'device_class': 'sulphur_dioxide',
'friendly_name': 'openweathermap Sulphur dioxide',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': 'µg/m³',
'unit_of_measurement': 'μg/m³',
}),
'context': <ANY>,
'entity_id': 'sensor.openweathermap_sulphur_dioxide',