Add sw_version and connections to sonos devices (#35743)

This commit is contained in:
J. Nick Koston 2020-05-17 16:16:50 -05:00 committed by GitHub
parent f085fb1499
commit 03b14c9aae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

View file

@ -40,6 +40,7 @@ from homeassistant.const import (
)
from homeassistant.core import ServiceCall, callback
from homeassistant.helpers import config_validation as cv, entity_platform, service
import homeassistant.helpers.device_registry as dr
from homeassistant.util.dt import utcnow
from . import (
@ -392,6 +393,8 @@ class SonosEntity(MediaPlayerEntity):
speaker_info = self.soco.get_speaker_info(True)
self._name = speaker_info["zone_name"]
self._model = speaker_info["model_name"]
self._sw_version = speaker_info["software_version"]
self._mac_address = speaker_info["mac_address"]
async def async_added_to_hass(self):
"""Subscribe sonos events."""
@ -427,6 +430,8 @@ class SonosEntity(MediaPlayerEntity):
"identifiers": {(SONOS_DOMAIN, self._unique_id)},
"name": self._name,
"model": self._model.replace("Sonos ", ""),
"sw_version": self._sw_version,
"connections": {(dr.CONNECTION_NETWORK_MAC, self._mac_address)},
"manufacturer": "Sonos",
}

View file

@ -69,4 +69,9 @@ def music_library_fixture():
@pytest.fixture(name="speaker_info")
def speaker_info_fixture():
"""Create speaker_info fixture."""
return {"zone_name": "Zone A", "model_name": "Model Name"}
return {
"zone_name": "Zone A",
"model_name": "Model Name",
"software_version": "49.2-64250",
"mac_address": "00-11-22-33-44-55",
}

View file

@ -42,3 +42,18 @@ async def test_services(hass, config_entry, config, hass_read_only_user):
blocking=True,
context=Context(user_id=hass_read_only_user.id),
)
async def test_device_registry(hass, config_entry, config, soco):
"""Test sonos device registered in the device registry."""
await setup_platform(hass, config_entry, config)
device_registry = await hass.helpers.device_registry.async_get_registry()
reg_device = device_registry.async_get_device(
identifiers={("sonos", "RINCON_test")}, connections=set(),
)
assert reg_device.model == "Model Name"
assert reg_device.sw_version == "49.2-64250"
assert reg_device.connections == {("mac", "00:11:22:33:44:55")}
assert reg_device.manufacturer == "Sonos"
assert reg_device.name == "Zone A"