mypy cleanup for homeassistant.components.nest (#53214)

This commit is contained in:
Allen Porter 2021-07-19 22:59:31 -07:00 committed by GitHub
parent 78a8ba99f9
commit c2a2f50316
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 16 deletions

View File

@ -33,7 +33,6 @@ from .const import DATA_SDM, DATA_SUBSCRIBER, DOMAIN, OAUTH2_AUTHORIZE, OAUTH2_T
from .events import EVENT_NAME_MAP, NEST_EVENT
from .legacy import async_setup_legacy, async_setup_legacy_entry
_CONFIGURING = {}
_LOGGER = logging.getLogger(__name__)
CONF_PROJECT_ID = "project_id"

View File

@ -22,6 +22,7 @@ import async_timeout
import voluptuous as vol
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_entry_oauth2_flow
from homeassistant.util.json import load_json
@ -79,13 +80,13 @@ class NestFlowHandler(
self._reauth = False
@classmethod
def register_sdm_api(cls, hass):
def register_sdm_api(cls, hass) -> None:
"""Configure the flow handler to use the SDM API."""
if DOMAIN not in hass.data:
hass.data[DOMAIN] = {}
hass.data[DOMAIN][DATA_SDM] = {}
def is_sdm_api(self):
def is_sdm_api(self) -> bool:
"""Return true if this flow is setup to use SDM API."""
return DOMAIN in self.hass.data and DATA_SDM in self.hass.data[DOMAIN]
@ -104,7 +105,7 @@ class NestFlowHandler(
"prompt": "consent",
}
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 SDM flow."""
assert self.is_sdm_api(), "Step only supported for SDM API"
data[DATA_SDM] = {}
@ -128,13 +129,13 @@ class NestFlowHandler(
return await super().async_oauth_create_entry(data)
async def async_step_reauth(self, user_input=None):
async def async_step_reauth(self, user_input=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):
async def async_step_reauth_confirm(self, user_input=None) -> FlowResult:
"""Confirm reauth dialog."""
assert self.is_sdm_api(), "Step only supported for SDM API"
if user_input is None:
@ -144,7 +145,7 @@ class NestFlowHandler(
)
return await self.async_step_user()
async def async_step_user(self, user_input=None):
async def async_step_user(self, user_input=None) -> FlowResult:
"""Handle a flow initialized by the user."""
if self.is_sdm_api():
# Reauth will update an existing entry
@ -153,7 +154,7 @@ 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):
async def async_step_init(self, user_input=None) -> FlowResult:
"""Handle a flow start."""
assert not self.is_sdm_api(), "Step only supported for legacy API"
@ -178,7 +179,7 @@ class NestFlowHandler(
data_schema=vol.Schema({vol.Required("flow_impl"): vol.In(list(flows))}),
)
async def async_step_link(self, user_input=None):
async def async_step_link(self, user_input=None) -> FlowResult:
"""Attempt to link with the Nest account.
Route the user to a website to authenticate with Nest. Depending on
@ -225,7 +226,7 @@ class NestFlowHandler(
errors=errors,
)
async def async_step_import(self, info):
async def async_step_import(self, info) -> FlowResult:
"""Import existing auth from Nest."""
assert not self.is_sdm_api(), "Step only supported for legacy API"
@ -235,7 +236,7 @@ class NestFlowHandler(
config_path = info["nest_conf_path"]
if not await self.hass.async_add_executor_job(os.path.isfile, config_path):
self.flow_impl = DOMAIN
self.flow_impl = DOMAIN # type: ignore
return await self.async_step_link()
flow = self.hass.data[DATA_FLOW_IMPL][DOMAIN]
@ -246,7 +247,7 @@ class NestFlowHandler(
)
@callback
def _entry_from_tokens(self, title, flow, tokens):
def _entry_from_tokens(self, title, flow, tokens) -> FlowResult:
"""Create an entry from tokens."""
return self.async_create_entry(
title=title, data={"tokens": tokens, "impl_domain": flow["domain"]}

View File

@ -27,7 +27,7 @@ TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend(
)
async def async_get_nest_device_id(hass: HomeAssistant, device_id: str) -> str:
async def async_get_nest_device_id(hass: HomeAssistant, device_id: str) -> str | None:
"""Get the nest API device_id from the HomeAssistant device_id."""
device_registry = await hass.helpers.device_registry.async_get_registry()
device = device_registry.async_get(device_id)

View File

@ -44,7 +44,7 @@ async def async_setup_sdm_entry(
_LOGGER.warning("Failed to get devices: %s", err)
raise PlatformNotReady from err
entities = []
entities: list[SensorEntity] = []
for device in device_manager.devices.values():
if TemperatureTrait.NAME in device.traits:
entities.append(TemperatureSensor(device))

View File

@ -1364,7 +1364,7 @@ ignore_errors = true
[mypy-homeassistant.components.ness_alarm.*]
ignore_errors = true
[mypy-homeassistant.components.nest.*]
[mypy-homeassistant.components.nest.legacy.*]
ignore_errors = true
[mypy-homeassistant.components.netatmo.*]

View File

@ -113,7 +113,7 @@ IGNORED_MODULES: Final[list[str]] = [
"homeassistant.components.mullvad.*",
"homeassistant.components.neato.*",
"homeassistant.components.ness_alarm.*",
"homeassistant.components.nest.*",
"homeassistant.components.nest.legacy.*",
"homeassistant.components.netatmo.*",
"homeassistant.components.netio.*",
"homeassistant.components.nightscout.*",