Fix type issues [mobile_app] (#67091)
This commit is contained in:
parent
49aabcb2ac
commit
8b7639940e
10 changed files with 24 additions and 53 deletions
|
@ -1,4 +1,6 @@
|
||||||
"""Binary sensor platform for mobile_app."""
|
"""Binary sensor platform for mobile_app."""
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
from homeassistant.components.binary_sensor import BinarySensorEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_NAME, CONF_UNIQUE_ID, CONF_WEBHOOK_ID, STATE_ON
|
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,
|
||||||
ATTR_SENSOR_TYPE_BINARY_SENSOR as ENTITY_TYPE,
|
ATTR_SENSOR_TYPE_BINARY_SENSOR as ENTITY_TYPE,
|
||||||
ATTR_SENSOR_UNIQUE_ID,
|
ATTR_SENSOR_UNIQUE_ID,
|
||||||
DATA_DEVICES,
|
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
from .entity import MobileAppEntity, unique_id
|
from .entity import MobileAppEntity, unique_id
|
||||||
|
@ -39,7 +40,7 @@ async def async_setup_entry(
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
if entry.domain != ENTITY_TYPE or entry.disabled_by:
|
if entry.domain != ENTITY_TYPE or entry.disabled_by:
|
||||||
continue
|
continue
|
||||||
config = {
|
config: dict[str, Any] = {
|
||||||
ATTR_SENSOR_ATTRIBUTES: {},
|
ATTR_SENSOR_ATTRIBUTES: {},
|
||||||
ATTR_SENSOR_DEVICE_CLASS: entry.device_class or entry.original_device_class,
|
ATTR_SENSOR_DEVICE_CLASS: entry.device_class or entry.original_device_class,
|
||||||
ATTR_SENSOR_ICON: entry.original_icon,
|
ATTR_SENSOR_ICON: entry.original_icon,
|
||||||
|
@ -49,7 +50,7 @@ async def async_setup_entry(
|
||||||
ATTR_SENSOR_UNIQUE_ID: entry.unique_id,
|
ATTR_SENSOR_UNIQUE_ID: entry.unique_id,
|
||||||
ATTR_SENSOR_ENTITY_CATEGORY: entry.entity_category,
|
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)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
@ -65,9 +66,7 @@ async def async_setup_entry(
|
||||||
CONF_NAME
|
CONF_NAME
|
||||||
] = f"{config_entry.data[ATTR_DEVICE_NAME]} {data[ATTR_SENSOR_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, config_entry)])
|
||||||
|
|
||||||
async_add_entities([MobileAppBinarySensor(data, device, config_entry)])
|
|
||||||
|
|
||||||
async_dispatcher_connect(
|
async_dispatcher_connect(
|
||||||
hass,
|
hass,
|
||||||
|
|
|
@ -7,6 +7,7 @@ from homeassistant.components import notify
|
||||||
from homeassistant.components.device_automation import InvalidDeviceAutomationConfig
|
from homeassistant.components.device_automation import InvalidDeviceAutomationConfig
|
||||||
from homeassistant.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_TYPE
|
from homeassistant.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_TYPE
|
||||||
from homeassistant.core import Context, HomeAssistant
|
from homeassistant.core import Context, HomeAssistant
|
||||||
|
from homeassistant.exceptions import TemplateError
|
||||||
from homeassistant.helpers import config_validation as cv, template
|
from homeassistant.helpers import config_validation as cv, template
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
@ -62,7 +63,7 @@ async def async_call_action_from_config(
|
||||||
|
|
||||||
try:
|
try:
|
||||||
service_data[key] = template.render_complex(value_template, variables)
|
service_data[key] = template.render_complex(value_template, variables)
|
||||||
except template.TemplateError as err:
|
except TemplateError as err:
|
||||||
raise InvalidDeviceAutomationConfig(
|
raise InvalidDeviceAutomationConfig(
|
||||||
f"Error rendering {key}: {err}"
|
f"Error rendering {key}: {err}"
|
||||||
) from err
|
) from err
|
||||||
|
|
|
@ -37,7 +37,6 @@ async def async_setup_entry(
|
||||||
"""Set up OwnTracks based off an entry."""
|
"""Set up OwnTracks based off an entry."""
|
||||||
entity = MobileAppEntity(entry)
|
entity = MobileAppEntity(entry)
|
||||||
async_add_entities([entity])
|
async_add_entities([entity])
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class MobileAppEntity(TrackerEntity, RestoreEntity):
|
class MobileAppEntity(TrackerEntity, RestoreEntity):
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
"""A entity class for mobile_app."""
|
"""A entity class for mobile_app."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ICON,
|
ATTR_ICON,
|
||||||
|
@ -8,7 +10,6 @@ from homeassistant.const import (
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.device_registry import DeviceEntry
|
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
|
|
||||||
|
@ -33,10 +34,9 @@ def unique_id(webhook_id, sensor_unique_id):
|
||||||
class MobileAppEntity(RestoreEntity):
|
class MobileAppEntity(RestoreEntity):
|
||||||
"""Representation of an mobile app entity."""
|
"""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."""
|
"""Initialize the entity."""
|
||||||
self._config = config
|
self._config = config
|
||||||
self._device = device
|
|
||||||
self._entry = entry
|
self._entry = entry
|
||||||
self._registration = entry.data
|
self._registration = entry.data
|
||||||
self._unique_id = config[CONF_UNIQUE_ID]
|
self._unique_id = config[CONF_UNIQUE_ID]
|
||||||
|
|
|
@ -60,7 +60,7 @@ def setup_encrypt() -> tuple[int, Callable]:
|
||||||
return (SecretBox.KEY_SIZE, encrypt)
|
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."""
|
"""Decrypt encrypted payload."""
|
||||||
try:
|
try:
|
||||||
keylen, decrypt = setup_decrypt()
|
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")
|
_LOGGER.warning("Ignoring encrypted payload because no decryption key known")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
key = key.encode("utf-8")
|
key_bytes = key.encode("utf-8")
|
||||||
key = key[:keylen]
|
key_bytes = key_bytes[:keylen]
|
||||||
key = key.ljust(keylen, b"\0")
|
key_bytes = key_bytes.ljust(keylen, b"\0")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
message = decrypt(ciphertext, key)
|
msg_bytes = decrypt(ciphertext, key_bytes)
|
||||||
message = json.loads(message.decode("utf-8"))
|
message = json.loads(msg_bytes.decode("utf-8"))
|
||||||
_LOGGER.debug("Successfully decrypted mobile_app payload")
|
_LOGGER.debug("Successfully decrypted mobile_app payload")
|
||||||
return message
|
return message
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
import secrets
|
import secrets
|
||||||
|
from typing import cast
|
||||||
|
|
||||||
from aiohttp.web import Request, Response
|
from aiohttp.web import Request, Response
|
||||||
import emoji
|
import emoji
|
||||||
|
@ -89,7 +90,7 @@ class RegistrationsView(HomeAssistantView):
|
||||||
# If otherwise empty string contains emoji
|
# If otherwise empty string contains emoji
|
||||||
# use descriptive name of the first emoji
|
# use descriptive name of the first emoji
|
||||||
data[ATTR_DEVICE_NAME] = emoji.demojize(
|
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(":", "")
|
).replace(":", "")
|
||||||
else:
|
else:
|
||||||
# Fallback to DEVICE_ID
|
# Fallback to DEVICE_ID
|
||||||
|
|
|
@ -28,7 +28,7 @@ class PushChannel:
|
||||||
self.support_confirm = support_confirm
|
self.support_confirm = support_confirm
|
||||||
self._send_message = send_message
|
self._send_message = send_message
|
||||||
self.on_teardown = on_teardown
|
self.on_teardown = on_teardown
|
||||||
self.pending_confirms = {}
|
self.pending_confirms: dict[str, dict] = {}
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_send_notification(self, data, fallback_send):
|
def async_send_notification(self, data, fallback_send):
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
"""Sensor platform for mobile_app."""
|
"""Sensor platform for mobile_app."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
@ -28,7 +30,6 @@ from .const import (
|
||||||
ATTR_SENSOR_TYPE_SENSOR as ENTITY_TYPE,
|
ATTR_SENSOR_TYPE_SENSOR as ENTITY_TYPE,
|
||||||
ATTR_SENSOR_UNIQUE_ID,
|
ATTR_SENSOR_UNIQUE_ID,
|
||||||
ATTR_SENSOR_UOM,
|
ATTR_SENSOR_UOM,
|
||||||
DATA_DEVICES,
|
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
from .entity import MobileAppEntity, unique_id
|
from .entity import MobileAppEntity, unique_id
|
||||||
|
@ -49,7 +50,7 @@ async def async_setup_entry(
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
if entry.domain != ENTITY_TYPE or entry.disabled_by:
|
if entry.domain != ENTITY_TYPE or entry.disabled_by:
|
||||||
continue
|
continue
|
||||||
config = {
|
config: dict[str, Any] = {
|
||||||
ATTR_SENSOR_ATTRIBUTES: {},
|
ATTR_SENSOR_ATTRIBUTES: {},
|
||||||
ATTR_SENSOR_DEVICE_CLASS: entry.device_class or entry.original_device_class,
|
ATTR_SENSOR_DEVICE_CLASS: entry.device_class or entry.original_device_class,
|
||||||
ATTR_SENSOR_ICON: entry.original_icon,
|
ATTR_SENSOR_ICON: entry.original_icon,
|
||||||
|
@ -60,7 +61,7 @@ async def async_setup_entry(
|
||||||
ATTR_SENSOR_UOM: entry.unit_of_measurement,
|
ATTR_SENSOR_UOM: entry.unit_of_measurement,
|
||||||
ATTR_SENSOR_ENTITY_CATEGORY: entry.entity_category,
|
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)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
@ -76,9 +77,7 @@ async def async_setup_entry(
|
||||||
CONF_NAME
|
CONF_NAME
|
||||||
] = f"{config_entry.data[ATTR_DEVICE_NAME]} {data[ATTR_SENSOR_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, config_entry)])
|
||||||
|
|
||||||
async_add_entities([MobileAppSensor(data, device, config_entry)])
|
|
||||||
|
|
||||||
async_dispatcher_connect(
|
async_dispatcher_connect(
|
||||||
hass,
|
hass,
|
||||||
|
|
21
mypy.ini
21
mypy.ini
|
@ -2477,27 +2477,6 @@ ignore_errors = true
|
||||||
[mypy-homeassistant.components.minecraft_server.sensor]
|
[mypy-homeassistant.components.minecraft_server.sensor]
|
||||||
ignore_errors = true
|
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]
|
[mypy-homeassistant.components.netgear]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
|
|
@ -94,13 +94,6 @@ IGNORED_MODULES: Final[list[str]] = [
|
||||||
"homeassistant.components.minecraft_server",
|
"homeassistant.components.minecraft_server",
|
||||||
"homeassistant.components.minecraft_server.helpers",
|
"homeassistant.components.minecraft_server.helpers",
|
||||||
"homeassistant.components.minecraft_server.sensor",
|
"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",
|
||||||
"homeassistant.components.netgear.config_flow",
|
"homeassistant.components.netgear.config_flow",
|
||||||
"homeassistant.components.netgear.device_tracker",
|
"homeassistant.components.netgear.device_tracker",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue