Skip to content

Commit 22b8ad9

Browse files
mattreimfrenck
authored andcommitted
Fix for deCONZ issue - Detected that integration 'deconz' calls device_registry.async_get_or_create referencing a non existing via_device - home-assistant#134539 (home-assistant#150355)
1 parent 26c9d28 commit 22b8ad9

File tree

8 files changed

+27
-42
lines changed

8 files changed

+27
-42
lines changed

homeassistant/components/deconz/entity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def device_info(self) -> DeviceInfo:
177177
"""Return a device description for device registry."""
178178
return DeviceInfo(
179179
identifiers={(DOMAIN, self._group_identifier)},
180-
manufacturer="Dresden Elektronik",
180+
manufacturer="dresden elektronik",
181181
model="deCONZ group",
182182
name=self.group.name,
183183
via_device=(DOMAIN, self.hub.api.config.bridge_id),

homeassistant/components/deconz/hub/hub.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from homeassistant.config_entries import SOURCE_HASSIO
1515
from homeassistant.core import Event, HomeAssistant, callback
1616
from homeassistant.helpers import device_registry as dr, entity_registry as er
17-
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
1817
from homeassistant.helpers.dispatcher import async_dispatcher_send
1918

2019
from ..const import CONF_MASTER_GATEWAY, DOMAIN, HASSIO_CONFIGURATION_URL, PLATFORMS
@@ -169,17 +168,8 @@ def async_connection_status_callback(self, available: bool) -> None:
169168

170169
async def async_update_device_registry(self) -> None:
171170
"""Update device registry."""
172-
if self.api.config.mac is None:
173-
return
174-
175171
device_registry = dr.async_get(self.hass)
176172

177-
# Host device
178-
device_registry.async_get_or_create(
179-
config_entry_id=self.config_entry.entry_id,
180-
connections={(CONNECTION_NETWORK_MAC, self.api.config.mac)},
181-
)
182-
183173
# Gateway service
184174
configuration_url = f"http://{self.config.host}:{self.config.port}"
185175
if self.config_entry.source == SOURCE_HASSIO:
@@ -189,11 +179,10 @@ async def async_update_device_registry(self) -> None:
189179
configuration_url=configuration_url,
190180
entry_type=dr.DeviceEntryType.SERVICE,
191181
identifiers={(DOMAIN, self.api.config.bridge_id)},
192-
manufacturer="Dresden Elektronik",
182+
manufacturer="dresden elektronik",
193183
model=self.api.config.model_id,
194184
name=self.api.config.name,
195185
sw_version=self.api.config.software_version,
196-
via_device=(CONNECTION_NETWORK_MAC, self.api.config.mac),
197186
)
198187

199188
@staticmethod

homeassistant/components/deconz/light.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ def device_info(self) -> DeviceInfo:
396396
"""Return a device description for device registry."""
397397
return DeviceInfo(
398398
identifiers={(DOMAIN, self.unique_id)},
399-
manufacturer="Dresden Elektronik",
399+
manufacturer="dresden elektronik",
400400
model="deCONZ group",
401401
name=self._device.name,
402402
via_device=(DOMAIN, self.hub.api.config.bridge_id),

homeassistant/components/deconz/services.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
device_registry as dr,
1212
entity_registry as er,
1313
)
14-
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
1514
from homeassistant.util.read_only_dict import ReadOnlyDict
1615

1716
from .const import CONF_BRIDGE_ID, DOMAIN, LOGGER
@@ -120,8 +119,8 @@ async def async_configure_service(hub: DeconzHub, data: ReadOnlyDict) -> None:
120119
"field": "/lights/1/state",
121120
"data": {"on": true}
122121
}
123-
See Dresden Elektroniks REST API documentation for details:
124-
http://dresden-elektronik.github.io/deconz-rest-doc/rest/
122+
See deCONZ REST-API documentation for details:
123+
https://dresden-elektronik.github.io/deconz-rest-doc/
125124
"""
126125
field = data.get(SERVICE_FIELD, "")
127126
entity_id = data.get(SERVICE_ENTITY)
@@ -162,14 +161,6 @@ async def async_remove_orphaned_entries_service(hub: DeconzHub) -> None:
162161
)
163162
]
164163

165-
# Don't remove the Gateway host entry
166-
if hub.api.config.mac:
167-
hub_host = device_registry.async_get_device(
168-
connections={(CONNECTION_NETWORK_MAC, hub.api.config.mac)},
169-
)
170-
if hub_host and hub_host.id in devices_to_be_removed:
171-
devices_to_be_removed.remove(hub_host.id)
172-
173164
# Don't remove the Gateway service entry
174165
hub_service = device_registry.async_get_device(
175166
identifiers={(DOMAIN, hub.api.config.bridge_id)}

tests/components/deconz/snapshots/test_hub.ambr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}),
2020
'labels': set({
2121
}),
22-
'manufacturer': 'Dresden Elektronik',
22+
'manufacturer': 'dresden elektronik',
2323
'model': 'deCONZ',
2424
'model_id': None,
2525
'name': 'deCONZ mock gateway',

tests/components/deconz/test_deconz_event.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ async def test_deconz_events(
7676
) -> None:
7777
"""Test successful creation of deconz events."""
7878
assert len(hass.states.async_all()) == 3
79-
# 5 switches + 2 additional devices for deconz service and host
79+
# 5 switches + 1 additional device for deconz gateway
8080
assert (
8181
len(
8282
dr.async_entries_for_config_entry(
8383
device_registry, config_entry_setup.entry_id
8484
)
8585
)
86-
== 7
86+
== 6
8787
)
8888
assert hass.states.get("sensor.switch_2_battery").state == "100"
8989
assert hass.states.get("sensor.switch_3_battery").state == "100"
@@ -233,14 +233,14 @@ async def test_deconz_alarm_events(
233233
) -> None:
234234
"""Test successful creation of deconz alarm events."""
235235
assert len(hass.states.async_all()) == 4
236-
# 1 alarm control device + 2 additional devices for deconz service and host
236+
# 1 alarm control device + 1 additional device for deconz gateway
237237
assert (
238238
len(
239239
dr.async_entries_for_config_entry(
240240
device_registry, config_entry_setup.entry_id
241241
)
242242
)
243-
== 3
243+
== 2
244244
)
245245

246246
captured_events = async_capture_events(hass, CONF_DECONZ_ALARM_EVENT)
@@ -362,7 +362,7 @@ async def test_deconz_presence_events(
362362
device_registry, config_entry_setup.entry_id
363363
)
364364
)
365-
== 3
365+
== 2
366366
)
367367

368368
device = device_registry.async_get_device(
@@ -439,7 +439,7 @@ async def test_deconz_relative_rotary_events(
439439
device_registry, config_entry_setup.entry_id
440440
)
441441
)
442-
== 3
442+
== 2
443443
)
444444

445445
device = device_registry.async_get_device(
@@ -508,5 +508,5 @@ async def test_deconz_events_bad_unique_id(
508508
device_registry, config_entry_setup.entry_id
509509
)
510510
)
511-
== 2
511+
== 1
512512
)

tests/components/deconz/test_services.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async def test_configure_service_with_field(
5656
{
5757
"name": "Test",
5858
"state": {"reachable": True},
59-
"type": "Light",
59+
"type": "Dimmable light",
6060
"uniqueid": "00:00:00:00:00:00:00:01-00",
6161
}
6262
],
@@ -85,7 +85,7 @@ async def test_configure_service_with_entity(
8585
{
8686
"name": "Test",
8787
"state": {"reachable": True},
88-
"type": "Light",
88+
"type": "Dimmable light",
8989
"uniqueid": "00:00:00:00:00:00:00:01-00",
9090
}
9191
],
@@ -204,7 +204,7 @@ async def test_service_refresh_devices(
204204
"1": {
205205
"name": "Light 1 name",
206206
"state": {"reachable": True},
207-
"type": "Light",
207+
"type": "Dimmable light",
208208
"uniqueid": "00:00:00:00:00:00:00:01-00",
209209
}
210210
},
@@ -270,7 +270,7 @@ async def test_service_refresh_devices_trigger_no_state_update(
270270
"1": {
271271
"name": "Light 1 name",
272272
"state": {"reachable": True},
273-
"type": "Light",
273+
"type": "Dimmable light",
274274
"uniqueid": "00:00:00:00:00:00:00:01-00",
275275
}
276276
},
@@ -301,7 +301,7 @@ async def test_service_refresh_devices_trigger_no_state_update(
301301
{
302302
"name": "Light 0 name",
303303
"state": {"reachable": True},
304-
"type": "Light",
304+
"type": "Dimmable light",
305305
"uniqueid": "00:00:00:00:00:00:00:01-00",
306306
}
307307
],
@@ -327,7 +327,12 @@ async def test_remove_orphaned_entries_service(
327327
"""Test service works and also don't remove more than expected."""
328328
device = device_registry.async_get_or_create(
329329
config_entry_id=config_entry_setup.entry_id,
330-
connections={(dr.CONNECTION_NETWORK_MAC, "123")},
330+
identifiers={(DOMAIN, BRIDGE_ID)},
331+
)
332+
333+
device_registry.async_get_or_create(
334+
config_entry_id=config_entry_setup.entry_id,
335+
identifiers={(DOMAIN, "orphaned")},
331336
)
332337

333338
assert (
@@ -338,7 +343,7 @@ async def test_remove_orphaned_entries_service(
338343
if config_entry_setup.entry_id in entry.config_entries
339344
]
340345
)
341-
== 5 # Host, gateway, light, switch and orphan
346+
== 4 # Gateway, light, switch and orphan
342347
)
343348

344349
entity_registry.async_get_or_create(
@@ -374,7 +379,7 @@ async def test_remove_orphaned_entries_service(
374379
if config_entry_setup.entry_id in entry.config_entries
375380
]
376381
)
377-
== 4 # Host, gateway, light and switch
382+
== 3 # Gateway, light and switch
378383
)
379384

380385
assert (

tests/components/unifi/test_services.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""deCONZ service tests."""
1+
"""UniFi service tests."""
22

33
from typing import Any
44
from unittest.mock import PropertyMock, patch

0 commit comments

Comments
 (0)