Fix ring chimes data update (#109220)

* Fix bug with chimes data update

* Trigger update in test with time change

* Fix test to use freezer

* Make test less fragile
pull/109199/head
Steven B 2024-01-31 18:39:18 +00:00 committed by GitHub
parent d361d47516
commit 605b7312a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 67 additions and 0 deletions

View File

@ -75,6 +75,7 @@ class RingDataCoordinator(DataUpdateCoordinator[dict[int, RingDeviceData]]):
if device.id in subscribed_device_ids:
data[device.id] = RingDeviceData(device=device)
try:
history_task = None
async with TaskGroup() as tg:
if hasattr(device, "history"):
history_task = tg.create_task(

View File

@ -0,0 +1,35 @@
{
"authorized_doorbots": [],
"chimes": [
{
"address": "123 Main St",
"alerts": { "connection": "online" },
"description": "Downstairs",
"device_id": "abcdef123",
"do_not_disturb": { "seconds_left": 0 },
"features": { "ringtones_enabled": true },
"firmware_version": "1.2.3",
"id": 123456,
"kind": "chime",
"latitude": 12.0,
"longitude": -70.12345,
"owned": true,
"owner": {
"email": "foo@bar.org",
"first_name": "Marcelo",
"id": 999999,
"last_name": "Assistant"
},
"settings": {
"ding_audio_id": null,
"ding_audio_user_id": null,
"motion_audio_id": null,
"motion_audio_user_id": null,
"volume": 2
},
"time_zone": "America/New_York"
}
],
"doorbots": [],
"stickup_cams": []
}

View File

@ -1,10 +1,17 @@
"""The tests for the Ring sensor platform."""
import logging
from freezegun.api import FrozenDateTimeFactory
import requests_mock
from homeassistant.components.ring.const import SCAN_INTERVAL
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from .common import setup_platform
from tests.common import async_fire_time_changed, load_fixture
WIFI_ENABLED = False
@ -48,3 +55,27 @@ async def test_sensor(hass: HomeAssistant, requests_mock: requests_mock.Mocker)
)
assert front_door_wifi_signal_strength_state is not None
assert front_door_wifi_signal_strength_state.state == "-58"
async def test_only_chime_devices(
hass: HomeAssistant,
requests_mock: requests_mock.Mocker,
freezer: FrozenDateTimeFactory,
caplog,
) -> None:
"""Tests the update service works correctly if only chimes are returned."""
hass.config.set_time_zone("UTC")
freezer.move_to("2021-01-09 12:00:00+00:00")
requests_mock.get(
"https://api.ring.com/clients_api/ring_devices",
text=load_fixture("chime_devices.json", "ring"),
)
await setup_platform(hass, Platform.SENSOR)
await hass.async_block_till_done()
caplog.set_level(logging.DEBUG)
caplog.clear()
freezer.tick(SCAN_INTERVAL)
async_fire_time_changed(hass)
await hass.async_block_till_done()
assert "UnboundLocalError" not in caplog.text # For issue #109210