diff --git a/homeassistant/components/esphome/__init__.py b/homeassistant/components/esphome/__init__.py index ea909725b9f..acbcc0f57dc 100644 --- a/homeassistant/components/esphome/__init__.py +++ b/homeassistant/components/esphome/__init__.py @@ -5,7 +5,7 @@ from collections.abc import Callable import functools import logging import math -from typing import TYPE_CHECKING, Any, Generic, NamedTuple, TypeVar, cast, overload +from typing import Any, Generic, NamedTuple, TypeVar, cast, overload from aioesphomeapi import ( APIClient, @@ -27,7 +27,7 @@ from aioesphomeapi import ( import voluptuous as vol from homeassistant import const -from homeassistant.components import zeroconf +from homeassistant.components import tag, zeroconf from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ATTR_DEVICE_ID, @@ -55,9 +55,6 @@ from .domain_data import DOMAIN, DomainData # Import config flow so that it's added to the registry from .entry_data import RuntimeEntryData -if TYPE_CHECKING: - from homeassistant.components.tag import TagProtocol - CONF_NOISE_PSK = "noise_psk" _LOGGER = logging.getLogger(__name__) _R = TypeVar("_R") @@ -134,11 +131,8 @@ async def async_setup_entry( # noqa: C901 # Call native tag scan if service_name == "tag_scanned" and device_id is not None: - # Importing tag via hass.components in case it is overridden - # in a custom_components (custom_components.tag) - tag: TagProtocol = hass.components.tag tag_id = service_data["tag_id"] - hass.async_create_task(tag.async_scan_tag(tag_id, device_id)) + hass.async_create_task(tag.async_scan_tag(hass, tag_id, device_id)) return hass.bus.async_fire( diff --git a/homeassistant/components/mobile_app/webhook.py b/homeassistant/components/mobile_app/webhook.py index 514d8820399..8dfadc6645d 100644 --- a/homeassistant/components/mobile_app/webhook.py +++ b/homeassistant/components/mobile_app/webhook.py @@ -7,14 +7,13 @@ from functools import wraps from http import HTTPStatus import logging import secrets -from typing import TYPE_CHECKING from aiohttp.web import HTTPBadRequest, Request, Response, json_response from nacl.exceptions import CryptoError from nacl.secret import SecretBox import voluptuous as vol -from homeassistant.components import camera, cloud, notify as hass_notify +from homeassistant.components import camera, cloud, notify as hass_notify, tag from homeassistant.components.binary_sensor import ( DEVICE_CLASSES as BINARY_SENSOR_CLASSES, ) @@ -114,10 +113,6 @@ from .helpers import ( webhook_response, ) -if TYPE_CHECKING: - from homeassistant.components.tag import TagProtocol - - _LOGGER = logging.getLogger(__name__) DELAY_SAVE = 10 @@ -688,10 +683,8 @@ async def webhook_get_config(hass, config_entry, data): @validate_schema({vol.Required("tag_id"): cv.string}) async def webhook_scan_tag(hass, config_entry, data): """Handle a fire event webhook.""" - # Importing tag via hass.components in case it is overridden - # in a custom_components (custom_components.tag) - tag: TagProtocol = hass.components.tag await tag.async_scan_tag( + hass, data["tag_id"], config_entry.data[ATTR_DEVICE_ID], registration_context(config_entry.data), diff --git a/homeassistant/components/mqtt/tag.py b/homeassistant/components/mqtt/tag.py index 223718554b0..132ab3200a1 100644 --- a/homeassistant/components/mqtt/tag.py +++ b/homeassistant/components/mqtt/tag.py @@ -3,10 +3,10 @@ from __future__ import annotations from collections.abc import Callable import functools -from typing import TYPE_CHECKING import voluptuous as vol +from homeassistant.components import tag from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_DEVICE, CONF_PLATFORM, CONF_VALUE_TEMPLATE from homeassistant.core import HomeAssistant @@ -28,9 +28,6 @@ from .models import MqttValueTemplate, ReceiveMessage, ReceivePayloadType from .subscription import EntitySubscription from .util import get_mqtt_data, valid_subscribe_topic -if TYPE_CHECKING: - from homeassistant.components.tag import TagProtocol - LOG_NAME = "Tag" TAG = "tag" @@ -139,10 +136,7 @@ class MQTTTagScanner(MqttDiscoveryDeviceUpdate): if not tag_id: # No output from template, ignore return - # Importing tag via hass.components in case it is overridden - # in a custom_components (custom_components.tag) - tag: TagProtocol = self.hass.components.tag - await tag.async_scan_tag(tag_id, self.device_id) + await tag.async_scan_tag(self.hass, tag_id, self.device_id) self._sub_state = subscription.async_prepare_subscribe_topics( self.hass, diff --git a/homeassistant/components/tag/__init__.py b/homeassistant/components/tag/__init__.py index 1b3ee9b646b..090835103f9 100644 --- a/homeassistant/components/tag/__init__.py +++ b/homeassistant/components/tag/__init__.py @@ -2,7 +2,6 @@ from __future__ import annotations import logging -from typing import Protocol import uuid import voluptuous as vol @@ -107,15 +106,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: return True -class TagProtocol(Protocol): - """Protocol for type checking.""" - - async def async_scan_tag( - self, tag_id: str, device_id: str | None, context: Context | None = None - ) -> None: - """Handle when a tag is scanned.""" - - @bind_hass async def async_scan_tag( hass: HomeAssistant,