mirror of
https://github.com/home-assistant/core.git
synced 2025-04-30 20:27:57 +00:00
Enable basic type checking for almond (#54927)
* Enable basic type checking for almond * Tweak * Address review comments
This commit is contained in:
parent
e5d6e18e30
commit
03bda6ed15
@ -5,6 +5,7 @@ import asyncio
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
from typing import Optional, cast
|
||||||
|
|
||||||
from aiohttp import ClientError, ClientSession
|
from aiohttp import ClientError, ClientSession
|
||||||
import async_timeout
|
import async_timeout
|
||||||
@ -166,7 +167,7 @@ async def _configure_almond_for_ha(
|
|||||||
|
|
||||||
_LOGGER.debug("Configuring Almond to connect to Home Assistant at %s", hass_url)
|
_LOGGER.debug("Configuring Almond to connect to Home Assistant at %s", hass_url)
|
||||||
store = storage.Store(hass, STORAGE_VERSION, STORAGE_KEY)
|
store = storage.Store(hass, STORAGE_VERSION, STORAGE_KEY)
|
||||||
data = await store.async_load()
|
data = cast(Optional[dict], await store.async_load())
|
||||||
|
|
||||||
if data is None:
|
if data is None:
|
||||||
data = {}
|
data = {}
|
||||||
@ -204,7 +205,7 @@ async def _configure_almond_for_ha(
|
|||||||
)
|
)
|
||||||
except (asyncio.TimeoutError, ClientError) as err:
|
except (asyncio.TimeoutError, ClientError) as err:
|
||||||
if isinstance(err, asyncio.TimeoutError):
|
if isinstance(err, asyncio.TimeoutError):
|
||||||
msg = "Request timeout"
|
msg: str | ClientError = "Request timeout"
|
||||||
else:
|
else:
|
||||||
msg = err
|
msg = err
|
||||||
_LOGGER.warning("Unable to configure Almond: %s", msg)
|
_LOGGER.warning("Unable to configure Almond: %s", msg)
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
"""Config flow to connect with Home Assistant."""
|
"""Config flow to connect with Home Assistant."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from aiohttp import ClientError
|
from aiohttp import ClientError
|
||||||
import async_timeout
|
import async_timeout
|
||||||
@ -9,6 +12,7 @@ import voluptuous as vol
|
|||||||
from yarl import URL
|
from yarl import URL
|
||||||
|
|
||||||
from homeassistant import config_entries, core, data_entry_flow
|
from homeassistant import config_entries, core, data_entry_flow
|
||||||
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
from homeassistant.helpers import aiohttp_client, config_entry_oauth2_flow
|
from homeassistant.helpers import aiohttp_client, config_entry_oauth2_flow
|
||||||
|
|
||||||
from .const import DOMAIN as ALMOND_DOMAIN, TYPE_LOCAL, TYPE_OAUTH2
|
from .const import DOMAIN as ALMOND_DOMAIN, TYPE_LOCAL, TYPE_OAUTH2
|
||||||
@ -64,7 +68,7 @@ class AlmondFlowHandler(config_entry_oauth2_flow.AbstractOAuth2FlowHandler):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
async def async_oauth_create_entry(self, data: dict) -> dict:
|
async def async_oauth_create_entry(self, data: dict) -> FlowResult:
|
||||||
"""Create an entry for the flow.
|
"""Create an entry for the flow.
|
||||||
|
|
||||||
Ok to override if you want to fetch extra info or even add another step.
|
Ok to override if you want to fetch extra info or even add another step.
|
||||||
@ -73,7 +77,7 @@ class AlmondFlowHandler(config_entry_oauth2_flow.AbstractOAuth2FlowHandler):
|
|||||||
data["host"] = self.host
|
data["host"] = self.host
|
||||||
return self.async_create_entry(title=self.flow_impl.name, data=data)
|
return self.async_create_entry(title=self.flow_impl.name, data=data)
|
||||||
|
|
||||||
async def async_step_import(self, user_input: dict = None) -> dict:
|
async def async_step_import(self, user_input: dict[str, Any]) -> FlowResult:
|
||||||
"""Import data."""
|
"""Import data."""
|
||||||
# Only allow 1 instance.
|
# Only allow 1 instance.
|
||||||
if self._async_current_entries():
|
if self._async_current_entries():
|
||||||
|
3
mypy.ini
3
mypy.ini
@ -1265,9 +1265,6 @@ no_implicit_optional = false
|
|||||||
warn_return_any = false
|
warn_return_any = false
|
||||||
warn_unreachable = false
|
warn_unreachable = false
|
||||||
|
|
||||||
[mypy-homeassistant.components.almond.*]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.awair.*]
|
[mypy-homeassistant.components.awair.*]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ from .model import Config, Integration
|
|||||||
# remove your component from this list to enable type checks.
|
# remove your component from this list to enable type checks.
|
||||||
# Do your best to not add anything new here.
|
# Do your best to not add anything new here.
|
||||||
IGNORED_MODULES: Final[list[str]] = [
|
IGNORED_MODULES: Final[list[str]] = [
|
||||||
"homeassistant.components.almond.*",
|
|
||||||
"homeassistant.components.awair.*",
|
"homeassistant.components.awair.*",
|
||||||
"homeassistant.components.azure_event_hub.*",
|
"homeassistant.components.azure_event_hub.*",
|
||||||
"homeassistant.components.blueprint.*",
|
"homeassistant.components.blueprint.*",
|
||||||
|
@ -82,7 +82,7 @@ async def test_abort_if_existing_entry(hass):
|
|||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "single_instance_allowed"
|
assert result["reason"] == "single_instance_allowed"
|
||||||
|
|
||||||
result = await flow.async_step_import()
|
result = await flow.async_step_import({})
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "single_instance_allowed"
|
assert result["reason"] == "single_instance_allowed"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user