Improve test coverage for zwave_js (#93262)
This commit is contained in:
parent
5bc825a8ab
commit
ec12d9a197
3 changed files with 77 additions and 0 deletions
tests/components/zwave_js
24
tests/components/zwave_js/test_helpers.py
Normal file
24
tests/components/zwave_js/test_helpers.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
"""Test the Z-Wave JS helpers module."""
|
||||||
|
from homeassistant.components.zwave_js.helpers import (
|
||||||
|
async_get_node_status_sensor_entity_id,
|
||||||
|
async_get_nodes_from_area_id,
|
||||||
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import area_registry as ar, device_registry as dr
|
||||||
|
|
||||||
|
|
||||||
|
async def test_async_get_node_status_sensor_entity_id(hass: HomeAssistant) -> None:
|
||||||
|
"""Test async_get_node_status_sensor_entity_id for non zwave_js device."""
|
||||||
|
dev_reg = dr.async_get(hass)
|
||||||
|
device = dev_reg.async_get_or_create(
|
||||||
|
config_entry_id="123",
|
||||||
|
identifiers={("test", "test")},
|
||||||
|
)
|
||||||
|
assert async_get_node_status_sensor_entity_id(hass, device.id) is None
|
||||||
|
|
||||||
|
|
||||||
|
async def test_async_get_nodes_from_area_id(hass: HomeAssistant) -> None:
|
||||||
|
"""Test async_get_nodes_from_area_id."""
|
||||||
|
area_reg = ar.async_get(hass)
|
||||||
|
area = area_reg.async_create("test")
|
||||||
|
assert not async_get_nodes_from_area_id(hass, area.id)
|
|
@ -20,6 +20,7 @@ from homeassistant.const import (
|
||||||
SERVICE_TURN_ON,
|
SERVICE_TURN_ON,
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
|
STATE_UNKNOWN,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
@ -914,3 +915,39 @@ async def test_dehumidifier(
|
||||||
"property": "mode",
|
"property": "mode",
|
||||||
}
|
}
|
||||||
assert args["value"] == int(HumidityControlMode.DEHUMIDIFY)
|
assert args["value"] == int(HumidityControlMode.DEHUMIDIFY)
|
||||||
|
|
||||||
|
# Test setting value to None
|
||||||
|
event = Event(
|
||||||
|
type="value updated",
|
||||||
|
data={
|
||||||
|
"source": "node",
|
||||||
|
"event": "value updated",
|
||||||
|
"nodeId": 68,
|
||||||
|
"args": {
|
||||||
|
"commandClassName": "Humidity Control Mode",
|
||||||
|
"commandClass": CommandClass.HUMIDITY_CONTROL_MODE,
|
||||||
|
"endpoint": 0,
|
||||||
|
"property": "mode",
|
||||||
|
"propertyName": "mode",
|
||||||
|
"newValue": None,
|
||||||
|
"prevValue": int(HumidityControlMode.OFF),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
node.receive_event(event)
|
||||||
|
|
||||||
|
state = hass.states.get(HUMIDIFIER_ADC_T3000_ENTITY)
|
||||||
|
|
||||||
|
assert state
|
||||||
|
assert state.state == STATE_UNKNOWN
|
||||||
|
|
||||||
|
client.async_send_command.reset_mock()
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
HUMIDIFIER_DOMAIN,
|
||||||
|
SERVICE_TURN_ON,
|
||||||
|
{ATTR_ENTITY_ID: HUMIDIFIER_ADC_T3000_ENTITY},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert len(client.async_send_command.call_args_list) == 0
|
||||||
|
|
|
@ -776,3 +776,19 @@ async def test_update_entity_full_restore_data_no_update_available(
|
||||||
assert state.state == STATE_OFF
|
assert state.state == STATE_OFF
|
||||||
assert state.attributes[ATTR_SKIPPED_VERSION] is None
|
assert state.attributes[ATTR_SKIPPED_VERSION] is None
|
||||||
assert state.attributes[ATTR_LATEST_VERSION] == "10.7"
|
assert state.attributes[ATTR_LATEST_VERSION] == "10.7"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_update_entity_unload_asleep_node(
|
||||||
|
hass: HomeAssistant, client, wallmote_central_scene, integration
|
||||||
|
) -> None:
|
||||||
|
"""Test unloading config entry after attempting an update for an asleep node."""
|
||||||
|
assert len(client.async_send_command.call_args_list) == 0
|
||||||
|
|
||||||
|
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=5, days=1))
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert len(client.async_send_command.call_args_list) == 0
|
||||||
|
assert len(wallmote_central_scene._listeners["wake up"]) == 2
|
||||||
|
|
||||||
|
await hass.config_entries.async_unload(integration.entry_id)
|
||||||
|
assert len(wallmote_central_scene._listeners["wake up"]) == 0
|
||||||
|
|
Loading…
Add table
Reference in a new issue