Alexa strict type hints (#97485)
* Enable strict typing * Adjustments for stict typing
This commit is contained in:
parent
9910da2f3d
commit
500d9a4da0
10 changed files with 37 additions and 18 deletions
|
@ -53,6 +53,7 @@ homeassistant.components.airzone_cloud.*
|
||||||
homeassistant.components.aladdin_connect.*
|
homeassistant.components.aladdin_connect.*
|
||||||
homeassistant.components.alarm_control_panel.*
|
homeassistant.components.alarm_control_panel.*
|
||||||
homeassistant.components.alert.*
|
homeassistant.components.alert.*
|
||||||
|
homeassistant.components.alexa.*
|
||||||
homeassistant.components.amazon_polly.*
|
homeassistant.components.amazon_polly.*
|
||||||
homeassistant.components.ambient_station.*
|
homeassistant.components.ambient_station.*
|
||||||
homeassistant.components.amcrest.*
|
homeassistant.components.amcrest.*
|
||||||
|
|
|
@ -76,7 +76,8 @@ class Auth:
|
||||||
assert self._prefs is not None
|
assert self._prefs is not None
|
||||||
if self.is_token_valid():
|
if self.is_token_valid():
|
||||||
_LOGGER.debug("Token still valid, using it")
|
_LOGGER.debug("Token still valid, using it")
|
||||||
return self._prefs[STORAGE_ACCESS_TOKEN]
|
token: str = self._prefs[STORAGE_ACCESS_TOKEN]
|
||||||
|
return token
|
||||||
|
|
||||||
if self._prefs[STORAGE_REFRESH_TOKEN] is None:
|
if self._prefs[STORAGE_REFRESH_TOKEN] is None:
|
||||||
_LOGGER.debug("Token invalid and no refresh token available")
|
_LOGGER.debug("Token invalid and no refresh token available")
|
||||||
|
|
|
@ -1990,7 +1990,7 @@ class AlexaDoorbellEventSource(AlexaCapability):
|
||||||
"""Return the Alexa API name of this interface."""
|
"""Return the Alexa API name of this interface."""
|
||||||
return "Alexa.DoorbellEventSource"
|
return "Alexa.DoorbellEventSource"
|
||||||
|
|
||||||
def capability_proactively_reported(self):
|
def capability_proactively_reported(self) -> bool:
|
||||||
"""Return True for proactively reported capability."""
|
"""Return True for proactively reported capability."""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,7 @@ class AlexaConfigStore:
|
||||||
def authorized(self) -> bool:
|
def authorized(self) -> bool:
|
||||||
"""Return authorization status."""
|
"""Return authorization status."""
|
||||||
assert self._data is not None
|
assert self._data is not None
|
||||||
return self._data[STORE_AUTHORIZED]
|
return bool(self._data[STORE_AUTHORIZED])
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def set_authorized(self, authorized: bool) -> None:
|
def set_authorized(self, authorized: bool) -> None:
|
||||||
|
|
|
@ -280,9 +280,10 @@ class AlexaEntity:
|
||||||
|
|
||||||
def friendly_name(self) -> str:
|
def friendly_name(self) -> str:
|
||||||
"""Return the Alexa API friendly name."""
|
"""Return the Alexa API friendly name."""
|
||||||
return self.entity_conf.get(CONF_NAME, self.entity.name).translate(
|
friendly_name: str = self.entity_conf.get(
|
||||||
TRANSLATION_TABLE
|
CONF_NAME, self.entity.name
|
||||||
)
|
).translate(TRANSLATION_TABLE)
|
||||||
|
return friendly_name
|
||||||
|
|
||||||
def description(self) -> str:
|
def description(self) -> str:
|
||||||
"""Return the Alexa API description."""
|
"""Return the Alexa API description."""
|
||||||
|
@ -725,7 +726,7 @@ class MediaPlayerCapabilities(AlexaEntity):
|
||||||
class SceneCapabilities(AlexaEntity):
|
class SceneCapabilities(AlexaEntity):
|
||||||
"""Class to represent Scene capabilities."""
|
"""Class to represent Scene capabilities."""
|
||||||
|
|
||||||
def description(self):
|
def description(self) -> str:
|
||||||
"""Return the Alexa API description."""
|
"""Return the Alexa API description."""
|
||||||
description = AlexaEntity.description(self)
|
description = AlexaEntity.description(self)
|
||||||
if "scene" not in description.casefold():
|
if "scene" not in description.casefold():
|
||||||
|
|
|
@ -758,7 +758,9 @@ async def async_api_previous(
|
||||||
return directive.response()
|
return directive.response()
|
||||||
|
|
||||||
|
|
||||||
def temperature_from_object(hass: ha.HomeAssistant, temp_obj, interval=False):
|
def temperature_from_object(
|
||||||
|
hass: ha.HomeAssistant, temp_obj: dict[str, Any], interval: bool = False
|
||||||
|
) -> float:
|
||||||
"""Get temperature from Temperature object in requested unit."""
|
"""Get temperature from Temperature object in requested unit."""
|
||||||
to_unit = hass.config.units.temperature_unit
|
to_unit = hass.config.units.temperature_unit
|
||||||
from_unit = UnitOfTemperature.CELSIUS
|
from_unit = UnitOfTemperature.CELSIUS
|
||||||
|
|
|
@ -129,7 +129,8 @@ async def async_handle_message(
|
||||||
if not (handler := HANDLERS.get(req_type)):
|
if not (handler := HANDLERS.get(req_type)):
|
||||||
raise UnknownRequest(f"Received unknown request {req_type}")
|
raise UnknownRequest(f"Received unknown request {req_type}")
|
||||||
|
|
||||||
return await handler(hass, message)
|
response: dict[str, Any] = await handler(hass, message)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
@HANDLERS.register("SessionEndedRequest")
|
@HANDLERS.register("SessionEndedRequest")
|
||||||
|
@ -282,7 +283,7 @@ class AlexaIntentResponse:
|
||||||
|
|
||||||
self.speech = {"type": speech_type.value, key: text}
|
self.speech = {"type": speech_type.value, key: text}
|
||||||
|
|
||||||
def add_reprompt(self, speech_type: SpeechType, text) -> None:
|
def add_reprompt(self, speech_type: SpeechType, text: str) -> None:
|
||||||
"""Add reprompt if user does not answer."""
|
"""Add reprompt if user does not answer."""
|
||||||
assert self.reprompt is None
|
assert self.reprompt is None
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ class AlexaConfig(AbstractConfig):
|
||||||
def should_expose(self, entity_id: str) -> bool:
|
def should_expose(self, entity_id: str) -> bool:
|
||||||
"""If an entity should be exposed."""
|
"""If an entity should be exposed."""
|
||||||
if not self._config[CONF_FILTER].empty_filter:
|
if not self._config[CONF_FILTER].empty_filter:
|
||||||
return self._config[CONF_FILTER](entity_id)
|
return bool(self._config[CONF_FILTER](entity_id))
|
||||||
|
|
||||||
entity_registry = er.async_get(self.hass)
|
entity_registry = er.async_get(self.hass)
|
||||||
if registry_entry := entity_registry.async_get(entity_id):
|
if registry_entry := entity_registry.async_get(entity_id):
|
||||||
|
|
|
@ -14,7 +14,7 @@ import async_timeout
|
||||||
|
|
||||||
from homeassistant.components import event
|
from homeassistant.components import event
|
||||||
from homeassistant.const import MATCH_ALL, STATE_ON
|
from homeassistant.const import MATCH_ALL, STATE_ON
|
||||||
from homeassistant.core import HomeAssistant, State, callback
|
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, State, callback
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.event import async_track_state_change
|
from homeassistant.helpers.event import async_track_state_change
|
||||||
from homeassistant.helpers.significant_change import create_checker
|
from homeassistant.helpers.significant_change import create_checker
|
||||||
|
@ -159,12 +159,14 @@ class AlexaResponse:
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Return the name of this response."""
|
"""Return the name of this response."""
|
||||||
return self._response[API_EVENT][API_HEADER]["name"]
|
name: str = self._response[API_EVENT][API_HEADER]["name"]
|
||||||
|
return name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def namespace(self) -> str:
|
def namespace(self) -> str:
|
||||||
"""Return the namespace of this response."""
|
"""Return the namespace of this response."""
|
||||||
return self._response[API_EVENT][API_HEADER]["namespace"]
|
namespace: str = self._response[API_EVENT][API_HEADER]["namespace"]
|
||||||
|
return namespace
|
||||||
|
|
||||||
def set_correlation_token(self, token: str) -> None:
|
def set_correlation_token(self, token: str) -> None:
|
||||||
"""Set the correlationToken.
|
"""Set the correlationToken.
|
||||||
|
@ -196,9 +198,10 @@ class AlexaResponse:
|
||||||
"""
|
"""
|
||||||
self._response[API_EVENT][API_ENDPOINT] = endpoint
|
self._response[API_EVENT][API_ENDPOINT] = endpoint
|
||||||
|
|
||||||
def _properties(self):
|
def _properties(self) -> list[dict[str, Any]]:
|
||||||
context = self._response.setdefault(API_CONTEXT, {})
|
context: dict[str, Any] = self._response.setdefault(API_CONTEXT, {})
|
||||||
return context.setdefault("properties", [])
|
properties: list[dict[str, Any]] = context.setdefault("properties", [])
|
||||||
|
return properties
|
||||||
|
|
||||||
def add_context_property(self, prop: dict[str, Any]) -> None:
|
def add_context_property(self, prop: dict[str, Any]) -> None:
|
||||||
"""Add a property to the response context.
|
"""Add a property to the response context.
|
||||||
|
@ -236,7 +239,7 @@ class AlexaResponse:
|
||||||
|
|
||||||
async def async_enable_proactive_mode(
|
async def async_enable_proactive_mode(
|
||||||
hass: HomeAssistant, smart_home_config: AbstractConfig
|
hass: HomeAssistant, smart_home_config: AbstractConfig
|
||||||
):
|
) -> CALLBACK_TYPE | None:
|
||||||
"""Enable the proactive mode.
|
"""Enable the proactive mode.
|
||||||
|
|
||||||
Proactive mode makes this component report state changes to Alexa.
|
Proactive mode makes this component report state changes to Alexa.
|
||||||
|
|
10
mypy.ini
10
mypy.ini
|
@ -291,6 +291,16 @@ disallow_untyped_defs = true
|
||||||
warn_return_any = true
|
warn_return_any = true
|
||||||
warn_unreachable = true
|
warn_unreachable = true
|
||||||
|
|
||||||
|
[mypy-homeassistant.components.alexa.*]
|
||||||
|
check_untyped_defs = true
|
||||||
|
disallow_incomplete_defs = true
|
||||||
|
disallow_subclassing_any = true
|
||||||
|
disallow_untyped_calls = true
|
||||||
|
disallow_untyped_decorators = true
|
||||||
|
disallow_untyped_defs = true
|
||||||
|
warn_return_any = true
|
||||||
|
warn_unreachable = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.amazon_polly.*]
|
[mypy-homeassistant.components.amazon_polly.*]
|
||||||
check_untyped_defs = true
|
check_untyped_defs = true
|
||||||
disallow_incomplete_defs = true
|
disallow_incomplete_defs = true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue