mirror of
https://github.com/home-assistant/core.git
synced 2025-08-30 09:51:37 +02:00
Revert "Add Tests for Sonos Alarms (#150014)"
This reverts commit 268f0d9e03
.
This commit is contained in:
committed by
GitHub
parent
ea946c90b3
commit
0d4069de64
@@ -214,26 +214,12 @@ class MockSoCo(MagicMock):
|
||||
surround_level = 3
|
||||
music_surround_level = 4
|
||||
soundbar_audio_input_format = "Dolby 5.1"
|
||||
factory: SoCoMockFactory | None = None
|
||||
|
||||
@property
|
||||
def visible_zones(self):
|
||||
"""Return visible zones and allow property to be overridden by device classes."""
|
||||
return {self}
|
||||
|
||||
@property
|
||||
def all_zones(self) -> set[MockSoCo]:
|
||||
"""Return all mock zones if a factory is set and enabled, else just self."""
|
||||
return (
|
||||
self.factory.mock_all_zones
|
||||
if self.factory and self.factory.mock_all_zones
|
||||
else {self}
|
||||
)
|
||||
|
||||
def set_factory(self, factory: SoCoMockFactory) -> None:
|
||||
"""Set the factory for this mock."""
|
||||
self.factory = factory
|
||||
|
||||
|
||||
class SoCoMockFactory:
|
||||
"""Factory for creating SoCo Mocks."""
|
||||
@@ -257,19 +243,12 @@ class SoCoMockFactory:
|
||||
self.alarm_clock = alarm_clock
|
||||
self.sonos_playlists = sonos_playlists
|
||||
self.sonos_queue = sonos_queue
|
||||
self.mock_zones: bool = False
|
||||
|
||||
@property
|
||||
def mock_all_zones(self) -> set[MockSoCo] | None:
|
||||
"""Return a set of all mock zones, or None if not enabled."""
|
||||
return set(self.mock_list.values()) if self.mock_zones else None
|
||||
|
||||
def cache_mock(
|
||||
self, mock_soco: MockSoCo, ip_address: str, name: str = "Zone A"
|
||||
) -> MockSoCo:
|
||||
"""Put a user created mock into the cache."""
|
||||
mock_soco.mock_add_spec(SoCo)
|
||||
mock_soco.set_factory(self)
|
||||
mock_soco.ip_address = ip_address
|
||||
if ip_address != "192.168.42.2":
|
||||
mock_soco.uid += f"_{ip_address}"
|
||||
@@ -281,11 +260,6 @@ class SoCoMockFactory:
|
||||
my_speaker_info = self.speaker_info.copy()
|
||||
my_speaker_info["zone_name"] = name
|
||||
my_speaker_info["uid"] = mock_soco.uid
|
||||
# Generate a different MAC for the non-default speakers.
|
||||
# otherwise new devices will not be created.
|
||||
if ip_address != "192.168.42.2":
|
||||
last_octet = ip_address.split(".")[-1]
|
||||
my_speaker_info["mac_address"] = f"00-00-00-00-00-{last_octet.zfill(2)}"
|
||||
mock_soco.get_speaker_info = Mock(return_value=my_speaker_info)
|
||||
mock_soco.add_to_queue = Mock(return_value=10)
|
||||
mock_soco.add_uri_to_queue = Mock(return_value=10)
|
||||
@@ -304,6 +278,7 @@ class SoCoMockFactory:
|
||||
|
||||
mock_soco.alarmClock = self.alarm_clock
|
||||
mock_soco.get_battery_info.return_value = self.battery_info
|
||||
mock_soco.all_zones = {mock_soco}
|
||||
mock_soco.group.coordinator = mock_soco
|
||||
mock_soco.household_id = "test_household_id"
|
||||
self.mock_list[ip_address] = mock_soco
|
||||
|
@@ -6,7 +6,6 @@ from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.sonos import DOMAIN
|
||||
from homeassistant.components.sonos.const import (
|
||||
DATA_SONOS_DISCOVERY_MANAGER,
|
||||
MODEL_SONOS_ARC_ULTRA,
|
||||
@@ -32,17 +31,10 @@ from homeassistant.const import (
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .conftest import (
|
||||
MockSoCo,
|
||||
SoCoMockFactory,
|
||||
SonosMockEvent,
|
||||
SonosMockService,
|
||||
create_rendering_control_event,
|
||||
)
|
||||
from .conftest import MockSoCo, SonosMockEvent, create_rendering_control_event
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
@@ -267,75 +259,3 @@ async def test_alarm_create_delete(
|
||||
|
||||
assert "switch.sonos_alarm_14" in entity_registry.entities
|
||||
assert "switch.sonos_alarm_15" not in entity_registry.entities
|
||||
|
||||
|
||||
async def test_alarm_change_device(
|
||||
hass: HomeAssistant,
|
||||
async_setup_sonos,
|
||||
soco: MockSoCo,
|
||||
alarm_clock: SonosMockService,
|
||||
alarm_clock_extended: SonosMockService,
|
||||
alarm_event: SonosMockEvent,
|
||||
entity_registry: er.EntityRegistry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
soco_factory: SoCoMockFactory,
|
||||
) -> None:
|
||||
"""Test Sonos Alarm being moved to a different speaker.
|
||||
|
||||
This test simulates a scenario where an alarm is created on one speaker
|
||||
and then moved to another speaker. It checks that the entity is correctly
|
||||
created on the new speaker and removed from the old one.
|
||||
"""
|
||||
|
||||
# Create the alarm on the soco_lr speaker
|
||||
soco_factory.mock_zones = True
|
||||
soco_lr = soco_factory.cache_mock(MockSoCo(), "10.10.10.1", "Living Room")
|
||||
alarm_dict = copy(alarm_clock.ListAlarms.return_value)
|
||||
alarm_dict["CurrentAlarmList"] = alarm_dict["CurrentAlarmList"].replace(
|
||||
"RINCON_test", f"{soco_lr.uid}"
|
||||
)
|
||||
alarm_dict["CurrentAlarmListVersion"] = f"{soco_lr.uid}:900"
|
||||
soco_lr.alarmClock.ListAlarms.return_value = alarm_dict
|
||||
soco_br = soco_factory.cache_mock(MockSoCo(), "10.10.10.2", "Bedroom")
|
||||
await async_setup_component(
|
||||
hass,
|
||||
DOMAIN,
|
||||
{
|
||||
DOMAIN: {
|
||||
"media_player": {
|
||||
"interface_addr": "127.0.0.1",
|
||||
"hosts": ["10.10.10.1", "10.10.10.2"],
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entity_id = "switch.sonos_alarm_14"
|
||||
|
||||
# Verify the alarm is created on the soco_lr speaker
|
||||
assert entity_id in entity_registry.entities
|
||||
entity = entity_registry.async_get(entity_id)
|
||||
device = device_registry.async_get(entity.device_id)
|
||||
assert device.name == soco_lr.get_speaker_info()["zone_name"]
|
||||
|
||||
# Simulate the alarm being moved to the soco_br speaker
|
||||
alarm_update = copy(alarm_clock_extended.ListAlarms.return_value)
|
||||
alarm_update["CurrentAlarmList"] = alarm_update["CurrentAlarmList"].replace(
|
||||
"RINCON_test", f"{soco_br.uid}"
|
||||
)
|
||||
alarm_clock.ListAlarms.return_value = alarm_update
|
||||
|
||||
# Update the alarm_list_version so it gets processed.
|
||||
alarm_event.variables["alarm_list_version"] = f"{soco_br.uid}:1000"
|
||||
alarm_update["CurrentAlarmListVersion"] = alarm_event.increment_variable(
|
||||
"alarm_list_version"
|
||||
)
|
||||
|
||||
alarm_clock.subscribe.return_value.callback(event=alarm_event)
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
assert entity_id in entity_registry.entities
|
||||
alarm_14 = entity_registry.async_get(entity_id)
|
||||
device = device_registry.async_get(alarm_14.device_id)
|
||||
assert device.name == soco_br.get_speaker_info()["zone_name"]
|
||||
|
Reference in New Issue
Block a user