diff --git a/homeassistant/components/ring/coordinator.py b/homeassistant/components/ring/coordinator.py index 35692ae2648..5b6412caffa 100644 --- a/homeassistant/components/ring/coordinator.py +++ b/homeassistant/components/ring/coordinator.py @@ -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( diff --git a/tests/components/ring/fixtures/chime_devices.json b/tests/components/ring/fixtures/chime_devices.json new file mode 100644 index 00000000000..5c3e60ec655 --- /dev/null +++ b/tests/components/ring/fixtures/chime_devices.json @@ -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": [] +} diff --git a/tests/components/ring/test_sensor.py b/tests/components/ring/test_sensor.py index 5c9a6ecacf7..5fd50f69c13 100644 --- a/tests/components/ring/test_sensor.py +++ b/tests/components/ring/test_sensor.py @@ -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