mirror of
https://github.com/home-assistant/core.git
synced 2025-11-10 03:19:34 +00:00
Make sure sensor state value is not None prior to trying to used the scaled value (#71189)
This commit is contained in:
@@ -785,6 +785,36 @@ async def test_add_new_sensor(hass, aioclient_mock, mock_deconz_websocket):
|
||||
assert hass.states.get("sensor.light_level_sensor").state == "999.8"
|
||||
|
||||
|
||||
BAD_SENSOR_DATA = [
|
||||
("ZHAConsumption", "consumption"),
|
||||
("ZHAHumidity", "humidity"),
|
||||
("ZHALightLevel", "lightlevel"),
|
||||
("ZHATemperature", "temperature"),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("sensor_type, sensor_property", BAD_SENSOR_DATA)
|
||||
async def test_dont_add_sensor_if_state_is_none(
|
||||
hass, aioclient_mock, sensor_type, sensor_property
|
||||
):
|
||||
"""Test sensor with scaled data is not created if state is None."""
|
||||
data = {
|
||||
"sensors": {
|
||||
"1": {
|
||||
"name": "Sensor 1",
|
||||
"type": sensor_type,
|
||||
"state": {sensor_property: None},
|
||||
"config": {},
|
||||
"uniqueid": "00:00:00:00:00:00:00:00-00",
|
||||
}
|
||||
}
|
||||
}
|
||||
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||
await setup_deconz_integration(hass, aioclient_mock)
|
||||
|
||||
assert len(hass.states.async_all()) == 0
|
||||
|
||||
|
||||
async def test_add_battery_later(hass, aioclient_mock, mock_deconz_websocket):
|
||||
"""Test that a sensor without an initial battery state creates a battery sensor once state exist."""
|
||||
data = {
|
||||
|
||||
Reference in New Issue
Block a user