From af9ac9022bc78b86adf306f74dcfd3afcfeb6fd3 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 15 Nov 2022 18:27:37 +0100 Subject: [PATCH] Import tag via hass.components in mobile_app (#82138) * Import tag via hass.components in mobile_app * Update webhook.py --- homeassistant/components/mobile_app/webhook.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/mobile_app/webhook.py b/homeassistant/components/mobile_app/webhook.py index 7c6bcc58db9..514d8820399 100644 --- a/homeassistant/components/mobile_app/webhook.py +++ b/homeassistant/components/mobile_app/webhook.py @@ -1,17 +1,20 @@ """Webhook handlers for mobile_app.""" +from __future__ import annotations + import asyncio from contextlib import suppress 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, tag +from homeassistant.components import camera, cloud, notify as hass_notify from homeassistant.components.binary_sensor import ( DEVICE_CLASSES as BINARY_SENSOR_CLASSES, ) @@ -111,6 +114,10 @@ from .helpers import ( webhook_response, ) +if TYPE_CHECKING: + from homeassistant.components.tag import TagProtocol + + _LOGGER = logging.getLogger(__name__) DELAY_SAVE = 10 @@ -681,8 +688,10 @@ 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),