Repository: home-assistant/core (Python)

Issue:
zwave_js KeyError during RebuildRoutes
### The problem

I started "Rebuild Network Routes" via the Home Assistant user interface and received the error traceback below.  

I also have zwave_js UI add-on, but did not use it to start the rebuild process.  

Node 3 is a valid node, and as best I can tell there were no issues with it before, during or after the route rebuild.  I don't have a Node 2.

While there may be some underlying device issue (not the focus of this bug report), I would assume that the HA integration should better handle this.

### What version of Home Assistant Core has the issue?

2023.11.2

### What was the last working version of Home Assistant Core?

unknown

### What type of installation are you running?

Home Assistant OS

### Integration causing the issue

zwave_js

### Link to integration documentation on our website

https://www.home-assistant.io/integrations/zwave_js

### Diagnostics information

[config_entry-zwave_js-564fc8effdabfd5359b34b4a5b16215c.json-2.txt](https://github.com/home-assistant/core/files/13328873/config_entry-zwave_js-564fc8effdabfd5359b34b4a5b16215c.json-2.txt)


### Example YAML snippet

```yaml
n/a
```


### Anything in the logs that might be useful for us?

```txt
Logger: homeassistant.components.zwave_js
Source: components/zwave_js/__init__.py:888
Integration: Z-Wave (documentation, issues)
First occurred: November 10, 2023 at 12:25:34 PM (43 occurrences)
Last logged: November 10, 2023 at 12:40:27 PM

Unexpected exception: '3'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/zwave_js/__init__.py", line 888, in client_listen
    await client.listen(driver_ready)
  File "/usr/local/lib/python3.11/site-packages/zwave_js_server/client.py", line 284, in listen
    await self.receive_until_closed()
  File "/usr/local/lib/python3.11/site-packages/zwave_js_server/client.py", line 443, in receive_until_closed
    self._handle_incoming_message(data)
  File "/usr/local/lib/python3.11/site-packages/zwave_js_server/client.py", line 532, in _handle_incoming_message
    self.driver.receive_event(event)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/zwave_js_server/model/driver.py", line 86, in receive_event
    self.controller.receive_event(event)
  File "/usr/local/lib/python3.11/site-packages/zwave_js_server/model/controller/__init__.py", line 851, in receive_event
    self._handle_event_protocol(event)
  File "/usr/local/lib/python3.11/site-packages/zwave_js_server/event.py", line 72, in _handle_event_protocol
    handler(event)
  File "/usr/local/lib/python3.11/site-packages/zwave_js_server/model/controller/__init__.py", line 904, in handle_rebuild_routes_progress
    self._rebuild_routes_progress = {
                                    ^
  File "/usr/local/lib/python3.11/site-packages/zwave_js_server/model/controller/__init__.py", line 905, in <dictcomp>
    self.nodes[node_id]: RebuildRoutesStatus(status)
    ~~~~~~~~~~^^^^^^^^^
KeyError: '3'
 
```
```


### Additional information

_No response_



Fix (patch):
diff --git a/homeassistant/components/scene.py b/homeassistant/components/scene.py
index 7c96230ccd49c4..ce1a324254297c 100644
--- a/homeassistant/components/scene.py
+++ b/homeassistant/components/scene.py
@@ -73,8 +73,9 @@ def _process_config(scene_config):
 
     for entity_id in c_entities:
         if isinstance(c_entities[entity_id], dict):
-            state = c_entities[entity_id].pop('state', None)
-            attributes = c_entities[entity_id]
+            entity_attrs = c_entities[entity_id].copy()
+            state = entity_attrs.pop('state', None)
+            attributes = entity_attrs
         else:
             state = c_entities[entity_id]
             attributes = {}