Improve generic event typing [google_pubsub] (#114731)

This commit is contained in:
Marc Mueller 2024-04-06 14:20:31 +02:00 committed by GitHub
parent bf0309a722
commit 856567d674
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,7 +11,7 @@ from google.cloud.pubsub_v1 import PublisherClient
import voluptuous as vol
from homeassistant.const import EVENT_STATE_CHANGED, STATE_UNAVAILABLE, STATE_UNKNOWN
from homeassistant.core import Event, HomeAssistant
from homeassistant.core import Event, EventStateChangedData, HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entityfilter import FILTER_SCHEMA
from homeassistant.helpers.typing import ConfigType
@ -59,9 +59,9 @@ def setup(hass: HomeAssistant, yaml_config: ConfigType) -> bool:
encoder = DateTimeJSONEncoder()
def send_to_pubsub(event: Event):
def send_to_pubsub(event: Event[EventStateChangedData]):
"""Send states to Pub/Sub."""
state = event.data.get("new_state")
state = event.data["new_state"]
if (
state is None
or state.state in (STATE_UNKNOWN, "", STATE_UNAVAILABLE)