mirror of
https://github.com/home-assistant/core.git
synced 2025-07-12 07:47:08 +00:00
Skip processed Sonos alarm updates (#51217)
* Skip processed Sonos alarm updates * Fix bad conflict merge
This commit is contained in:
parent
9bd74961f0
commit
e5309e89ea
@ -2,7 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict, deque
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
@ -76,6 +76,7 @@ class SonosData:
|
|||||||
self.discovered: OrderedDict[str, SonosSpeaker] = OrderedDict()
|
self.discovered: OrderedDict[str, SonosSpeaker] = OrderedDict()
|
||||||
self.favorites: dict[str, SonosFavorites] = {}
|
self.favorites: dict[str, SonosFavorites] = {}
|
||||||
self.alarms: dict[str, Alarm] = {}
|
self.alarms: dict[str, Alarm] = {}
|
||||||
|
self.processed_alarm_events = deque(maxlen=5)
|
||||||
self.topology_condition = asyncio.Condition()
|
self.topology_condition = asyncio.Condition()
|
||||||
self.hosts_heartbeat = None
|
self.hosts_heartbeat = None
|
||||||
self.ssdp_known: set[str] = set()
|
self.ssdp_known: set[str] = set()
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from collections import deque
|
||||||
from collections.abc import Coroutine
|
from collections.abc import Coroutine
|
||||||
import contextlib
|
import contextlib
|
||||||
import datetime
|
import datetime
|
||||||
@ -282,6 +283,11 @@ class SonosSpeaker:
|
|||||||
"""Return true if player is a coordinator."""
|
"""Return true if player is a coordinator."""
|
||||||
return self.coordinator is None
|
return self.coordinator is None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def processed_alarm_events(self) -> deque[str]:
|
||||||
|
"""Return the container of processed alarm events."""
|
||||||
|
return self.hass.data[DATA_SONOS].processed_alarm_events
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def subscription_address(self) -> str | None:
|
def subscription_address(self) -> str | None:
|
||||||
"""Return the current subscription callback address if any."""
|
"""Return the current subscription callback address if any."""
|
||||||
@ -366,6 +372,10 @@ class SonosSpeaker:
|
|||||||
@callback
|
@callback
|
||||||
def async_dispatch_alarms(self, event: SonosEvent) -> None:
|
def async_dispatch_alarms(self, event: SonosEvent) -> None:
|
||||||
"""Create a task to update alarms from an event."""
|
"""Create a task to update alarms from an event."""
|
||||||
|
update_id = event.variables["alarm_list_version"]
|
||||||
|
if update_id in self.processed_alarm_events:
|
||||||
|
return
|
||||||
|
self.processed_alarm_events.append(update_id)
|
||||||
self.hass.async_add_executor_job(self.update_alarms)
|
self.hass.async_add_executor_job(self.update_alarms)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -31,6 +31,15 @@ class SonosMockEvent:
|
|||||||
self.service = service
|
self.service = service
|
||||||
self.variables = variables
|
self.variables = variables
|
||||||
|
|
||||||
|
def increment_variable(self, var_name):
|
||||||
|
"""Increment the value of the var_name key in variables dict attribute.
|
||||||
|
|
||||||
|
Assumes value has a format of <str>:<int>.
|
||||||
|
"""
|
||||||
|
base, count = self.variables[var_name].split(":")
|
||||||
|
newcount = int(count) + 1
|
||||||
|
self.variables[var_name] = ":".join([base, str(newcount)])
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="config_entry")
|
@pytest.fixture(name="config_entry")
|
||||||
def config_entry_fixture():
|
def config_entry_fixture():
|
||||||
@ -174,7 +183,7 @@ def alarm_event_fixture(soco):
|
|||||||
"time_zone": "ffc40a000503000003000502ffc4",
|
"time_zone": "ffc40a000503000003000502ffc4",
|
||||||
"time_server": "0.sonostime.pool.ntp.org,1.sonostime.pool.ntp.org,2.sonostime.pool.ntp.org,3.sonostime.pool.ntp.org",
|
"time_server": "0.sonostime.pool.ntp.org,1.sonostime.pool.ntp.org,2.sonostime.pool.ntp.org,3.sonostime.pool.ntp.org",
|
||||||
"time_generation": "20000001",
|
"time_generation": "20000001",
|
||||||
"alarm_list_version": "RINCON_test",
|
"alarm_list_version": "RINCON_test:1",
|
||||||
"time_format": "INV",
|
"time_format": "INV",
|
||||||
"date_format": "INV",
|
"date_format": "INV",
|
||||||
"daily_index_refresh_time": None,
|
"daily_index_refresh_time": None,
|
||||||
|
@ -68,6 +68,7 @@ async def test_alarm_create_delete(
|
|||||||
assert "switch.sonos_alarm_15" in entity_registry.entities
|
assert "switch.sonos_alarm_15" in entity_registry.entities
|
||||||
|
|
||||||
alarm_clock_extended.ListAlarms.return_value = alarm_clock.ListAlarms.return_value
|
alarm_clock_extended.ListAlarms.return_value = alarm_clock.ListAlarms.return_value
|
||||||
|
alarm_event.increment_variable("alarm_list_version")
|
||||||
|
|
||||||
sub_callback(event=alarm_event)
|
sub_callback(event=alarm_event)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user