From 68f1c190490786577ef4fc9d87146a7cbc262b50 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 23 Aug 2021 17:04:42 +0200 Subject: [PATCH] Enable basic type checking for azure_event_hub (#55047) * Enable basic type checking for azure_event_hub * Update homeassistant/components/azure_event_hub/__init__.py Co-authored-by: Martin Hjelmare * Disable false pylint positive Co-authored-by: Martin Hjelmare --- .../components/azure_event_hub/__init__.py | 16 +++++++++------- .../components/azure_event_hub/const.py | 6 +++++- mypy.ini | 3 --- script/hassfest/mypy_config.py | 1 - 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/azure_event_hub/__init__.py b/homeassistant/components/azure_event_hub/__init__.py index 1c9add1bd8b..9bae21ec43b 100644 --- a/homeassistant/components/azure_event_hub/__init__.py +++ b/homeassistant/components/azure_event_hub/__init__.py @@ -5,9 +5,9 @@ import asyncio import json import logging import time -from typing import Any +from typing import Any, Callable -from azure.eventhub import EventData +from azure.eventhub import EventData, EventDataBatch from azure.eventhub.aio import EventHubProducerClient, EventHubSharedKeyCredential from azure.eventhub.exceptions import EventHubError import voluptuous as vol @@ -109,14 +109,16 @@ class AzureEventHub: ) -> None: """Initialize the listener.""" self.hass = hass - self.queue = asyncio.PriorityQueue() + self.queue: asyncio.PriorityQueue[ # pylint: disable=unsubscriptable-object + tuple[int, tuple[float, Event | None]] + ] = asyncio.PriorityQueue() self._client_args = client_args self._conn_str_client = conn_str_client self._entities_filter = entities_filter self._send_interval = send_interval self._max_delay = max_delay + send_interval - self._listener_remover = None - self._next_send_remover = None + self._listener_remover: Callable[[], None] | None = None + self._next_send_remover: Callable[[], None] | None = None self.shutdown = False async def async_start(self) -> None: @@ -169,7 +171,7 @@ class AzureEventHub: self.hass, self._send_interval, self.async_send ) - async def fill_batch(self, client) -> None: + async def fill_batch(self, client) -> tuple[EventDataBatch, int]: """Return a batch of events formatted for writing. Uses get_nowait instead of await get, because the functions batches and doesn't wait for each single event, the send function is called. @@ -207,7 +209,7 @@ class AzureEventHub: return event_batch, dequeue_count - def _event_to_filtered_event_data(self, event: Event) -> None: + def _event_to_filtered_event_data(self, event: Event) -> EventData | None: """Filter event states and create EventData object.""" state = event.data.get("new_state") if ( diff --git a/homeassistant/components/azure_event_hub/const.py b/homeassistant/components/azure_event_hub/const.py index 1786bb5cbf2..fdb5180fe4e 100644 --- a/homeassistant/components/azure_event_hub/const.py +++ b/homeassistant/components/azure_event_hub/const.py @@ -1,4 +1,8 @@ """Constants and shared schema for the Azure Event Hub integration.""" +from __future__ import annotations + +from typing import Any + DOMAIN = "azure_event_hub" CONF_EVENT_HUB_NAMESPACE = "event_hub_namespace" @@ -10,4 +14,4 @@ CONF_SEND_INTERVAL = "send_interval" CONF_MAX_DELAY = "max_delay" CONF_FILTER = "filter" -ADDITIONAL_ARGS = {"logging_enable": False} +ADDITIONAL_ARGS: dict[str, Any] = {"logging_enable": False} diff --git a/mypy.ini b/mypy.ini index 5c2c8678999..2d94878ee2a 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1268,9 +1268,6 @@ warn_unreachable = false [mypy-homeassistant.components.awair.*] ignore_errors = true -[mypy-homeassistant.components.azure_event_hub.*] -ignore_errors = true - [mypy-homeassistant.components.blueprint.*] ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index b22919ce5fa..b761bdee919 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -15,7 +15,6 @@ from .model import Config, Integration # Do your best to not add anything new here. IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.awair.*", - "homeassistant.components.azure_event_hub.*", "homeassistant.components.blueprint.*", "homeassistant.components.bmw_connected_drive.*", "homeassistant.components.cert_expiry.*",