1
mirror of https://github.com/home-assistant/core synced 2024-09-06 10:29:55 +02:00

Improve test coverage for zwave_js (#93262)

This commit is contained in:
Raman Gupta 2023-05-22 06:20:01 -04:00 committed by GitHub
parent 5bc825a8ab
commit ec12d9a197
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 77 additions and 0 deletions

View 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)

View File

@ -20,6 +20,7 @@ from homeassistant.const import (
SERVICE_TURN_ON,
STATE_OFF,
STATE_ON,
STATE_UNKNOWN,
)
from homeassistant.core import HomeAssistant
@ -914,3 +915,39 @@ async def test_dehumidifier(
"property": "mode",
}
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

View File

@ -776,3 +776,19 @@ async def test_update_entity_full_restore_data_no_update_available(
assert state.state == STATE_OFF
assert state.attributes[ATTR_SKIPPED_VERSION] is None
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