Address style issues in nest typing (#53236)

* Add additional types for config flow

Fixing style errors introduced by partial typing in pr #53214

* Address typing style errors

Make all functions fully typed, follow up to pr #53214
This commit is contained in:
Allen Porter 2021-07-20 08:41:48 -07:00 committed by GitHub
parent f819be7acc
commit 1fe2d0f9c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,11 +17,12 @@ import asyncio
from collections import OrderedDict
import logging
import os
from typing import Any
import async_timeout
import voluptuous as vol
from homeassistant.core import callback
from homeassistant.core import HomeAssistant, callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_entry_oauth2_flow
@ -80,7 +81,7 @@ class NestFlowHandler(
self._reauth = False
@classmethod
def register_sdm_api(cls, hass) -> None:
def register_sdm_api(cls, hass: HomeAssistant) -> None:
"""Configure the flow handler to use the SDM API."""
if DOMAIN not in hass.data:
hass.data[DOMAIN] = {}
@ -105,7 +106,7 @@ class NestFlowHandler(
"prompt": "consent",
}
async def async_oauth_create_entry(self, data: dict) -> FlowResult:
async def async_oauth_create_entry(self, data: dict[str, Any]) -> FlowResult:
"""Create an entry for the SDM flow."""
assert self.is_sdm_api(), "Step only supported for SDM API"
data[DATA_SDM] = {}
@ -129,13 +130,17 @@ class NestFlowHandler(
return await super().async_oauth_create_entry(data)
async def async_step_reauth(self, user_input=None) -> FlowResult:
async def async_step_reauth(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Perform reauth upon an API authentication error."""
assert self.is_sdm_api(), "Step only supported for SDM API"
self._reauth = True # Forces update of existing config entry
return await self.async_step_reauth_confirm()
async def async_step_reauth_confirm(self, user_input=None) -> FlowResult:
async def async_step_reauth_confirm(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Confirm reauth dialog."""
assert self.is_sdm_api(), "Step only supported for SDM API"
if user_input is None:
@ -145,7 +150,9 @@ class NestFlowHandler(
)
return await self.async_step_user()
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 initialized by the user."""
if self.is_sdm_api():
# Reauth will update an existing entry
@ -154,7 +161,9 @@ class NestFlowHandler(
return await super().async_step_user(user_input)
return await self.async_step_init(user_input)
async def async_step_init(self, user_input=None) -> FlowResult:
async def async_step_init(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle a flow start."""
assert not self.is_sdm_api(), "Step only supported for legacy API"
@ -179,7 +188,9 @@ class NestFlowHandler(
data_schema=vol.Schema({vol.Required("flow_impl"): vol.In(list(flows))}),
)
async def async_step_link(self, user_input=None) -> FlowResult:
async def async_step_link(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Attempt to link with the Nest account.
Route the user to a website to authenticate with Nest. Depending on
@ -226,7 +237,7 @@ class NestFlowHandler(
errors=errors,
)
async def async_step_import(self, info) -> FlowResult:
async def async_step_import(self, info: dict[str, Any]) -> FlowResult:
"""Import existing auth from Nest."""
assert not self.is_sdm_api(), "Step only supported for legacy API"
@ -247,7 +258,9 @@ class NestFlowHandler(
)
@callback
def _entry_from_tokens(self, title, flow, tokens) -> FlowResult:
def _entry_from_tokens(
self, title: str, flow: dict[str, Any], tokens: list[Any] | dict[Any, Any]
) -> FlowResult:
"""Create an entry from tokens."""
return self.async_create_entry(
title=title, data={"tokens": tokens, "impl_domain": flow["domain"]}