Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add select entity for zwave_js Door Lock CC #104292

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add select entity for zwave_js Door Lock CC
  • Loading branch information
raman325 committed Nov 21, 2023
commit fe8c6f8b7818cc9de539e9080c28d01a5999cef5
9 changes: 8 additions & 1 deletion homeassistant/components/zwave_js/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,14 @@ class ZWaveDiscoverySchema:
# locks
# Door Lock CC
ZWaveDiscoverySchema(
platform=Platform.LOCK, primary_value=DOOR_LOCK_CURRENT_MODE_SCHEMA
platform=Platform.LOCK,
primary_value=DOOR_LOCK_CURRENT_MODE_SCHEMA,
allow_multi=True,
),
ZWaveDiscoverySchema(
platform=Platform.SELECT,
primary_value=DOOR_LOCK_CURRENT_MODE_SCHEMA,
hint="door_lock",
),
# Only discover the Lock CC if the Door Lock CC isn't also present on the node
ZWaveDiscoverySchema(
Expand Down
28 changes: 26 additions & 2 deletions homeassistant/components/zwave_js/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

from zwave_js_server.client import Client as ZwaveClient
from zwave_js_server.const import TARGET_VALUE_PROPERTY, CommandClass
from zwave_js_server.const.command_class.sound_switch import ToneID
from zwave_js_server.const.command_class.lock import TARGET_MODE_PROPERTY
from zwave_js_server.const.command_class.sound_switch import TONE_ID_PROPERTY, ToneID
from zwave_js_server.model.driver import Driver

from homeassistant.components.select import DOMAIN as SELECT_DOMAIN, SelectEntity
Expand Down Expand Up @@ -46,6 +47,8 @@ def async_add_select(info: ZwaveDiscoveryInfo) -> None:
entities.append(
ZWaveConfigParameterSelectEntity(config_entry, driver, info)
)
elif info.platform_hint == "door_lock":
entities.append(ZWaveDoorLockSelectEntity(config_entry, driver, info))
else:
entities.append(ZwaveSelectEntity(config_entry, driver, info))
async_add_entities(entities)
Expand Down Expand Up @@ -95,6 +98,27 @@ async def async_select_option(self, option: str) -> None:
await self._async_set_value(self.info.primary_value, int(key))


class ZWaveDoorLockSelectEntity(ZwaveSelectEntity):
"""Representation of a Z-Wave door lock CC mode select entity."""

def __init__(
self, config_entry: ConfigEntry, driver: Driver, info: ZwaveDiscoveryInfo
) -> None:
"""Initialize a ZWaveDoorLockSelectEntity entity."""
super().__init__(config_entry, driver, info)
self._target_value = self.get_zwave_value(TARGET_MODE_PROPERTY)

async def async_select_option(self, option: str) -> None:
"""Change the selected option."""
assert self._target_value is not None
key = next(
key
for key, val in self.info.primary_value.metadata.states.items()
if val == option
)
await self._async_set_value(self._target_value, int(key))


class ZWaveConfigParameterSelectEntity(ZwaveSelectEntity):
"""Representation of a Z-Wave config parameter select."""

Expand Down Expand Up @@ -125,7 +149,7 @@ def __init__(
"""Initialize a ZwaveDefaultToneSelectEntity entity."""
super().__init__(config_entry, driver, info)
self._tones_value = self.get_zwave_value(
"toneId", command_class=CommandClass.SOUND_SWITCH
TONE_ID_PROPERTY, command_class=CommandClass.SOUND_SWITCH
)

# Entity class attributes
Expand Down
1 change: 1 addition & 0 deletions tests/components/zwave_js/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ async def test_lock_popp_electric_strike_lock_control(
hass.states.get("binary_sensor.node_62_the_current_status_of_the_door")
is not None
)
assert hass.states.get("select.node_62_current_lock_mode") is not None


async def test_fortrez_ssa3_siren(
Expand Down
27 changes: 27 additions & 0 deletions tests/components/zwave_js/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,30 @@ async def test_config_parameter_select(
state = hass.states.get(select_entity_id)
assert state
assert state.state == "Normal"


async def test_lock_popp_electric_strike_lock_control_select(
hass: HomeAssistant, client, lock_popp_electric_strike_lock_control, integration
) -> None:
"""Test that the Popp Electric Strike Lock Control select entity."""
LOCK_SELECT_ENTITY = "select.node_62_current_lock_mode"
state = hass.states.get(LOCK_SELECT_ENTITY)
assert state
assert state.state == "Unsecured"
await hass.services.async_call(
"select",
"select_option",
{"entity_id": LOCK_SELECT_ENTITY, "option": "UnsecuredWithTimeout"},
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"] == lock_popp_electric_strike_lock_control.node_id
assert args["valueId"] == {
"endpoint": 0,
"commandClass": 98,
"property": "targetMode",
}
assert args["value"] == 1
Loading