mirror of
https://github.com/home-assistant/core.git
synced 2026-11-23 06:07:01 -04:00
Deprecate temperature conversion in base entity class (#68978)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
co-authored by
Paulus Schoutsen
parent
39cc91dec6
commit
69ee4cd978
@@ -13,6 +13,7 @@ from homeassistant.const import (
|
||||
ATTR_DEVICE_CLASS,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
TEMP_FAHRENHEIT,
|
||||
)
|
||||
from homeassistant.core import Context, HomeAssistantError
|
||||
from homeassistant.helpers import entity, entity_registry
|
||||
@@ -814,6 +815,64 @@ async def test_float_conversion(hass):
|
||||
assert state.state == "3.6"
|
||||
|
||||
|
||||
async def test_temperature_conversion(hass, caplog):
|
||||
"""Test conversion of temperatures."""
|
||||
# Non sensor entity reporting a temperature
|
||||
with patch.object(
|
||||
entity.Entity, "state", PropertyMock(return_value=100)
|
||||
), patch.object(
|
||||
entity.Entity, "unit_of_measurement", PropertyMock(return_value=TEMP_FAHRENHEIT)
|
||||
):
|
||||
ent = entity.Entity()
|
||||
ent.hass = hass
|
||||
ent.entity_id = "hello.world"
|
||||
ent.async_write_ha_state()
|
||||
|
||||
state = hass.states.get("hello.world")
|
||||
assert state is not None
|
||||
assert state.state == "38"
|
||||
assert (
|
||||
"Entity hello.world (<class 'homeassistant.helpers.entity.Entity'>) relies on automatic "
|
||||
"temperature conversion, this will be unsupported in Home Assistant Core 2022.7. "
|
||||
"Please create a bug report" in caplog.text
|
||||
)
|
||||
|
||||
# Sensor entity, not extending SensorEntity, reporting a temperature
|
||||
with patch.object(
|
||||
entity.Entity, "state", PropertyMock(return_value=100)
|
||||
), patch.object(
|
||||
entity.Entity, "unit_of_measurement", PropertyMock(return_value=TEMP_FAHRENHEIT)
|
||||
):
|
||||
ent = entity.Entity()
|
||||
ent.hass = hass
|
||||
ent.entity_id = "sensor.temp"
|
||||
ent.async_write_ha_state()
|
||||
|
||||
state = hass.states.get("sensor.temp")
|
||||
assert state is not None
|
||||
assert state.state == "38"
|
||||
assert (
|
||||
"Temperature sensor sensor.temp (<class 'homeassistant.helpers.entity.Entity'>) "
|
||||
"does not inherit SensorEntity, this will be unsupported in Home Assistant Core "
|
||||
"2022.7.Please create a bug report" in caplog.text
|
||||
)
|
||||
|
||||
# Sensor entity, not extending SensorEntity, not reporting a number
|
||||
with patch.object(
|
||||
entity.Entity, "state", PropertyMock(return_value="really warm")
|
||||
), patch.object(
|
||||
entity.Entity, "unit_of_measurement", PropertyMock(return_value=TEMP_FAHRENHEIT)
|
||||
):
|
||||
ent = entity.Entity()
|
||||
ent.hass = hass
|
||||
ent.entity_id = "sensor.temp"
|
||||
ent.async_write_ha_state()
|
||||
|
||||
state = hass.states.get("sensor.temp")
|
||||
assert state is not None
|
||||
assert state.state == "really warm"
|
||||
|
||||
|
||||
async def test_attribution_attribute(hass):
|
||||
"""Test attribution attribute."""
|
||||
mock_entity = entity.Entity()
|
||||
|
||||
Reference in New Issue
Block a user