Warn if unit_of_measurement is set on instances of SensorEntityDescription (#54867)

* Add class BaseEntityDescription without unit_of_measurement

* Refactor according to review comments

* Tweak

* Fix offending integrations

* Fix offending integrations
This commit is contained in:
Erik Montnemery
2021-08-20 15:54:57 +02:00
committed by GitHub
parent e134246cbd
commit 2fa07777cd
6 changed files with 57 additions and 29 deletions

View File

@@ -1,4 +1,5 @@
"""The test for sensor device automation."""
from homeassistant.components.sensor import SensorEntityDescription
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.setup import async_setup_component
from homeassistant.util import dt as dt_util
@@ -49,3 +50,12 @@ async def test_deprecated_last_reset(hass, caplog, enable_custom_integrations):
"update your configuration if state_class is manually configured, otherwise "
"report it to the custom component author."
) in caplog.text
async def test_deprecated_unit_of_measurement(hass, caplog, enable_custom_integrations):
"""Test warning on deprecated unit_of_measurement."""
SensorEntityDescription("catsensor", unit_of_measurement="cats")
assert (
"tests.components.sensor.test_init is setting 'unit_of_measurement' on an "
"instance of SensorEntityDescription"
) in caplog.text