Activate mypy for sonar ()

* Please mypy.
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
pull/55373/head
jan iversen 2021-08-28 12:05:48 +02:00 committed by GitHub
parent 16351ef3c2
commit d1965eef8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 24 deletions
homeassistant/components/sonarr
script/hassfest

View File

@ -35,7 +35,7 @@ from .const import (
_LOGGER = logging.getLogger(__name__)
async def validate_input(hass: HomeAssistant, data: dict) -> dict[str, Any]:
async def validate_input(hass: HomeAssistant, data: dict) -> None:
"""Validate the user input allows us to connect.
Data has the keys from DATA_SCHEMA with values provided by the user.
@ -54,8 +54,6 @@ async def validate_input(hass: HomeAssistant, data: dict) -> dict[str, Any]:
await sonarr.update()
return True
class SonarrConfigFlow(ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Sonarr."""
@ -72,14 +70,14 @@ class SonarrConfigFlow(ConfigFlow, domain=DOMAIN):
"""Get the options flow for this handler."""
return SonarrOptionsFlowHandler(config_entry)
async def async_step_reauth(self, data: dict[str, Any] | None = None) -> FlowResult:
async def async_step_reauth(self, data: dict[str, Any]) -> FlowResult:
"""Handle configuration by re-auth."""
self.entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
return await self.async_step_reauth_confirm()
async def async_step_reauth_confirm(
self, user_input: dict[str, Any] | None = None
self, user_input: dict[str, str] | None = None
) -> FlowResult:
"""Confirm reauth dialog."""
if user_input is None:
@ -164,7 +162,7 @@ class SonarrOptionsFlowHandler(OptionsFlow):
"""Initialize options flow."""
self.config_entry = config_entry
async def async_step_init(self, user_input: dict[str, Any] | None = None):
async def async_step_init(self, user_input: dict[str, int] | None = None):
"""Manage Sonarr options."""
if user_input is not None:
return self.async_create_entry(title="", data=user_input)

View File

@ -3,9 +3,16 @@ from __future__ import annotations
from datetime import timedelta
import logging
from typing import Any
from sonarr import Sonarr, SonarrConnectionError, SonarrError
from sonarr.models import (
CommandItem,
Disk,
Episode,
QueueItem,
SeriesItem,
WantedResults,
)
from homeassistant.components.sensor import SensorEntity
from homeassistant.config_entries import ConfigEntry
@ -106,7 +113,7 @@ class SonarrCommandsSensor(SonarrSensor):
def __init__(self, sonarr: Sonarr, entry_id: str) -> None:
"""Initialize Sonarr Commands sensor."""
self._commands = []
self._commands: list[CommandItem] = []
super().__init__(
sonarr=sonarr,
@ -124,7 +131,7 @@ class SonarrCommandsSensor(SonarrSensor):
self._commands = await self.sonarr.commands()
@property
def extra_state_attributes(self) -> dict[str, Any] | None:
def extra_state_attributes(self) -> dict[str, str] | None:
"""Return the state attributes of the entity."""
attrs = {}
@ -144,7 +151,7 @@ class SonarrDiskspaceSensor(SonarrSensor):
def __init__(self, sonarr: Sonarr, entry_id: str) -> None:
"""Initialize Sonarr Disk Space sensor."""
self._disks = []
self._disks: list[Disk] = []
self._total_free = 0
super().__init__(
@ -165,7 +172,7 @@ class SonarrDiskspaceSensor(SonarrSensor):
self._total_free = sum(disk.free for disk in self._disks)
@property
def extra_state_attributes(self) -> dict[str, Any] | None:
def extra_state_attributes(self) -> dict[str, str] | None:
"""Return the state attributes of the entity."""
attrs = {}
@ -192,7 +199,7 @@ class SonarrQueueSensor(SonarrSensor):
def __init__(self, sonarr: Sonarr, entry_id: str) -> None:
"""Initialize Sonarr Queue sensor."""
self._queue = []
self._queue: list[QueueItem] = []
super().__init__(
sonarr=sonarr,
@ -210,7 +217,7 @@ class SonarrQueueSensor(SonarrSensor):
self._queue = await self.sonarr.queue()
@property
def extra_state_attributes(self) -> dict[str, Any] | None:
def extra_state_attributes(self) -> dict[str, str] | None:
"""Return the state attributes of the entity."""
attrs = {}
@ -233,7 +240,7 @@ class SonarrSeriesSensor(SonarrSensor):
def __init__(self, sonarr: Sonarr, entry_id: str) -> None:
"""Initialize Sonarr Series sensor."""
self._items = []
self._items: list[SeriesItem] = []
super().__init__(
sonarr=sonarr,
@ -251,7 +258,7 @@ class SonarrSeriesSensor(SonarrSensor):
self._items = await self.sonarr.series()
@property
def extra_state_attributes(self) -> dict[str, Any] | None:
def extra_state_attributes(self) -> dict[str, str] | None:
"""Return the state attributes of the entity."""
attrs = {}
@ -272,7 +279,7 @@ class SonarrUpcomingSensor(SonarrSensor):
def __init__(self, sonarr: Sonarr, entry_id: str, days: int = 1) -> None:
"""Initialize Sonarr Upcoming sensor."""
self._days = days
self._upcoming = []
self._upcoming: list[Episode] = []
super().__init__(
sonarr=sonarr,
@ -294,7 +301,7 @@ class SonarrUpcomingSensor(SonarrSensor):
)
@property
def extra_state_attributes(self) -> dict[str, Any] | None:
def extra_state_attributes(self) -> dict[str, str] | None:
"""Return the state attributes of the entity."""
attrs = {}
@ -315,7 +322,7 @@ class SonarrWantedSensor(SonarrSensor):
def __init__(self, sonarr: Sonarr, entry_id: str, max_items: int = 10) -> None:
"""Initialize Sonarr Wanted sensor."""
self._max_items = max_items
self._results = None
self._results: WantedResults | None = None
self._total: int | None = None
super().__init__(
@ -335,9 +342,9 @@ class SonarrWantedSensor(SonarrSensor):
self._total = self._results.total
@property
def extra_state_attributes(self) -> dict[str, Any] | None:
def extra_state_attributes(self) -> dict[str, str] | None:
"""Return the state attributes of the entity."""
attrs = {}
attrs: dict[str, str] = {}
if self._results is not None:
for episode in self._results.episodes:

View File

@ -1597,9 +1597,6 @@ ignore_errors = true
[mypy-homeassistant.components.somfy_mylink.*]
ignore_errors = true
[mypy-homeassistant.components.sonarr.*]
ignore_errors = true
[mypy-homeassistant.components.sonos.*]
ignore_errors = true

View File

@ -121,7 +121,6 @@ IGNORED_MODULES: Final[list[str]] = [
"homeassistant.components.solaredge.*",
"homeassistant.components.somfy.*",
"homeassistant.components.somfy_mylink.*",
"homeassistant.components.sonarr.*",
"homeassistant.components.sonos.*",
"homeassistant.components.spotify.*",
"homeassistant.components.stt.*",