mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Activate strict typing for nfandroidtv (#57743)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
aed6eee1ff
commit
19d812602e
@ -75,6 +75,7 @@ homeassistant.components.neato.*
|
|||||||
homeassistant.components.nest.*
|
homeassistant.components.nest.*
|
||||||
homeassistant.components.netatmo.*
|
homeassistant.components.netatmo.*
|
||||||
homeassistant.components.network.*
|
homeassistant.components.network.*
|
||||||
|
homeassistant.components.nfandroidtv.*
|
||||||
homeassistant.components.no_ip.*
|
homeassistant.components.no_ip.*
|
||||||
homeassistant.components.notify.*
|
homeassistant.components.notify.*
|
||||||
homeassistant.components.notion.*
|
homeassistant.components.notion.*
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from notifications_android_tv.notifications import ConnectError, Notifications
|
from notifications_android_tv.notifications import ConnectError, Notifications
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
@ -18,7 +19,9 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
class NFAndroidTVFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
class NFAndroidTVFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
"""Handle a config flow for NFAndroidTV."""
|
"""Handle a config flow for NFAndroidTV."""
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None) -> FlowResult:
|
async def async_step_user(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
"""Handle a flow initiated by the user."""
|
"""Handle a flow initiated by the user."""
|
||||||
errors = {}
|
errors = {}
|
||||||
|
|
||||||
@ -50,7 +53,7 @@ class NFAndroidTVFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
errors=errors,
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_import(self, import_config):
|
async def async_step_import(self, import_config: dict[str, Any]) -> FlowResult:
|
||||||
"""Import a config entry from configuration.yaml."""
|
"""Import a config entry from configuration.yaml."""
|
||||||
for entry in self._async_current_entries():
|
for entry in self._async_current_entries():
|
||||||
if entry.data[CONF_HOST] == import_config[CONF_HOST]:
|
if entry.data[CONF_HOST] == import_config[CONF_HOST]:
|
||||||
@ -63,7 +66,7 @@ class NFAndroidTVFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
return await self.async_step_user(import_config)
|
return await self.async_step_user(import_config)
|
||||||
|
|
||||||
async def _async_try_connect(self, host):
|
async def _async_try_connect(self, host: str) -> str | None:
|
||||||
"""Try connecting to Android TV / Fire TV."""
|
"""Try connecting to Android TV / Fire TV."""
|
||||||
try:
|
try:
|
||||||
await self.hass.async_add_executor_job(Notifications, host)
|
await self.hass.async_add_executor_job(Notifications, host)
|
||||||
@ -73,4 +76,4 @@ class NFAndroidTVFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
_LOGGER.exception("Unexpected exception")
|
_LOGGER.exception("Unexpected exception")
|
||||||
return "unknown"
|
return "unknown"
|
||||||
return
|
return None
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
"""Notifications for Android TV notification service."""
|
"""Notifications for Android TV notification service."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any, BinaryIO
|
||||||
|
|
||||||
from notifications_android_tv import Notifications
|
from notifications_android_tv import Notifications
|
||||||
import requests
|
import requests
|
||||||
@ -16,6 +19,7 @@ from homeassistant.components.notify import (
|
|||||||
from homeassistant.const import ATTR_ICON, CONF_HOST, CONF_TIMEOUT
|
from homeassistant.const import ATTR_ICON, CONF_HOST, CONF_TIMEOUT
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_COLOR,
|
ATTR_COLOR,
|
||||||
@ -63,7 +67,11 @@ PLATFORM_SCHEMA = cv.deprecated(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_get_service(hass: HomeAssistant, config, discovery_info=None):
|
async def async_get_service(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config: ConfigType,
|
||||||
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
|
) -> NFAndroidTVNotificationService:
|
||||||
"""Get the NFAndroidTV notification service."""
|
"""Get the NFAndroidTV notification service."""
|
||||||
if discovery_info is not None:
|
if discovery_info is not None:
|
||||||
notify = await hass.async_add_executor_job(
|
notify = await hass.async_add_executor_job(
|
||||||
@ -86,15 +94,15 @@ class NFAndroidTVNotificationService(BaseNotificationService):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
notify: Notifications,
|
notify: Notifications,
|
||||||
is_allowed_path,
|
is_allowed_path: Any,
|
||||||
):
|
) -> None:
|
||||||
"""Initialize the service."""
|
"""Initialize the service."""
|
||||||
self.notify = notify
|
self.notify = notify
|
||||||
self.is_allowed_path = is_allowed_path
|
self.is_allowed_path = is_allowed_path
|
||||||
|
|
||||||
def send_message(self, message="", **kwargs):
|
def send_message(self, message: str, **kwargs: Any) -> None:
|
||||||
"""Send a message to a Android TV device."""
|
"""Send a message to a Android TV device."""
|
||||||
data = kwargs.get(ATTR_DATA)
|
data: dict | None = kwargs.get(ATTR_DATA)
|
||||||
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
|
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
|
||||||
duration = None
|
duration = None
|
||||||
fontsize = None
|
fontsize = None
|
||||||
@ -107,7 +115,9 @@ class NFAndroidTVNotificationService(BaseNotificationService):
|
|||||||
if data:
|
if data:
|
||||||
if ATTR_DURATION in data:
|
if ATTR_DURATION in data:
|
||||||
try:
|
try:
|
||||||
duration = int(data.get(ATTR_DURATION))
|
duration = int(
|
||||||
|
data.get(ATTR_DURATION, Notifications.DEFAULT_DURATION)
|
||||||
|
)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"Invalid duration-value: %s", str(data.get(ATTR_DURATION))
|
"Invalid duration-value: %s", str(data.get(ATTR_DURATION))
|
||||||
@ -152,7 +162,7 @@ class NFAndroidTVNotificationService(BaseNotificationService):
|
|||||||
if filedata is not None:
|
if filedata is not None:
|
||||||
if ATTR_ICON in filedata:
|
if ATTR_ICON in filedata:
|
||||||
icon = self.load_file(
|
icon = self.load_file(
|
||||||
url=filedata.get(ATTR_ICON),
|
url=filedata[ATTR_ICON],
|
||||||
local_path=filedata.get(ATTR_FILE_PATH),
|
local_path=filedata.get(ATTR_FILE_PATH),
|
||||||
username=filedata.get(ATTR_FILE_USERNAME),
|
username=filedata.get(ATTR_FILE_USERNAME),
|
||||||
password=filedata.get(ATTR_FILE_PASSWORD),
|
password=filedata.get(ATTR_FILE_PASSWORD),
|
||||||
@ -179,14 +189,20 @@ class NFAndroidTVNotificationService(BaseNotificationService):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def load_file(
|
def load_file(
|
||||||
self, url=None, local_path=None, username=None, password=None, auth=None
|
self,
|
||||||
):
|
url: str | None = None,
|
||||||
|
local_path: str | None = None,
|
||||||
|
username: str | None = None,
|
||||||
|
password: str | None = None,
|
||||||
|
auth: str | None = None,
|
||||||
|
) -> bytes | BinaryIO | None:
|
||||||
"""Load image/document/etc from a local path or URL."""
|
"""Load image/document/etc from a local path or URL."""
|
||||||
try:
|
try:
|
||||||
if url is not None:
|
if url is not None:
|
||||||
# Check whether authentication parameters are provided
|
# Check whether authentication parameters are provided
|
||||||
if username is not None and password is not None:
|
if username is not None and password is not None:
|
||||||
# Use digest or basic authentication
|
# Use digest or basic authentication
|
||||||
|
auth_: HTTPDigestAuth | HTTPBasicAuth
|
||||||
if ATTR_FILE_AUTH_DIGEST == auth:
|
if ATTR_FILE_AUTH_DIGEST == auth:
|
||||||
auth_ = HTTPDigestAuth(username, password)
|
auth_ = HTTPDigestAuth(username, password)
|
||||||
else:
|
else:
|
||||||
|
11
mypy.ini
11
mypy.ini
@ -836,6 +836,17 @@ no_implicit_optional = true
|
|||||||
warn_return_any = true
|
warn_return_any = true
|
||||||
warn_unreachable = true
|
warn_unreachable = true
|
||||||
|
|
||||||
|
[mypy-homeassistant.components.nfandroidtv.*]
|
||||||
|
check_untyped_defs = true
|
||||||
|
disallow_incomplete_defs = true
|
||||||
|
disallow_subclassing_any = true
|
||||||
|
disallow_untyped_calls = true
|
||||||
|
disallow_untyped_decorators = true
|
||||||
|
disallow_untyped_defs = true
|
||||||
|
no_implicit_optional = true
|
||||||
|
warn_return_any = true
|
||||||
|
warn_unreachable = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.no_ip.*]
|
[mypy-homeassistant.components.no_ip.*]
|
||||||
check_untyped_defs = true
|
check_untyped_defs = true
|
||||||
disallow_incomplete_defs = true
|
disallow_incomplete_defs = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user