Skip to content

Commit

Permalink
Code refactoring after #479
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Apr 5, 2024
1 parent a6f8695 commit c733199
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions custom_components/yandex_station/intent.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import asyncio
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 @@ -30,12 +27,10 @@ async def async_setup_intents(hass: HomeAssistant) -> None:
if not handlers:
return

async def listener(event_data: Mapping[str, Any] | Event):

async def listener(event_data: dict | 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
# Intentionally avoid `isinstance` because it's slow and we trust `Event` is not subclassed
if type(event_data) is Event:
event_data = event_data.data

request_id = event_data["request_id"]
Expand All @@ -51,7 +46,7 @@ async def listener(event_data: Mapping[str, Any] | Event):

class YandexIntentHandler(IntentHandler):
request_id: str = None
response_text: Optional[str] = None
response_text: str | None = None
response_waiter = None

def __init__(self, entity_id: str):
Expand Down

0 comments on commit c733199

Please sign in to comment.