Make Basic CC Z-Wave values a light (#101438)

This commit is contained in:
Raman Gupta
2023-10-13 11:11:44 -04:00
committed by GitHub
parent 370e3166ee
commit 7d8ea404b3
5 changed files with 175 additions and 36 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ DISABLED_LEGACY_BINARY_SENSOR = "binary_sensor.multisensor_6_any"
NOTIFICATION_MOTION_BINARY_SENSOR = "binary_sensor.multisensor_6_motion_detection"
NOTIFICATION_MOTION_SENSOR = "sensor.multisensor_6_home_security_motion_sensor_status"
INDICATOR_SENSOR = "sensor.z_wave_thermostat_indicator_value"
BASIC_NUMBER_ENTITY = "number.livingroomlight_basic"
BASIC_LIGHT_ENTITY = "light.livingroomlight_basic"
PROPERTY_DOOR_STATUS_BINARY_SENSOR = (
"binary_sensor.august_smart_lock_pro_3rd_gen_the_current_status_of_the_door"
)
+143
View File
@@ -26,9 +26,11 @@ from homeassistant.const import (
STATE_UNKNOWN,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from .common import (
AEON_SMART_SWITCH_LIGHT_ENTITY,
BASIC_LIGHT_ENTITY,
BULB_6_MULTI_COLOR_LIGHT_ENTITY,
EATON_RF9640_ENTITY,
ZEN_31_ENTITY,
@@ -859,3 +861,144 @@ async def test_black_is_off_zdb5100(
"property": "targetColor",
}
assert args["value"] == {"red": 255, "green": 76, "blue": 255}
async def test_basic_cc_light(
hass: HomeAssistant, client, ge_in_wall_dimmer_switch, integration
) -> None:
"""Test light is created from Basic CC."""
node = ge_in_wall_dimmer_switch
ent_reg = er.async_get(hass)
entity_entry = ent_reg.async_get(BASIC_LIGHT_ENTITY)
assert entity_entry
assert not entity_entry.disabled
state = hass.states.get(BASIC_LIGHT_ENTITY)
assert state
assert state.state == STATE_UNKNOWN
assert state.attributes["supported_features"] == 0
# Send value to 0
event = Event(
type="value updated",
data={
"source": "node",
"event": "value updated",
"nodeId": 2,
"args": {
"commandClassName": "Basic",
"commandClass": 32,
"endpoint": 0,
"property": "currentValue",
"newValue": 0,
"prevValue": None,
"propertyName": "currentValue",
},
},
)
node.receive_event(event)
state = hass.states.get(BASIC_LIGHT_ENTITY)
assert state
assert state.state == STATE_OFF
# Turn on light
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": BASIC_LIGHT_ENTITY},
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"] == 2
assert args["valueId"] == {
"commandClass": 32,
"endpoint": 0,
"property": "targetValue",
}
assert args["value"] == 255
# Due to optimistic updates, the state should be on even though the Z-Wave state
# hasn't been updated yet
state = hass.states.get(BASIC_LIGHT_ENTITY)
assert state
assert state.state == STATE_ON
client.async_send_command.reset_mock()
# Send value to 0
event = Event(
type="value updated",
data={
"source": "node",
"event": "value updated",
"nodeId": 2,
"args": {
"commandClassName": "Basic",
"commandClass": 32,
"endpoint": 0,
"property": "currentValue",
"newValue": 0,
"prevValue": None,
"propertyName": "currentValue",
},
},
)
node.receive_event(event)
state = hass.states.get(BASIC_LIGHT_ENTITY)
assert state
assert state.state == STATE_OFF
# Turn on light with brightness
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": BASIC_LIGHT_ENTITY, ATTR_BRIGHTNESS: 128},
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"] == 2
assert args["valueId"] == {
"commandClass": 32,
"endpoint": 0,
"property": "targetValue",
}
assert args["value"] == 50
# Since we specified a brightness, there is no optimistic update so the state
# should be off
state = hass.states.get(BASIC_LIGHT_ENTITY)
assert state
assert state.state == STATE_OFF
client.async_send_command.reset_mock()
# Turn off light
await hass.services.async_call(
"light",
"turn_off",
{"entity_id": BASIC_LIGHT_ENTITY},
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"] == 2
assert args["valueId"] == {
"commandClass": 32,
"endpoint": 0,
"property": "targetValue",
}
assert args["value"] == 0
-14
View File
@@ -9,8 +9,6 @@ from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import entity_registry as er
from .common import BASIC_NUMBER_ENTITY
from tests.common import MockConfigEntry
NUMBER_ENTITY = "number.thermostat_hvac_valve_control"
@@ -219,18 +217,6 @@ async def test_volume_number(
assert state.state == STATE_UNKNOWN
async def test_disabled_basic_number(
hass: HomeAssistant, ge_in_wall_dimmer_switch, integration
) -> None:
"""Test number is created from Basic CC and is disabled."""
ent_reg = er.async_get(hass)
entity_entry = ent_reg.async_get(BASIC_NUMBER_ENTITY)
assert entity_entry
assert entity_entry.disabled
assert entity_entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
async def test_config_parameter_number(
hass: HomeAssistant, climate_adc_t3000, integration
) -> None: