Use dispatcher for doorbird event entities (#121825)
* Use dispatcher for doorbird event entities https://github.com/home-assistant/core/pull/121114#discussion_r1668171539 * Update homeassistant/components/doorbird/view.py
This commit is contained in:
parent
73f6e3c07b
commit
73b836df55
2 changed files with 9 additions and 4 deletions
|
@ -7,7 +7,8 @@ from homeassistant.components.event import (
|
|||
EventEntity,
|
||||
EventEntityDescription,
|
||||
)
|
||||
from homeassistant.core import Event, HomeAssistant, callback
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
|
@ -70,14 +71,15 @@ class DoorBirdEventEntity(DoorBirdEntity, EventEntity):
|
|||
async def async_added_to_hass(self) -> None:
|
||||
"""Subscribe to device events."""
|
||||
self.async_on_remove(
|
||||
self.hass.bus.async_listen(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
f"{DOMAIN}_{self._doorbird_event.event}",
|
||||
self._async_handle_event,
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def _async_handle_event(self, event: Event) -> None:
|
||||
def _async_handle_event(self) -> None:
|
||||
"""Handle a device event."""
|
||||
event_types = self.entity_description.event_types
|
||||
if TYPE_CHECKING:
|
||||
|
|
|
@ -7,6 +7,7 @@ from http import HTTPStatus
|
|||
from aiohttp import web
|
||||
|
||||
from homeassistant.components.http import KEY_HASS, HomeAssistantView
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
|
||||
from .const import API_URL, DOMAIN
|
||||
from .util import get_door_station_by_token
|
||||
|
@ -45,5 +46,7 @@ class DoorBirdRequestView(HomeAssistantView):
|
|||
# Do not copy this pattern in the future
|
||||
# for any new integrations.
|
||||
#
|
||||
hass.bus.async_fire(f"{DOMAIN}_{event}", event_data)
|
||||
event_type = f"{DOMAIN}_{event}"
|
||||
hass.bus.async_fire(event_type, event_data)
|
||||
async_dispatcher_send(hass, event_type)
|
||||
return web.Response(text="OK")
|
||||
|
|
Loading…
Add table
Reference in a new issue