From 833805f9be329172bf2844a2cf3babbee4caa09a Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Sun, 3 Dec 2023 21:10:37 +0100 Subject: [PATCH] Add StreamLabsWater to strict typing (#104957) --- .strict-typing | 1 + .../streamlabswater/binary_sensor.py | 16 +++++++++----- .../components/streamlabswater/sensor.py | 22 +++++++++++-------- mypy.ini | 10 +++++++++ 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/.strict-typing b/.strict-typing index daf2baabf67..6180379f977 100644 --- a/.strict-typing +++ b/.strict-typing @@ -317,6 +317,7 @@ homeassistant.components.statistics.* homeassistant.components.steamist.* homeassistant.components.stookalert.* homeassistant.components.stream.* +homeassistant.components.streamlabswater.* homeassistant.components.sun.* homeassistant.components.surepetcare.* homeassistant.components.switch.* diff --git a/homeassistant/components/streamlabswater/binary_sensor.py b/homeassistant/components/streamlabswater/binary_sensor.py index 43465fb99ae..4a974077592 100644 --- a/homeassistant/components/streamlabswater/binary_sensor.py +++ b/homeassistant/components/streamlabswater/binary_sensor.py @@ -3,6 +3,8 @@ from __future__ import annotations from datetime import timedelta +from streamlabswater.streamlabswater import StreamlabsClient + from homeassistant.components.binary_sensor import BinarySensorEntity from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -39,19 +41,19 @@ def setup_platform( class StreamlabsLocationData: """Track and query location data.""" - def __init__(self, location_id, client): + def __init__(self, location_id: str, client: StreamlabsClient) -> None: """Initialize the location data.""" self._location_id = location_id self._client = client self._is_away = None @Throttle(MIN_TIME_BETWEEN_LOCATION_UPDATES) - def update(self): + def update(self) -> None: """Query and store location data.""" location = self._client.get_location(self._location_id) self._is_away = location["homeAway"] == "away" - def is_away(self): + def is_away(self) -> bool | None: """Return whether away more is enabled.""" return self._is_away @@ -59,19 +61,21 @@ class StreamlabsLocationData: class StreamlabsAwayMode(BinarySensorEntity): """Monitor the away mode state.""" - def __init__(self, location_name, streamlabs_location_data): + def __init__( + self, location_name: str, streamlabs_location_data: StreamlabsLocationData + ) -> None: """Initialize the away mode device.""" self._location_name = location_name self._streamlabs_location_data = streamlabs_location_data self._is_away = None @property - def name(self): + def name(self) -> str: """Return the name for away mode.""" return f"{self._location_name} {NAME_AWAY_MODE}" @property - def is_on(self): + def is_on(self) -> bool | None: """Return if away mode is on.""" return self._streamlabs_location_data.is_away() diff --git a/homeassistant/components/streamlabswater/sensor.py b/homeassistant/components/streamlabswater/sensor.py index 42cf2bb588f..42e551c5c11 100644 --- a/homeassistant/components/streamlabswater/sensor.py +++ b/homeassistant/components/streamlabswater/sensor.py @@ -3,6 +3,8 @@ from __future__ import annotations from datetime import timedelta +from streamlabswater.streamlabswater import StreamlabsClient + from homeassistant.components.sensor import SensorDeviceClass, SensorEntity from homeassistant.const import UnitOfVolume from homeassistant.core import HomeAssistant @@ -48,7 +50,7 @@ def setup_platform( class StreamlabsUsageData: """Track and query usage data.""" - def __init__(self, location_id, client): + def __init__(self, location_id: str, client: StreamlabsClient) -> None: """Initialize the usage data.""" self._location_id = location_id self._client = client @@ -57,22 +59,22 @@ class StreamlabsUsageData: self._this_year = None @Throttle(MIN_TIME_BETWEEN_USAGE_UPDATES) - def update(self): + def update(self) -> None: """Query and store usage data.""" water_usage = self._client.get_water_usage_summary(self._location_id) self._today = round(water_usage["today"], 1) self._this_month = round(water_usage["thisMonth"], 1) self._this_year = round(water_usage["thisYear"], 1) - def get_daily_usage(self): + def get_daily_usage(self) -> float | None: """Return the day's usage.""" return self._today - def get_monthly_usage(self): + def get_monthly_usage(self) -> float | None: """Return the month's usage.""" return self._this_month - def get_yearly_usage(self): + def get_yearly_usage(self) -> float | None: """Return the year's usage.""" return self._this_year @@ -83,7 +85,9 @@ class StreamLabsDailyUsage(SensorEntity): _attr_device_class = SensorDeviceClass.WATER _attr_native_unit_of_measurement = UnitOfVolume.GALLONS - def __init__(self, location_name, streamlabs_usage_data): + def __init__( + self, location_name: str, streamlabs_usage_data: StreamlabsUsageData + ) -> None: """Initialize the daily water usage device.""" self._location_name = location_name self._streamlabs_usage_data = streamlabs_usage_data @@ -95,7 +99,7 @@ class StreamLabsDailyUsage(SensorEntity): return f"{self._location_name} {NAME_DAILY_USAGE}" @property - def native_value(self): + def native_value(self) -> float | None: """Return the current daily usage.""" return self._streamlabs_usage_data.get_daily_usage() @@ -113,7 +117,7 @@ class StreamLabsMonthlyUsage(StreamLabsDailyUsage): return f"{self._location_name} {NAME_MONTHLY_USAGE}" @property - def native_value(self): + def native_value(self) -> float | None: """Return the current monthly usage.""" return self._streamlabs_usage_data.get_monthly_usage() @@ -127,6 +131,6 @@ class StreamLabsYearlyUsage(StreamLabsDailyUsage): return f"{self._location_name} {NAME_YEARLY_USAGE}" @property - def native_value(self): + def native_value(self) -> float | None: """Return the current yearly usage.""" return self._streamlabs_usage_data.get_yearly_usage() diff --git a/mypy.ini b/mypy.ini index 83bc95a940b..2a3a5f0fb0f 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2932,6 +2932,16 @@ warn_return_any = true warn_unreachable = true no_implicit_reexport = true +[mypy-homeassistant.components.streamlabswater.*] +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.sun.*] check_untyped_defs = true disallow_incomplete_defs = true