2019-04-26 06:56:43 +00:00
|
|
|
"""Tests for the Sonos Media Player platform."""
|
2024-03-08 13:47:22 +00:00
|
|
|
|
2021-04-05 03:26:55 +00:00
|
|
|
from homeassistant.const import STATE_IDLE
|
2023-02-15 14:23:34 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2024-02-03 08:20:10 +00:00
|
|
|
from homeassistant.helpers.device_registry import (
|
|
|
|
CONNECTION_NETWORK_MAC,
|
|
|
|
CONNECTION_UPNP,
|
|
|
|
DeviceRegistry,
|
|
|
|
)
|
2016-07-29 03:40:58 +00:00
|
|
|
|
|
|
|
|
2023-02-15 14:23:34 +00:00
|
|
|
async def test_device_registry(
|
2024-02-03 08:20:10 +00:00
|
|
|
hass: HomeAssistant, device_registry: DeviceRegistry, async_autosetup_sonos, soco
|
2023-02-15 14:23:34 +00:00
|
|
|
) -> None:
|
2020-05-17 21:16:50 +00:00
|
|
|
"""Test sonos device registered in the device registry."""
|
|
|
|
reg_device = device_registry.async_get_device(
|
2021-01-07 12:49:45 +00:00
|
|
|
identifiers={("sonos", "RINCON_test")}
|
2020-05-17 21:16:50 +00:00
|
|
|
)
|
2024-02-03 08:20:10 +00:00
|
|
|
assert reg_device is not None
|
2020-05-17 21:16:50 +00:00
|
|
|
assert reg_device.model == "Model Name"
|
2021-05-23 13:43:49 +00:00
|
|
|
assert reg_device.sw_version == "13.1"
|
2021-09-27 15:36:47 +00:00
|
|
|
assert reg_device.connections == {
|
2024-02-03 08:20:10 +00:00
|
|
|
(CONNECTION_NETWORK_MAC, "00:11:22:33:44:55"),
|
|
|
|
(CONNECTION_UPNP, "uuid:RINCON_test"),
|
2021-09-27 15:36:47 +00:00
|
|
|
}
|
2020-05-17 21:16:50 +00:00
|
|
|
assert reg_device.manufacturer == "Sonos"
|
|
|
|
assert reg_device.name == "Zone A"
|
2024-02-03 08:20:10 +00:00
|
|
|
# Default device provides battery info, area should not be suggested
|
|
|
|
assert reg_device.suggested_area is None
|
|
|
|
|
|
|
|
|
|
|
|
async def test_device_registry_not_portable(
|
|
|
|
hass: HomeAssistant, device_registry: DeviceRegistry, async_setup_sonos, soco
|
|
|
|
) -> None:
|
|
|
|
"""Test non-portable sonos device registered in the device registry to ensure area suggested."""
|
|
|
|
soco.get_battery_info.return_value = {}
|
|
|
|
await async_setup_sonos()
|
|
|
|
|
|
|
|
reg_device = device_registry.async_get_device(
|
|
|
|
identifiers={("sonos", "RINCON_test")}
|
|
|
|
)
|
|
|
|
assert reg_device is not None
|
|
|
|
assert reg_device.suggested_area == "Zone A"
|
2021-04-05 03:26:55 +00:00
|
|
|
|
|
|
|
|
2023-02-15 14:23:34 +00:00
|
|
|
async def test_entity_basic(
|
|
|
|
hass: HomeAssistant, async_autosetup_sonos, discover
|
|
|
|
) -> None:
|
2021-04-05 03:26:55 +00:00
|
|
|
"""Test basic state and attributes."""
|
|
|
|
state = hass.states.get("media_player.zone_a")
|
|
|
|
assert state.state == STATE_IDLE
|
|
|
|
attributes = state.attributes
|
|
|
|
assert attributes["friendly_name"] == "Zone A"
|
|
|
|
assert attributes["is_volume_muted"] is False
|
|
|
|
assert attributes["volume_level"] == 0.19
|