mirror of
https://github.com/home-assistant/core.git
synced 2025-08-01 09:38:21 +00:00
Fix mqt sensor unit validation, fix openweather snapshot
This commit is contained in:
parent
4b0db92a2a
commit
1c666150aa
@ -128,15 +128,14 @@ def validate_sensor_state_and_device_class_config(config: ConfigType) -> ConfigT
|
|||||||
f"together with state class '{state_class}'"
|
f"together with state class '{state_class}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
if (device_class := config.get(CONF_DEVICE_CLASS)) is None or (
|
if (unit_of_measurement := config.get(CONF_UNIT_OF_MEASUREMENT)) is None:
|
||||||
unit_of_measurement := config.get(CONF_UNIT_OF_MEASUREMENT)
|
return config
|
||||||
) in EQUIVALENT_UNITS:
|
|
||||||
unit_of_measurement = EQUIVALENT_UNITS[unit_of_measurement]
|
|
||||||
config[CONF_UNIT_OF_MEASUREMENT] = unit_of_measurement
|
|
||||||
|
|
||||||
if (
|
config[CONF_UNIT_OF_MEASUREMENT] = EQUIVALENT_UNITS.get(
|
||||||
device_class := config.get(CONF_DEVICE_CLASS)
|
unit_of_measurement, unit_of_measurement
|
||||||
) is None or unit_of_measurement is None:
|
)
|
||||||
|
|
||||||
|
if (device_class := config.get(CONF_DEVICE_CLASS)) is None:
|
||||||
return config
|
return config
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
@ -140,7 +140,7 @@
|
|||||||
'supported_features': 0,
|
'supported_features': 0,
|
||||||
'translation_key': None,
|
'translation_key': None,
|
||||||
'unique_id': '12.34-56.78-no2',
|
'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]
|
# name: test_sensor_states[air_pollution][sensor.openweathermap_nitrogen_dioxide-state]
|
||||||
@ -150,7 +150,7 @@
|
|||||||
'device_class': 'nitrogen_dioxide',
|
'device_class': 'nitrogen_dioxide',
|
||||||
'friendly_name': 'openweathermap Nitrogen dioxide',
|
'friendly_name': 'openweathermap Nitrogen dioxide',
|
||||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
'unit_of_measurement': 'µg/m³',
|
'unit_of_measurement': 'μg/m³',
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
'entity_id': 'sensor.openweathermap_nitrogen_dioxide',
|
'entity_id': 'sensor.openweathermap_nitrogen_dioxide',
|
||||||
@ -194,7 +194,7 @@
|
|||||||
'supported_features': 0,
|
'supported_features': 0,
|
||||||
'translation_key': None,
|
'translation_key': None,
|
||||||
'unique_id': '12.34-56.78-no',
|
'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]
|
# name: test_sensor_states[air_pollution][sensor.openweathermap_nitrogen_monoxide-state]
|
||||||
@ -204,7 +204,7 @@
|
|||||||
'device_class': 'nitrogen_monoxide',
|
'device_class': 'nitrogen_monoxide',
|
||||||
'friendly_name': 'openweathermap Nitrogen monoxide',
|
'friendly_name': 'openweathermap Nitrogen monoxide',
|
||||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
'unit_of_measurement': 'µg/m³',
|
'unit_of_measurement': 'μg/m³',
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
'entity_id': 'sensor.openweathermap_nitrogen_monoxide',
|
'entity_id': 'sensor.openweathermap_nitrogen_monoxide',
|
||||||
@ -248,7 +248,7 @@
|
|||||||
'supported_features': 0,
|
'supported_features': 0,
|
||||||
'translation_key': None,
|
'translation_key': None,
|
||||||
'unique_id': '12.34-56.78-o3',
|
'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]
|
# name: test_sensor_states[air_pollution][sensor.openweathermap_ozone-state]
|
||||||
@ -258,7 +258,7 @@
|
|||||||
'device_class': 'ozone',
|
'device_class': 'ozone',
|
||||||
'friendly_name': 'openweathermap Ozone',
|
'friendly_name': 'openweathermap Ozone',
|
||||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
'unit_of_measurement': 'µg/m³',
|
'unit_of_measurement': 'μg/m³',
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
'entity_id': 'sensor.openweathermap_ozone',
|
'entity_id': 'sensor.openweathermap_ozone',
|
||||||
@ -302,7 +302,7 @@
|
|||||||
'supported_features': 0,
|
'supported_features': 0,
|
||||||
'translation_key': None,
|
'translation_key': None,
|
||||||
'unique_id': '12.34-56.78-pm10',
|
'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]
|
# name: test_sensor_states[air_pollution][sensor.openweathermap_pm10-state]
|
||||||
@ -312,7 +312,7 @@
|
|||||||
'device_class': 'pm10',
|
'device_class': 'pm10',
|
||||||
'friendly_name': 'openweathermap PM10',
|
'friendly_name': 'openweathermap PM10',
|
||||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
'unit_of_measurement': 'µg/m³',
|
'unit_of_measurement': 'μg/m³',
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
'entity_id': 'sensor.openweathermap_pm10',
|
'entity_id': 'sensor.openweathermap_pm10',
|
||||||
@ -356,7 +356,7 @@
|
|||||||
'supported_features': 0,
|
'supported_features': 0,
|
||||||
'translation_key': None,
|
'translation_key': None,
|
||||||
'unique_id': '12.34-56.78-pm2_5',
|
'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]
|
# name: test_sensor_states[air_pollution][sensor.openweathermap_pm2_5-state]
|
||||||
@ -366,7 +366,7 @@
|
|||||||
'device_class': 'pm25',
|
'device_class': 'pm25',
|
||||||
'friendly_name': 'openweathermap PM2.5',
|
'friendly_name': 'openweathermap PM2.5',
|
||||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
'unit_of_measurement': 'µg/m³',
|
'unit_of_measurement': 'μg/m³',
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
'entity_id': 'sensor.openweathermap_pm2_5',
|
'entity_id': 'sensor.openweathermap_pm2_5',
|
||||||
@ -410,7 +410,7 @@
|
|||||||
'supported_features': 0,
|
'supported_features': 0,
|
||||||
'translation_key': None,
|
'translation_key': None,
|
||||||
'unique_id': '12.34-56.78-so2',
|
'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]
|
# name: test_sensor_states[air_pollution][sensor.openweathermap_sulphur_dioxide-state]
|
||||||
@ -420,7 +420,7 @@
|
|||||||
'device_class': 'sulphur_dioxide',
|
'device_class': 'sulphur_dioxide',
|
||||||
'friendly_name': 'openweathermap Sulphur dioxide',
|
'friendly_name': 'openweathermap Sulphur dioxide',
|
||||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
'unit_of_measurement': 'µg/m³',
|
'unit_of_measurement': 'μg/m³',
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
'entity_id': 'sensor.openweathermap_sulphur_dioxide',
|
'entity_id': 'sensor.openweathermap_sulphur_dioxide',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user