mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 04:08:19 -04:00
Reload the DoorBird entry when the configured events change (#185961)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ed2d43f0cb
commit
266d2c5e8a
@@ -114,7 +114,5 @@ async def _async_register_events(
|
||||
|
||||
async def _update_listener(hass: HomeAssistant, entry: DoorBirdConfigEntry) -> None:
|
||||
"""Handle options update."""
|
||||
door_station = entry.runtime_data.door_station
|
||||
door_station.update_events(entry.options[CONF_EVENTS])
|
||||
# Subscribe to doorbell or motion events
|
||||
await _async_register_events(hass, door_station, entry)
|
||||
# The entities are built from the registered events, so rebuild them.
|
||||
await hass.config_entries.async_reload(entry.entry_id)
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.doorbird.const import DOMAIN
|
||||
from homeassistant.components.doorbird.const import CONF_EVENTS, DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import mock_not_found_exception, mock_unauthorized_exception
|
||||
from .conftest import DoorbirdMockerType
|
||||
from . import mock_not_found_exception, mock_unauthorized_exception, mock_webhook_call
|
||||
from .conftest import DoorbirdMockerType, patch_doorbird_api_entry_points
|
||||
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_basic_setup(
|
||||
@@ -79,8 +82,9 @@ async def test_events_changed(
|
||||
api.change_favorite.reset_mock()
|
||||
api.schedule.reset_mock()
|
||||
|
||||
hass.config_entries.async_update_entry(entry, options={"events": ["xyz"]})
|
||||
await hass.async_block_till_done()
|
||||
with patch_doorbird_api_entry_points(api):
|
||||
hass.config_entries.async_update_entry(entry, options={"events": ["xyz"]})
|
||||
await hass.async_block_till_done()
|
||||
assert len(api.favorites.mock_calls) == 2
|
||||
assert len(api.schedule.mock_calls) == 1
|
||||
|
||||
@@ -89,5 +93,29 @@ async def test_events_changed(
|
||||
assert favorite_type == "http"
|
||||
assert title == "Home Assistant (mydoorbird_xyz)"
|
||||
assert url == (
|
||||
f"http://10.10.10.10:8123/api/doorbird/mydoorbird_xyz?token={entry.entry_id}"
|
||||
f"http://127.0.0.1:8123/api/doorbird/mydoorbird_xyz?token={entry.entry_id}"
|
||||
)
|
||||
|
||||
|
||||
async def test_entities_follow_events_changed(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
doorbird_mocker: DoorbirdMockerType,
|
||||
) -> None:
|
||||
"""Test the entities pick up newly configured events without a restart."""
|
||||
doorbird_entry = await doorbird_mocker(options={CONF_EVENTS: []})
|
||||
assert hass.states.get("event.mydoorbird_doorbell") is None
|
||||
|
||||
with patch_doorbird_api_entry_points(doorbird_entry.api):
|
||||
hass.config_entries.async_update_entry(
|
||||
doorbird_entry.entry, options={CONF_EVENTS: ["doorbell", "motion"]}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("event.mydoorbird_doorbell") is not None
|
||||
|
||||
client = await hass_client()
|
||||
await mock_webhook_call(doorbird_entry.entry, client, "mydoorbird_doorbell")
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("image.mydoorbird_last_ring").state != STATE_UNKNOWN
|
||||
|
||||
Reference in New Issue
Block a user