From 007798916977869a6d049184e1994f03a1383586 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 1 Jan 2024 20:19:19 +0100 Subject: [PATCH] Enable strict typing for alpha_vantage (#106816) --- .strict-typing | 1 + homeassistant/components/alpha_vantage/sensor.py | 12 +++++++----- mypy.ini | 10 ++++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.strict-typing b/.strict-typing index cceaeb9ee52..a304f771cd8 100644 --- a/.strict-typing +++ b/.strict-typing @@ -58,6 +58,7 @@ homeassistant.components.aladdin_connect.* homeassistant.components.alarm_control_panel.* homeassistant.components.alert.* homeassistant.components.alexa.* +homeassistant.components.alpha_vantage.* homeassistant.components.amazon_polly.* homeassistant.components.ambient_station.* homeassistant.components.amcrest.* diff --git a/homeassistant/components/alpha_vantage/sensor.py b/homeassistant/components/alpha_vantage/sensor.py index 02c6958e0da..52427065f68 100644 --- a/homeassistant/components/alpha_vantage/sensor.py +++ b/homeassistant/components/alpha_vantage/sensor.py @@ -74,9 +74,9 @@ def setup_platform( discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the Alpha Vantage sensor.""" - api_key = config[CONF_API_KEY] - symbols = config.get(CONF_SYMBOLS, []) - conversions = config.get(CONF_FOREIGN_EXCHANGE, []) + api_key: str = config[CONF_API_KEY] + symbols: list[dict[str, str]] = config.get(CONF_SYMBOLS, []) + conversions: list[dict[str, str]] = config.get(CONF_FOREIGN_EXCHANGE, []) if not symbols and not conversions: msg = "No symbols or currencies configured." @@ -120,7 +120,7 @@ class AlphaVantageSensor(SensorEntity): _attr_attribution = ATTRIBUTION - def __init__(self, timeseries, symbol): + def __init__(self, timeseries: TimeSeries, symbol: dict[str, str]) -> None: """Initialize the sensor.""" self._symbol = symbol[CONF_SYMBOL] self._attr_name = symbol.get(CONF_NAME, self._symbol) @@ -154,7 +154,9 @@ class AlphaVantageForeignExchange(SensorEntity): _attr_attribution = ATTRIBUTION - def __init__(self, foreign_exchange, config): + def __init__( + self, foreign_exchange: ForeignExchange, config: dict[str, str] + ) -> None: """Initialize the sensor.""" self._foreign_exchange = foreign_exchange self._from_currency = config[CONF_FROM] diff --git a/mypy.ini b/mypy.ini index 57020bc9f3a..bc7c33396ff 100644 --- a/mypy.ini +++ b/mypy.ini @@ -340,6 +340,16 @@ disallow_untyped_defs = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.alpha_vantage.*] +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.*] check_untyped_defs = true disallow_incomplete_defs = true