Refactor zwave_js.fan and add tests (#93256)
* Refactor zwave_js.fan and add tests * fix const
This commit is contained in:
parent
03300c24da
commit
18eeeaaf68
3 changed files with 86 additions and 27 deletions
|
@ -13,6 +13,7 @@ from homeassistant.components.fan import (
|
|||
ATTR_PRESET_MODE,
|
||||
ATTR_PRESET_MODES,
|
||||
DOMAIN as FAN_DOMAIN,
|
||||
SERVICE_SET_PERCENTAGE,
|
||||
SERVICE_SET_PRESET_MODE,
|
||||
FanEntityFeature,
|
||||
NotValidPresetModeError,
|
||||
|
@ -167,6 +168,50 @@ async def test_generic_fan(
|
|||
assert state.state == "off"
|
||||
assert state.attributes[ATTR_PERCENTAGE] == 0
|
||||
|
||||
client.async_send_command.reset_mock()
|
||||
|
||||
# Test setting percentage to 0
|
||||
await hass.services.async_call(
|
||||
"fan",
|
||||
SERVICE_SET_PERCENTAGE,
|
||||
{"entity_id": entity_id, "percentage": 0},
|
||||
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"] == 17
|
||||
assert args["valueId"] == {
|
||||
"commandClass": 38,
|
||||
"endpoint": 0,
|
||||
"property": "targetValue",
|
||||
}
|
||||
assert args["value"] == 0
|
||||
|
||||
# Test value is None
|
||||
event = Event(
|
||||
type="value updated",
|
||||
data={
|
||||
"source": "node",
|
||||
"event": "value updated",
|
||||
"nodeId": 17,
|
||||
"args": {
|
||||
"commandClassName": "Multilevel Switch",
|
||||
"commandClass": 38,
|
||||
"endpoint": 0,
|
||||
"property": "currentValue",
|
||||
"newValue": None,
|
||||
"prevValue": 0,
|
||||
"propertyName": "currentValue",
|
||||
},
|
||||
},
|
||||
)
|
||||
node.receive_event(event)
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
|
||||
async def test_configurable_speeds_fan(
|
||||
hass: HomeAssistant, client, hs_fc200, integration
|
||||
|
@ -361,6 +406,29 @@ async def test_ge_12730_fan(hass: HomeAssistant, client, ge_12730, integration)
|
|||
assert state.attributes[ATTR_PERCENTAGE_STEP] == pytest.approx(33.3333, rel=1e-3)
|
||||
assert state.attributes[ATTR_PRESET_MODES] == []
|
||||
|
||||
# Test value is None
|
||||
event = Event(
|
||||
type="value updated",
|
||||
data={
|
||||
"source": "node",
|
||||
"event": "value updated",
|
||||
"nodeId": node_id,
|
||||
"args": {
|
||||
"commandClassName": "Multilevel Switch",
|
||||
"commandClass": 38,
|
||||
"endpoint": 0,
|
||||
"property": "currentValue",
|
||||
"newValue": None,
|
||||
"prevValue": 0,
|
||||
"propertyName": "currentValue",
|
||||
},
|
||||
},
|
||||
)
|
||||
node.receive_event(event)
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
|
||||
async def test_inovelli_lzw36(
|
||||
hass: HomeAssistant, client, inovelli_lzw36, integration
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue