diff --git a/homeassistant/components/mobile_app/binary_sensor.py b/homeassistant/components/mobile_app/binary_sensor.py index d9d766974fd..4d40e42a47e 100644 --- a/homeassistant/components/mobile_app/binary_sensor.py +++ b/homeassistant/components/mobile_app/binary_sensor.py @@ -1,4 +1,6 @@ """Binary sensor platform for mobile_app.""" +from typing import Any + from homeassistant.components.binary_sensor import BinarySensorEntity from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_NAME, CONF_UNIQUE_ID, CONF_WEBHOOK_ID, STATE_ON @@ -18,7 +20,6 @@ from .const import ( ATTR_SENSOR_TYPE, ATTR_SENSOR_TYPE_BINARY_SENSOR as ENTITY_TYPE, ATTR_SENSOR_UNIQUE_ID, - DATA_DEVICES, DOMAIN, ) from .entity import MobileAppEntity, unique_id @@ -39,7 +40,7 @@ async def async_setup_entry( for entry in entries: if entry.domain != ENTITY_TYPE or entry.disabled_by: continue - config = { + config: dict[str, Any] = { ATTR_SENSOR_ATTRIBUTES: {}, ATTR_SENSOR_DEVICE_CLASS: entry.device_class or entry.original_device_class, ATTR_SENSOR_ICON: entry.original_icon, @@ -49,7 +50,7 @@ async def async_setup_entry( ATTR_SENSOR_UNIQUE_ID: entry.unique_id, ATTR_SENSOR_ENTITY_CATEGORY: entry.entity_category, } - entities.append(MobileAppBinarySensor(config, entry.device_id, config_entry)) + entities.append(MobileAppBinarySensor(config, config_entry)) async_add_entities(entities) @@ -65,9 +66,7 @@ async def async_setup_entry( CONF_NAME ] = f"{config_entry.data[ATTR_DEVICE_NAME]} {data[ATTR_SENSOR_NAME]}" - device = hass.data[DOMAIN][DATA_DEVICES][data[CONF_WEBHOOK_ID]] - - async_add_entities([MobileAppBinarySensor(data, device, config_entry)]) + async_add_entities([MobileAppBinarySensor(data, config_entry)]) async_dispatcher_connect( hass, diff --git a/homeassistant/components/mobile_app/device_action.py b/homeassistant/components/mobile_app/device_action.py index 3ad43098225..d17702ec24f 100644 --- a/homeassistant/components/mobile_app/device_action.py +++ b/homeassistant/components/mobile_app/device_action.py @@ -7,6 +7,7 @@ from homeassistant.components import notify from homeassistant.components.device_automation import InvalidDeviceAutomationConfig from homeassistant.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_TYPE from homeassistant.core import Context, HomeAssistant +from homeassistant.exceptions import TemplateError from homeassistant.helpers import config_validation as cv, template from .const import DOMAIN @@ -62,7 +63,7 @@ async def async_call_action_from_config( try: service_data[key] = template.render_complex(value_template, variables) - except template.TemplateError as err: + except TemplateError as err: raise InvalidDeviceAutomationConfig( f"Error rendering {key}: {err}" ) from err diff --git a/homeassistant/components/mobile_app/device_tracker.py b/homeassistant/components/mobile_app/device_tracker.py index 67f3672ef8d..5e2ae23af16 100644 --- a/homeassistant/components/mobile_app/device_tracker.py +++ b/homeassistant/components/mobile_app/device_tracker.py @@ -37,7 +37,6 @@ async def async_setup_entry( """Set up OwnTracks based off an entry.""" entity = MobileAppEntity(entry) async_add_entities([entity]) - return True class MobileAppEntity(TrackerEntity, RestoreEntity): diff --git a/homeassistant/components/mobile_app/entity.py b/homeassistant/components/mobile_app/entity.py index 0c26533b7cb..0cb6cfc6fcc 100644 --- a/homeassistant/components/mobile_app/entity.py +++ b/homeassistant/components/mobile_app/entity.py @@ -1,4 +1,6 @@ """A entity class for mobile_app.""" +from __future__ import annotations + from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ATTR_ICON, @@ -8,7 +10,6 @@ from homeassistant.const import ( STATE_UNAVAILABLE, ) from homeassistant.core import callback -from homeassistant.helpers.device_registry import DeviceEntry from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.restore_state import RestoreEntity @@ -33,10 +34,9 @@ def unique_id(webhook_id, sensor_unique_id): class MobileAppEntity(RestoreEntity): """Representation of an mobile app entity.""" - def __init__(self, config: dict, device: DeviceEntry, entry: ConfigEntry) -> None: + def __init__(self, config: dict, entry: ConfigEntry) -> None: """Initialize the entity.""" self._config = config - self._device = device self._entry = entry self._registration = entry.data self._unique_id = config[CONF_UNIQUE_ID] diff --git a/homeassistant/components/mobile_app/helpers.py b/homeassistant/components/mobile_app/helpers.py index c4e0a81560b..b7d38357a78 100644 --- a/homeassistant/components/mobile_app/helpers.py +++ b/homeassistant/components/mobile_app/helpers.py @@ -60,7 +60,7 @@ def setup_encrypt() -> tuple[int, Callable]: return (SecretBox.KEY_SIZE, encrypt) -def _decrypt_payload(key: str, ciphertext: str) -> dict[str, str]: +def _decrypt_payload(key: str | None, ciphertext: str) -> dict[str, str] | None: """Decrypt encrypted payload.""" try: keylen, decrypt = setup_decrypt() @@ -72,13 +72,13 @@ def _decrypt_payload(key: str, ciphertext: str) -> dict[str, str]: _LOGGER.warning("Ignoring encrypted payload because no decryption key known") return None - key = key.encode("utf-8") - key = key[:keylen] - key = key.ljust(keylen, b"\0") + key_bytes = key.encode("utf-8") + key_bytes = key_bytes[:keylen] + key_bytes = key_bytes.ljust(keylen, b"\0") try: - message = decrypt(ciphertext, key) - message = json.loads(message.decode("utf-8")) + msg_bytes = decrypt(ciphertext, key_bytes) + message = json.loads(msg_bytes.decode("utf-8")) _LOGGER.debug("Successfully decrypted mobile_app payload") return message except ValueError: diff --git a/homeassistant/components/mobile_app/http_api.py b/homeassistant/components/mobile_app/http_api.py index a80e7db204e..20fa25ec21f 100644 --- a/homeassistant/components/mobile_app/http_api.py +++ b/homeassistant/components/mobile_app/http_api.py @@ -4,6 +4,7 @@ from __future__ import annotations from contextlib import suppress from http import HTTPStatus import secrets +from typing import cast from aiohttp.web import Request, Response import emoji @@ -89,7 +90,7 @@ class RegistrationsView(HomeAssistantView): # If otherwise empty string contains emoji # use descriptive name of the first emoji data[ATTR_DEVICE_NAME] = emoji.demojize( - emoji.emoji_lis(data[ATTR_DEVICE_NAME])[0]["emoji"] + cast(str, emoji.emoji_lis(data[ATTR_DEVICE_NAME])[0]["emoji"]) ).replace(":", "") else: # Fallback to DEVICE_ID diff --git a/homeassistant/components/mobile_app/push_notification.py b/homeassistant/components/mobile_app/push_notification.py index f3852895d32..0ef9739c8bd 100644 --- a/homeassistant/components/mobile_app/push_notification.py +++ b/homeassistant/components/mobile_app/push_notification.py @@ -28,7 +28,7 @@ class PushChannel: self.support_confirm = support_confirm self._send_message = send_message self.on_teardown = on_teardown - self.pending_confirms = {} + self.pending_confirms: dict[str, dict] = {} @callback def async_send_notification(self, data, fallback_send): diff --git a/homeassistant/components/mobile_app/sensor.py b/homeassistant/components/mobile_app/sensor.py index 32477ccb50a..45bc4acd6a2 100644 --- a/homeassistant/components/mobile_app/sensor.py +++ b/homeassistant/components/mobile_app/sensor.py @@ -1,6 +1,8 @@ """Sensor platform for mobile_app.""" from __future__ import annotations +from typing import Any + from homeassistant.components.sensor import SensorDeviceClass, SensorEntity from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -28,7 +30,6 @@ from .const import ( ATTR_SENSOR_TYPE_SENSOR as ENTITY_TYPE, ATTR_SENSOR_UNIQUE_ID, ATTR_SENSOR_UOM, - DATA_DEVICES, DOMAIN, ) from .entity import MobileAppEntity, unique_id @@ -49,7 +50,7 @@ async def async_setup_entry( for entry in entries: if entry.domain != ENTITY_TYPE or entry.disabled_by: continue - config = { + config: dict[str, Any] = { ATTR_SENSOR_ATTRIBUTES: {}, ATTR_SENSOR_DEVICE_CLASS: entry.device_class or entry.original_device_class, ATTR_SENSOR_ICON: entry.original_icon, @@ -60,7 +61,7 @@ async def async_setup_entry( ATTR_SENSOR_UOM: entry.unit_of_measurement, ATTR_SENSOR_ENTITY_CATEGORY: entry.entity_category, } - entities.append(MobileAppSensor(config, entry.device_id, config_entry)) + entities.append(MobileAppSensor(config, config_entry)) async_add_entities(entities) @@ -76,9 +77,7 @@ async def async_setup_entry( CONF_NAME ] = f"{config_entry.data[ATTR_DEVICE_NAME]} {data[ATTR_SENSOR_NAME]}" - device = hass.data[DOMAIN][DATA_DEVICES][data[CONF_WEBHOOK_ID]] - - async_add_entities([MobileAppSensor(data, device, config_entry)]) + async_add_entities([MobileAppSensor(data, config_entry)]) async_dispatcher_connect( hass, diff --git a/mypy.ini b/mypy.ini index adb0cb25297..3f8386a2a27 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2477,27 +2477,6 @@ ignore_errors = true [mypy-homeassistant.components.minecraft_server.sensor] ignore_errors = true -[mypy-homeassistant.components.mobile_app.binary_sensor] -ignore_errors = true - -[mypy-homeassistant.components.mobile_app.device_action] -ignore_errors = true - -[mypy-homeassistant.components.mobile_app.device_tracker] -ignore_errors = true - -[mypy-homeassistant.components.mobile_app.helpers] -ignore_errors = true - -[mypy-homeassistant.components.mobile_app.http_api] -ignore_errors = true - -[mypy-homeassistant.components.mobile_app.push_notification] -ignore_errors = true - -[mypy-homeassistant.components.mobile_app.sensor] -ignore_errors = true - [mypy-homeassistant.components.netgear] ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index 8d542290458..ef29562578e 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -94,13 +94,6 @@ IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.minecraft_server", "homeassistant.components.minecraft_server.helpers", "homeassistant.components.minecraft_server.sensor", - "homeassistant.components.mobile_app.binary_sensor", - "homeassistant.components.mobile_app.device_action", - "homeassistant.components.mobile_app.device_tracker", - "homeassistant.components.mobile_app.helpers", - "homeassistant.components.mobile_app.http_api", - "homeassistant.components.mobile_app.push_notification", - "homeassistant.components.mobile_app.sensor", "homeassistant.components.netgear", "homeassistant.components.netgear.config_flow", "homeassistant.components.netgear.device_tracker",