mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 00:07:10 +00:00
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
@ -7,7 +7,8 @@ from homeassistant.components.event import (
|
|||||||
EventEntity,
|
EventEntity,
|
||||||
EventEntityDescription,
|
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 homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
@ -70,14 +71,15 @@ class DoorBirdEventEntity(DoorBirdEntity, EventEntity):
|
|||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Subscribe to device events."""
|
"""Subscribe to device events."""
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
self.hass.bus.async_listen(
|
async_dispatcher_connect(
|
||||||
|
self.hass,
|
||||||
f"{DOMAIN}_{self._doorbird_event.event}",
|
f"{DOMAIN}_{self._doorbird_event.event}",
|
||||||
self._async_handle_event,
|
self._async_handle_event,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_handle_event(self, event: Event) -> None:
|
def _async_handle_event(self) -> None:
|
||||||
"""Handle a device event."""
|
"""Handle a device event."""
|
||||||
event_types = self.entity_description.event_types
|
event_types = self.entity_description.event_types
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
@ -7,6 +7,7 @@ from http import HTTPStatus
|
|||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
|
|
||||||
from homeassistant.components.http import KEY_HASS, HomeAssistantView
|
from homeassistant.components.http import KEY_HASS, HomeAssistantView
|
||||||
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
|
|
||||||
from .const import API_URL, DOMAIN
|
from .const import API_URL, DOMAIN
|
||||||
from .util import get_door_station_by_token
|
from .util import get_door_station_by_token
|
||||||
@ -45,5 +46,7 @@ class DoorBirdRequestView(HomeAssistantView):
|
|||||||
# Do not copy this pattern in the future
|
# Do not copy this pattern in the future
|
||||||
# for any new integrations.
|
# 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")
|
return web.Response(text="OK")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user