Improve zwave_js test coverage (#83372)
* Improve zwave_js test coverage * review comments and clean up testpull/83425/head
parent
dc3401c94e
commit
8d1a70391e
|
@ -71,30 +71,26 @@ class ZwaveNumberEntity(ZWaveBaseEntity, NumberEntity):
|
||||||
@property
|
@property
|
||||||
def native_min_value(self) -> float:
|
def native_min_value(self) -> float:
|
||||||
"""Return the minimum value."""
|
"""Return the minimum value."""
|
||||||
if self.info.primary_value.metadata.min is None:
|
min_ = self.info.primary_value.metadata.min
|
||||||
return 0
|
return float(0 if min_ is None else min_)
|
||||||
return float(self.info.primary_value.metadata.min)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_max_value(self) -> float:
|
def native_max_value(self) -> float:
|
||||||
"""Return the maximum value."""
|
"""Return the maximum value."""
|
||||||
if self.info.primary_value.metadata.max is None:
|
max_ = self.info.primary_value.metadata.max
|
||||||
return 255
|
return float(255 if max_ is None else max_)
|
||||||
return float(self.info.primary_value.metadata.max)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> float | None:
|
def native_value(self) -> float | None:
|
||||||
"""Return the entity value."""
|
"""Return the entity value."""
|
||||||
if self.info.primary_value.value is None:
|
value = self.info.primary_value.value
|
||||||
return None
|
return None if value is None else float(value)
|
||||||
return float(self.info.primary_value.value)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_unit_of_measurement(self) -> str | None:
|
def native_unit_of_measurement(self) -> str | None:
|
||||||
"""Return the unit of measurement of this entity, if any."""
|
"""Return the unit of measurement of this entity, if any."""
|
||||||
if self.info.primary_value.metadata.unit is None:
|
unit = self.info.primary_value.metadata.unit
|
||||||
return None
|
return None if unit is None else str(unit)
|
||||||
return str(self.info.primary_value.metadata.unit)
|
|
||||||
|
|
||||||
async def async_set_native_value(self, value: float) -> None:
|
async def async_set_native_value(self, value: float) -> None:
|
||||||
"""Set new value."""
|
"""Set new value."""
|
||||||
|
|
|
@ -87,6 +87,26 @@ def get_device(hass, node):
|
||||||
return dev_reg.async_get_device({device_id})
|
return dev_reg.async_get_device({device_id})
|
||||||
|
|
||||||
|
|
||||||
|
async def test_no_driver(
|
||||||
|
hass, client, multisensor_6, controller_state, integration, hass_ws_client
|
||||||
|
):
|
||||||
|
"""Test driver missing results in error."""
|
||||||
|
entry = integration
|
||||||
|
ws_client = await hass_ws_client(hass)
|
||||||
|
client.driver = None
|
||||||
|
|
||||||
|
# Try API call with entry ID
|
||||||
|
await ws_client.send_json(
|
||||||
|
{
|
||||||
|
ID: 1,
|
||||||
|
TYPE: "zwave_js/network_status",
|
||||||
|
ENTRY_ID: entry.entry_id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
msg = await ws_client.receive_json()
|
||||||
|
assert not msg["success"]
|
||||||
|
|
||||||
|
|
||||||
async def test_network_status(
|
async def test_network_status(
|
||||||
hass, multisensor_6, controller_state, integration, hass_ws_client
|
hass, multisensor_6, controller_state, integration, hass_ws_client
|
||||||
):
|
):
|
||||||
|
|
|
@ -267,6 +267,31 @@ async def test_fibaro_FGR222_shutter_cover(
|
||||||
}
|
}
|
||||||
assert args["value"] == 0
|
assert args["value"] == 0
|
||||||
|
|
||||||
|
# Test some tilt
|
||||||
|
event = Event(
|
||||||
|
type="value updated",
|
||||||
|
data={
|
||||||
|
"source": "node",
|
||||||
|
"event": "value updated",
|
||||||
|
"nodeId": 42,
|
||||||
|
"args": {
|
||||||
|
"commandClassName": "Manufacturer Proprietary",
|
||||||
|
"commandClass": 145,
|
||||||
|
"endpoint": 0,
|
||||||
|
"property": "fibaro",
|
||||||
|
"propertyKey": "venetianBlindsTilt",
|
||||||
|
"newValue": 99,
|
||||||
|
"prevValue": 0,
|
||||||
|
"propertyName": "fibaro",
|
||||||
|
"propertyKeyName": "venetianBlindsTilt",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
fibaro_fgr222_shutter.receive_event(event)
|
||||||
|
state = hass.states.get(FIBARO_SHUTTER_COVER_ENTITY)
|
||||||
|
assert state
|
||||||
|
assert state.attributes[ATTR_CURRENT_TILT_POSITION] == 100
|
||||||
|
|
||||||
|
|
||||||
async def test_aeotec_nano_shutter_cover(
|
async def test_aeotec_nano_shutter_cover(
|
||||||
hass, client, aeotec_nano_shutter, integration
|
hass, client, aeotec_nano_shutter, integration
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
"""Test the Z-Wave JS number platform."""
|
"""Test the Z-Wave JS number platform."""
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
from zwave_js_server.event import Event
|
from zwave_js_server.event import Event
|
||||||
|
|
||||||
from homeassistant.const import STATE_UNKNOWN
|
from homeassistant.const import STATE_UNKNOWN
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
from .common import BASIC_NUMBER_ENTITY
|
from .common import BASIC_NUMBER_ENTITY
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
NUMBER_ENTITY = "number.thermostat_hvac_valve_control"
|
NUMBER_ENTITY = "number.thermostat_hvac_valve_control"
|
||||||
VOLUME_NUMBER_ENTITY = "number.indoor_siren_6_default_volume_2"
|
VOLUME_NUMBER_ENTITY = "number.indoor_siren_6_default_volume_2"
|
||||||
|
|
||||||
|
@ -63,6 +69,66 @@ async def test_number(hass, client, aeotec_radiator_thermostat, integration):
|
||||||
assert state.state == "99.0"
|
assert state.state == "99.0"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(name="no_target_value")
|
||||||
|
def mock_client_fixture():
|
||||||
|
"""Mock no target_value."""
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.zwave_js.number.ZwaveNumberEntity.get_zwave_value",
|
||||||
|
return_value=None,
|
||||||
|
):
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
async def test_number_no_target_value(
|
||||||
|
hass, client, no_target_value, aeotec_radiator_thermostat, integration
|
||||||
|
):
|
||||||
|
"""Test the number entity with no target value."""
|
||||||
|
# Test turn on setting value fails
|
||||||
|
with pytest.raises(HomeAssistantError):
|
||||||
|
await hass.services.async_call(
|
||||||
|
"number",
|
||||||
|
"set_value",
|
||||||
|
{"entity_id": NUMBER_ENTITY, "value": 30},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_number_writeable(hass, client, aeotec_radiator_thermostat):
|
||||||
|
"""Test the number entity where current value is writeable."""
|
||||||
|
aeotec_radiator_thermostat.values["4-38-0-currentValue"].metadata.data[
|
||||||
|
"writeable"
|
||||||
|
] = True
|
||||||
|
aeotec_radiator_thermostat.values.pop("4-38-0-targetValue")
|
||||||
|
|
||||||
|
# set up config entry
|
||||||
|
entry = MockConfigEntry(domain="zwave_js", data={"url": "ws://test.org"})
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
# Test turn on setting value
|
||||||
|
await hass.services.async_call(
|
||||||
|
"number",
|
||||||
|
"set_value",
|
||||||
|
{"entity_id": NUMBER_ENTITY, "value": 30},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert len(client.async_send_command.call_args_list) == 1
|
||||||
|
args = client.async_send_command.call_args[0][0]
|
||||||
|
assert args["command"] == "node.set_value"
|
||||||
|
assert args["nodeId"] == 4
|
||||||
|
assert args["valueId"] == {
|
||||||
|
"commandClass": 38,
|
||||||
|
"endpoint": 0,
|
||||||
|
"property": "currentValue",
|
||||||
|
}
|
||||||
|
assert args["value"] == 30.0
|
||||||
|
|
||||||
|
client.async_send_command.reset_mock()
|
||||||
|
|
||||||
|
|
||||||
async def test_volume_number(hass, client, aeotec_zw164_siren, integration):
|
async def test_volume_number(hass, client, aeotec_zw164_siren, integration):
|
||||||
"""Test the volume number entity."""
|
"""Test the volume number entity."""
|
||||||
node = aeotec_zw164_siren
|
node = aeotec_zw164_siren
|
||||||
|
|
Loading…
Reference in New Issue