Print expected device class units in error log (#86125)
This commit is contained in:
parent
74ae351ac0
commit
1b97a51b5e
2 changed files with 13 additions and 3 deletions
|
@ -665,6 +665,7 @@ class SensorEntity(Entity):
|
|||
(
|
||||
"Entity %s (%s) is using native unit of measurement '%s' which "
|
||||
"is not a valid unit for the device class ('%s') it is using; "
|
||||
"expected one of %s; "
|
||||
"Please update your configuration if your entity is manually "
|
||||
"configured, otherwise %s"
|
||||
),
|
||||
|
@ -672,6 +673,7 @@ class SensorEntity(Entity):
|
|||
type(self),
|
||||
native_unit_of_measurement,
|
||||
device_class,
|
||||
[str(unit) if unit else "no unit of measurement" for unit in units],
|
||||
report_issue,
|
||||
)
|
||||
|
||||
|
|
|
@ -9,7 +9,11 @@ import pytest
|
|||
from pytest import approx
|
||||
|
||||
from homeassistant.components.number import NumberDeviceClass
|
||||
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
|
||||
from homeassistant.components.sensor import (
|
||||
DEVICE_CLASS_UNITS,
|
||||
SensorDeviceClass,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
PERCENTAGE,
|
||||
|
@ -1403,13 +1407,17 @@ async def test_device_classes_with_invalid_unit_of_measurement(
|
|||
device_class=device_class,
|
||||
native_unit_of_measurement="INVALID!",
|
||||
)
|
||||
|
||||
units = [
|
||||
str(unit) if unit else "no unit of measurement"
|
||||
for unit in DEVICE_CLASS_UNITS.get(device_class, set())
|
||||
]
|
||||
assert await async_setup_component(hass, "sensor", {"sensor": {"platform": "test"}})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (
|
||||
"is using native unit of measurement 'INVALID!' which is not a valid "
|
||||
f"unit for the device class ('{device_class}') it is using"
|
||||
f"unit for the device class ('{device_class}') it is using; "
|
||||
f"expected one of {units}"
|
||||
) in caplog.text
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue