mirror of
https://github.com/home-assistant/core.git
synced 2025-07-12 15:57:06 +00:00
Revert "Check if the unit of measurement is valid before creating the entity" (#140155)
Revert "Check if the unit of measurement is valid before creating the entity …" This reverts commit 99e1a7a676b2fc14f9f8a8db64bee2840fae4646.
This commit is contained in:
parent
134b5319e1
commit
61f0eabcbb
@ -11,7 +11,6 @@ import voluptuous as vol
|
|||||||
from homeassistant.components import sensor
|
from homeassistant.components import sensor
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
CONF_STATE_CLASS,
|
CONF_STATE_CLASS,
|
||||||
DEVICE_CLASS_UNITS,
|
|
||||||
DEVICE_CLASSES_SCHEMA,
|
DEVICE_CLASSES_SCHEMA,
|
||||||
ENTITY_ID_FORMAT,
|
ENTITY_ID_FORMAT,
|
||||||
STATE_CLASSES_SCHEMA,
|
STATE_CLASSES_SCHEMA,
|
||||||
@ -108,20 +107,6 @@ def validate_sensor_state_and_device_class_config(config: ConfigType) -> ConfigT
|
|||||||
f"got `{CONF_DEVICE_CLASS}` '{device_class}'"
|
f"got `{CONF_DEVICE_CLASS}` '{device_class}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
if (device_class := config.get(CONF_DEVICE_CLASS)) is None or (
|
|
||||||
unit_of_measurement := config.get(CONF_UNIT_OF_MEASUREMENT)
|
|
||||||
) is None:
|
|
||||||
return config
|
|
||||||
|
|
||||||
if (
|
|
||||||
device_class in DEVICE_CLASS_UNITS
|
|
||||||
and unit_of_measurement not in DEVICE_CLASS_UNITS[device_class]
|
|
||||||
):
|
|
||||||
raise vol.Invalid(
|
|
||||||
f"The unit of measurement `{unit_of_measurement}` is not valid "
|
|
||||||
f"together with device class `{device_class}`"
|
|
||||||
)
|
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
@ -870,32 +870,6 @@ async def test_invalid_device_class(
|
|||||||
assert "expected SensorDeviceClass or one of" in caplog.text
|
assert "expected SensorDeviceClass or one of" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"hass_config",
|
|
||||||
[
|
|
||||||
{
|
|
||||||
mqtt.DOMAIN: {
|
|
||||||
sensor.DOMAIN: {
|
|
||||||
"name": "test",
|
|
||||||
"state_topic": "test-topic",
|
|
||||||
"device_class": "energy",
|
|
||||||
"unit_of_measurement": "ppm",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
)
|
|
||||||
async def test_invalid_unit_of_measurement(
|
|
||||||
mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture
|
|
||||||
) -> None:
|
|
||||||
"""Test device_class with invalid unit of measurement."""
|
|
||||||
assert await mqtt_mock_entry()
|
|
||||||
assert (
|
|
||||||
"The unit of measurement `ppm` is not valid together with device class `energy`"
|
|
||||||
in caplog.text
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"hass_config",
|
"hass_config",
|
||||||
[
|
[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user