mirror of
https://github.com/home-assistant/core.git
synced 2026-10-07 14:58:11 -04:00
Fix doorbird events (#183871)
This commit is contained in:
@@ -115,14 +115,14 @@ class DoorBirdCamera(DoorBirdEntity, Camera):
|
||||
"""Subscribe to events."""
|
||||
await super().async_added_to_hass()
|
||||
event_to_entity_id = self._door_bird_data.event_entity_ids
|
||||
for event in self._door_station.events:
|
||||
for event in self._door_station.door_station_events:
|
||||
event_to_entity_id[event] = self.entity_id
|
||||
|
||||
@override
|
||||
async def async_will_remove_from_hass(self) -> None:
|
||||
"""Unsubscribe from events."""
|
||||
event_to_entity_id = self._door_bird_data.event_entity_ids
|
||||
for event in self._door_station.events:
|
||||
for event in self._door_station.door_station_events:
|
||||
# If the clear api was called, the events may not be in the dict
|
||||
event_to_entity_id.pop(event, None)
|
||||
await super().async_will_remove_from_hass()
|
||||
|
||||
@@ -2,10 +2,16 @@
|
||||
|
||||
from http import HTTPStatus
|
||||
|
||||
from homeassistant.components.doorbird.const import API_URL
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.doorbird.const import API_URL
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import mock_webhook_call
|
||||
from .conftest import DoorbirdMockerType
|
||||
|
||||
from tests.common import async_capture_events
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
@@ -19,3 +25,22 @@ async def test_non_webhook_with_wrong_token(
|
||||
|
||||
response = await client.get(f"{API_URL}/doorbell?token=wrong")
|
||||
assert response.status == HTTPStatus.UNAUTHORIZED
|
||||
|
||||
|
||||
@pytest.mark.parametrize("event", ["mydoorbird_doorbell", "mydoorbird_motion"])
|
||||
async def test_webhook_event_entity_id(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
doorbird_mocker: DoorbirdMockerType,
|
||||
event: str,
|
||||
) -> None:
|
||||
"""Test the fired event carries the camera entity_id."""
|
||||
doorbird_entry = await doorbird_mocker()
|
||||
events = async_capture_events(hass, f"doorbird_{event}")
|
||||
client = await hass_client()
|
||||
|
||||
await mock_webhook_call(doorbird_entry.entry, client, event)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(events) == 1
|
||||
assert events[0].data[ATTR_ENTITY_ID] == "camera.mydoorbird_last_motion"
|
||||
|
||||
Reference in New Issue
Block a user