Extend typing on scaffold templates (#48232)

This commit is contained in:
Franck Nijhof 2021-03-26 15:19:44 +01:00 committed by GitHub
parent 3bc6497cbd
commit d2d78d6205
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 85 additions and 44 deletions

View file

@ -1,5 +1,8 @@
"""The NEW_NAME integration."""
from __future__ import annotations
import asyncio
from typing import Any
import voluptuous as vol
@ -32,7 +35,7 @@ CONFIG_SCHEMA = vol.Schema(
PLATFORMS = ["light"]
async def async_setup(hass: HomeAssistant, config: dict):
async def async_setup(hass: HomeAssistant, config: dict[str, Any]) -> bool:
"""Set up the NEW_NAME component."""
hass.data[DOMAIN] = {}
@ -54,7 +57,7 @@ async def async_setup(hass: HomeAssistant, config: dict):
return True
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up NEW_NAME from a config entry."""
implementation = (
await config_entry_oauth2_flow.async_get_config_entry_implementation(
@ -80,7 +83,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
unload_ok = all(
await asyncio.gather(

View file

@ -4,7 +4,7 @@ from asyncio import run_coroutine_threadsafe
from aiohttp import ClientSession
import my_pypi_package
from homeassistant import core
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_entry_oauth2_flow
# TODO the following two API examples are based on our suggested best practices
@ -17,9 +17,9 @@ class ConfigEntryAuth(my_pypi_package.AbstractAuth):
def __init__(
self,
hass: core.HomeAssistant,
hass: HomeAssistant,
oauth_session: config_entry_oauth2_flow.OAuth2Session,
):
) -> None:
"""Initialize NEW_NAME Auth."""
self.hass = hass
self.session = oauth_session
@ -41,7 +41,7 @@ class AsyncConfigEntryAuth(my_pypi_package.AbstractAuth):
self,
websession: ClientSession,
oauth_session: config_entry_oauth2_flow.OAuth2Session,
):
) -> None:
"""Initialize NEW_NAME auth."""
super().__init__(websession)
self._oauth_session = oauth_session

View file

@ -7,6 +7,7 @@ from homeassistant.components.NEW_DOMAIN.const import (
OAUTH2_AUTHORIZE,
OAUTH2_TOKEN,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_entry_oauth2_flow
CLIENT_ID = "1234"
@ -14,8 +15,11 @@ CLIENT_SECRET = "5678"
async def test_full_flow(
hass, aiohttp_client, aioclient_mock, current_request_with_host
):
hass: HomeAssistant,
aiohttp_client,
aioclient_mock,
current_request_with_host,
) -> None:
"""Check full flow."""
assert await setup.async_setup_component(
hass,