Files
core/tests/components/sonos/test_statistics.py
Pete Sage afc0a2789d Update Sonos to use SonosConfigEntry and runtime data (#145512)
* fix: initial

* fix: cleanup

* fix: cleanup

* fix: cleanup

* fix: SonosConfigEntry

* add config_entry.py

* fix: sonos_data to runtime_data

* fix: move to helpers.py
2025-06-12 14:05:51 +02:00

38 lines
1.2 KiB
Python

"""Tests for the Sonos statistics."""
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
async def test_statistics_duplicate(
hass: HomeAssistant,
async_autosetup_sonos,
soco,
device_properties_event,
config_entry: MockConfigEntry,
) -> None:
"""Test Sonos statistics."""
speaker = list(config_entry.runtime_data.discovered.values())[0]
subscription = soco.deviceProperties.subscribe.return_value
sub_callback = subscription.callback
# Update the speaker with a callback event
sub_callback(device_properties_event)
await hass.async_block_till_done()
report = speaker.event_stats.report()
assert report["DeviceProperties"]["received"] == 1
assert report["DeviceProperties"]["duplicates"] == 0
assert report["DeviceProperties"]["processed"] == 1
# Ensure a duplicate is registered in the statistics
sub_callback(device_properties_event)
await hass.async_block_till_done()
report = speaker.event_stats.report()
assert report["DeviceProperties"]["received"] == 2
assert report["DeviceProperties"]["duplicates"] == 1
assert report["DeviceProperties"]["processed"] == 1