mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Fix Z-WaveJS inclusion in the background (#138717)
* Fix Z-WaveJS inclusion in the background * improve async handling * just return the `requested_grant` to the driver * handle controller busy state
This commit is contained in:
parent
22c634e626
commit
a003f89a5e
@ -805,7 +805,7 @@ async def websocket_add_node(
|
|||||||
]
|
]
|
||||||
msg[DATA_UNSUBSCRIBE] = unsubs
|
msg[DATA_UNSUBSCRIBE] = unsubs
|
||||||
|
|
||||||
if controller.inclusion_state == InclusionState.INCLUDING:
|
if controller.inclusion_state in (InclusionState.INCLUDING, InclusionState.BUSY):
|
||||||
connection.send_result(
|
connection.send_result(
|
||||||
msg[ID],
|
msg[ID],
|
||||||
True, # Inclusion is already in progress
|
True, # Inclusion is already in progress
|
||||||
@ -883,6 +883,11 @@ async def websocket_subscribe_s2_inclusion(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Subscribe to S2 inclusion initiated by the controller."""
|
"""Subscribe to S2 inclusion initiated by the controller."""
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def async_cleanup() -> None:
|
||||||
|
for unsub in unsubs:
|
||||||
|
unsub()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def forward_dsk(event: dict) -> None:
|
def forward_dsk(event: dict) -> None:
|
||||||
connection.send_message(
|
connection.send_message(
|
||||||
@ -891,9 +896,18 @@ async def websocket_subscribe_s2_inclusion(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
unsub = driver.controller.on("validate dsk and enter pin", forward_dsk)
|
@callback
|
||||||
connection.subscriptions[msg["id"]] = unsub
|
def handle_requested_grant(event: dict) -> None:
|
||||||
msg[DATA_UNSUBSCRIBE] = [unsub]
|
"""Accept the requested security classes without user interaction."""
|
||||||
|
hass.async_create_task(
|
||||||
|
driver.controller.async_grant_security_classes(event["requested_grant"])
|
||||||
|
)
|
||||||
|
|
||||||
|
connection.subscriptions[msg["id"]] = async_cleanup
|
||||||
|
msg[DATA_UNSUBSCRIBE] = unsubs = [
|
||||||
|
driver.controller.on("grant security classes", handle_requested_grant),
|
||||||
|
driver.controller.on("validate dsk and enter pin", forward_dsk),
|
||||||
|
]
|
||||||
connection.send_result(msg[ID])
|
connection.send_result(msg[ID])
|
||||||
|
|
||||||
|
|
||||||
|
@ -5284,6 +5284,20 @@ async def test_subscribe_s2_inclusion(
|
|||||||
assert msg["success"]
|
assert msg["success"]
|
||||||
assert msg["result"] is None
|
assert msg["result"] is None
|
||||||
|
|
||||||
|
# Test receiving requested grant event
|
||||||
|
event = Event(
|
||||||
|
type="grant security classes",
|
||||||
|
data={
|
||||||
|
"source": "controller",
|
||||||
|
"event": "grant security classes",
|
||||||
|
"requested": {
|
||||||
|
"securityClasses": [SecurityClass.S2_UNAUTHENTICATED],
|
||||||
|
"clientSideAuth": False,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
client.driver.receive_event(event)
|
||||||
|
|
||||||
# Test receiving DSK request event
|
# Test receiving DSK request event
|
||||||
event = Event(
|
event = Event(
|
||||||
type="validate dsk and enter pin",
|
type="validate dsk and enter pin",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user