55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
"""Tests for the Sonos Media Player platform."""
|
|
from homeassistant.const import STATE_IDLE
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.device_registry import (
|
|
CONNECTION_NETWORK_MAC,
|
|
CONNECTION_UPNP,
|
|
DeviceRegistry,
|
|
)
|
|
|
|
|
|
async def test_device_registry(
|
|
hass: HomeAssistant, device_registry: DeviceRegistry, async_autosetup_sonos, soco
|
|
) -> None:
|
|
"""Test sonos device registered in the device registry."""
|
|
reg_device = device_registry.async_get_device(
|
|
identifiers={("sonos", "RINCON_test")}
|
|
)
|
|
assert reg_device is not None
|
|
assert reg_device.model == "Model Name"
|
|
assert reg_device.sw_version == "13.1"
|
|
assert reg_device.connections == {
|
|
(CONNECTION_NETWORK_MAC, "00:11:22:33:44:55"),
|
|
(CONNECTION_UPNP, "uuid:RINCON_test"),
|
|
}
|
|
assert reg_device.manufacturer == "Sonos"
|
|
assert reg_device.name == "Zone A"
|
|
# 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"
|
|
|
|
|
|
async def test_entity_basic(
|
|
hass: HomeAssistant, async_autosetup_sonos, discover
|
|
) -> None:
|
|
"""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
|