Correct dlna_dmr device info (#96480)

This commit is contained in:
Erik Montnemery 2023-07-13 18:15:46 +02:00 committed by GitHub
parent 5b93017740
commit 8440f14a08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 10 deletions

View File

@ -37,7 +37,6 @@ from .const import (
CONF_CALLBACK_URL_OVERRIDE,
CONF_LISTEN_PORT,
CONF_POLL_AVAILABILITY,
DOMAIN,
LOGGER as _LOGGER,
MEDIA_METADATA_DIDL,
MEDIA_TYPE_MAP,
@ -381,7 +380,6 @@ class DlnaDmrEntity(MediaPlayerEntity):
device_entry = dev_reg.async_get_or_create(
config_entry_id=self.registry_entry.config_entry_id,
connections=connections,
identifiers={(DOMAIN, self.unique_id)},
default_manufacturer=self._device.manufacturer,
default_model=self._device.model_name,
default_name=self._device.name,

View File

@ -50,6 +50,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import (
CONNECTION_NETWORK_MAC,
CONNECTION_UPNP,
async_get as async_get_dr,
)
from homeassistant.helpers.entity_component import async_update_entity
@ -347,7 +348,10 @@ async def test_setup_entry_mac_address(
# Check the device registry connections for MAC address
dev_reg = async_get_dr(hass)
device = dev_reg.async_get_device(identifiers={(DLNA_DOMAIN, MOCK_DEVICE_UDN)})
device = dev_reg.async_get_device(
connections={(CONNECTION_UPNP, MOCK_DEVICE_UDN)},
identifiers=set(),
)
assert device is not None
assert (CONNECTION_NETWORK_MAC, MOCK_MAC_ADDRESS) in device.connections
@ -364,7 +368,10 @@ async def test_setup_entry_no_mac_address(
# Check the device registry connections does not include the MAC address
dev_reg = async_get_dr(hass)
device = dev_reg.async_get_device(identifiers={(DLNA_DOMAIN, MOCK_DEVICE_UDN)})
device = dev_reg.async_get_device(
connections={(CONNECTION_UPNP, MOCK_DEVICE_UDN)},
identifiers=set(),
)
assert device is not None
assert (CONNECTION_NETWORK_MAC, MOCK_MAC_ADDRESS) not in device.connections
@ -427,7 +434,10 @@ async def test_available_device(
"""Test a DlnaDmrEntity with a connected DmrDevice."""
# Check hass device information is filled in
dev_reg = async_get_dr(hass)
device = dev_reg.async_get_device(identifiers={(DLNA_DOMAIN, MOCK_DEVICE_UDN)})
device = dev_reg.async_get_device(
connections={(CONNECTION_UPNP, MOCK_DEVICE_UDN)},
identifiers=set(),
)
assert device is not None
# Device properties are set in dmr_device_mock before the entity gets constructed
assert device.manufacturer == "device_manufacturer"
@ -1323,7 +1333,10 @@ async def test_unavailable_device(
# Check hass device information has not been filled in yet
dev_reg = async_get_dr(hass)
device = dev_reg.async_get_device(identifiers={(DLNA_DOMAIN, MOCK_DEVICE_UDN)})
device = dev_reg.async_get_device(
connections={(CONNECTION_UPNP, MOCK_DEVICE_UDN)},
identifiers=set(),
)
assert device is None
# Unload config entry to clean up
@ -1360,7 +1373,10 @@ async def test_become_available(
# Check hass device information has not been filled in yet
dev_reg = async_get_dr(hass)
device = dev_reg.async_get_device(identifiers={(DLNA_DOMAIN, MOCK_DEVICE_UDN)})
device = dev_reg.async_get_device(
connections={(CONNECTION_UPNP, MOCK_DEVICE_UDN)},
identifiers=set(),
)
assert device is None
# Mock device is now available.
@ -1399,7 +1415,10 @@ async def test_become_available(
assert mock_state.state == MediaPlayerState.IDLE
# Check hass device information is now filled in
dev_reg = async_get_dr(hass)
device = dev_reg.async_get_device(identifiers={(DLNA_DOMAIN, MOCK_DEVICE_UDN)})
device = dev_reg.async_get_device(
connections={(CONNECTION_UPNP, MOCK_DEVICE_UDN)},
identifiers=set(),
)
assert device is not None
assert device.manufacturer == "device_manufacturer"
assert device.model == "device_model_name"
@ -2231,7 +2250,10 @@ async def test_config_update_mac_address(
# Check the device registry connections does not include the MAC address
dev_reg = async_get_dr(hass)
device = dev_reg.async_get_device(identifiers={(DLNA_DOMAIN, MOCK_DEVICE_UDN)})
device = dev_reg.async_get_device(
connections={(CONNECTION_UPNP, MOCK_DEVICE_UDN)},
identifiers=set(),
)
assert device is not None
assert (CONNECTION_NETWORK_MAC, MOCK_MAC_ADDRESS) not in device.connections
@ -2248,6 +2270,9 @@ async def test_config_update_mac_address(
await hass.async_block_till_done()
# Device registry connections should now include the MAC address
device = dev_reg.async_get_device(identifiers={(DLNA_DOMAIN, MOCK_DEVICE_UDN)})
device = dev_reg.async_get_device(
connections={(CONNECTION_UPNP, MOCK_DEVICE_UDN)},
identifiers=set(),
)
assert device is not None
assert (CONNECTION_NETWORK_MAC, MOCK_MAC_ADDRESS) in device.connections