Skip to content

Commit

Permalink
Merge pull request #479 from skrashevich/fix-ha-2024.4
Browse files Browse the repository at this point in the history
Fix compatibility with HA 2024.4
  • Loading branch information
AlexxIT authored Apr 5, 2024
2 parents 2ab47bc + 870289c commit a6f8695
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions custom_components/yandex_station/intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import logging
from typing import Optional

from collections.abc import Mapping
from homeassistant.core import Event, HomeAssistant
from homeassistant.helpers.intent import Intent, IntentHandler, IntentResponse
from typing import Any

from .core.const import DATA_SPEAKERS, DOMAIN

Expand All @@ -28,11 +30,19 @@ async def async_setup_intents(hass: HomeAssistant) -> None:
if not handlers:
return

async def listener(event: Event):
request_id = event.data["request_id"]
async def listener(event_data: Mapping[str, Any] | Event):

# Breaking change in 2024.4.0, check for Event for versions prior to this
if (
type(event_data) is Event
): # Intentionally avoid `isinstance` because it's slow and we trust `Event` is not subclassed
event_data = event_data.data

request_id = event_data["request_id"]

for handler in handlers:
if handler.request_id == request_id:
handler.response_text = event.data["text"]
handler.response_text = event_data["text"]
handler.response_waiter.set()
return

Expand Down

0 comments on commit a6f8695

Please sign in to comment.