From 59818649922bf1f44282d6714fed37fb1005eef9 Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Fri, 7 Oct 2022 13:08:08 -0400 Subject: [PATCH] Add strict typing to Sonarr (#79802) --- .strict-typing | 1 + homeassistant/components/sonarr/entity.py | 7 +------ homeassistant/components/sonarr/sensor.py | 6 +++--- mypy.ini | 10 ++++++++++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.strict-typing b/.strict-typing index 466312a30a9..0a0f5a2496c 100644 --- a/.strict-typing +++ b/.strict-typing @@ -236,6 +236,7 @@ homeassistant.components.skybell.* homeassistant.components.slack.* homeassistant.components.sleepiq.* homeassistant.components.smhi.* +homeassistant.components.sonarr.* homeassistant.components.ssdp.* homeassistant.components.statistics.* homeassistant.components.steamist.* diff --git a/homeassistant/components/sonarr/entity.py b/homeassistant/components/sonarr/entity.py index 41f6786503d..852e326cdb4 100644 --- a/homeassistant/components/sonarr/entity.py +++ b/homeassistant/components/sonarr/entity.py @@ -1,6 +1,4 @@ """Base Entity for Sonarr.""" -from __future__ import annotations - from aiopyarr import SystemStatus from aiopyarr.models.host_configuration import PyArrHostConfiguration from aiopyarr.sonarr_client import SonarrClient @@ -31,11 +29,8 @@ class SonarrEntity(Entity): self.system_status = system_status @property - def device_info(self) -> DeviceInfo | None: + def device_info(self) -> DeviceInfo: """Return device information about the application.""" - if self._device_id is None: - return None - return DeviceInfo( identifiers={(DOMAIN, self._device_id)}, name="Activity Sensor", diff --git a/homeassistant/components/sonarr/sensor.py b/homeassistant/components/sonarr/sensor.py index adc588f6951..cdb44dee359 100644 --- a/homeassistant/components/sonarr/sensor.py +++ b/homeassistant/components/sonarr/sensor.py @@ -5,7 +5,7 @@ from collections.abc import Awaitable, Callable, Coroutine from datetime import timedelta from functools import wraps import logging -from typing import Any, TypeVar +from typing import Any, TypeVar, cast from aiopyarr import ArrConnectionException, ArrException, SystemStatus from aiopyarr.models.host_configuration import PyArrHostConfiguration @@ -267,7 +267,7 @@ class SonarrSensor(SonarrEntity, SensorEntity): return len(self.data[key]) if key == "queue" and self.data.get(key) is not None: - return self.data[key].totalRecords + return cast(int, self.data[key].totalRecords) if key == "series" and self.data.get(key) is not None: return len(self.data[key]) @@ -276,6 +276,6 @@ class SonarrSensor(SonarrEntity, SensorEntity): return len(self.data[key]) if key == "wanted" and self.data.get(key) is not None: - return self.data[key].totalRecords + return cast(int, self.data[key].totalRecords) return None diff --git a/mypy.ini b/mypy.ini index 819f461454b..9b748a21124 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2112,6 +2112,16 @@ disallow_untyped_defs = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.sonarr.*] +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.ssdp.*] check_untyped_defs = true disallow_incomplete_defs = true