mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Activate mypy for sonar (#55327)
* Please mypy. Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
16351ef3c2
commit
d1965eef8b
@ -35,7 +35,7 @@ from .const import (
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_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.
|
"""Validate the user input allows us to connect.
|
||||||
|
|
||||||
Data has the keys from DATA_SCHEMA with values provided by the user.
|
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()
|
await sonarr.update()
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class SonarrConfigFlow(ConfigFlow, domain=DOMAIN):
|
class SonarrConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
"""Handle a config flow for Sonarr."""
|
"""Handle a config flow for Sonarr."""
|
||||||
@ -72,14 +70,14 @@ class SonarrConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
"""Get the options flow for this handler."""
|
"""Get the options flow for this handler."""
|
||||||
return SonarrOptionsFlowHandler(config_entry)
|
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."""
|
"""Handle configuration by re-auth."""
|
||||||
self.entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
|
self.entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
|
||||||
|
|
||||||
return await self.async_step_reauth_confirm()
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
async def 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:
|
) -> FlowResult:
|
||||||
"""Confirm reauth dialog."""
|
"""Confirm reauth dialog."""
|
||||||
if user_input is None:
|
if user_input is None:
|
||||||
@ -164,7 +162,7 @@ class SonarrOptionsFlowHandler(OptionsFlow):
|
|||||||
"""Initialize options flow."""
|
"""Initialize options flow."""
|
||||||
self.config_entry = config_entry
|
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."""
|
"""Manage Sonarr options."""
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
return self.async_create_entry(title="", data=user_input)
|
return self.async_create_entry(title="", data=user_input)
|
||||||
|
@ -3,9 +3,16 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from sonarr import Sonarr, SonarrConnectionError, SonarrError
|
from sonarr import Sonarr, SonarrConnectionError, SonarrError
|
||||||
|
from sonarr.models import (
|
||||||
|
CommandItem,
|
||||||
|
Disk,
|
||||||
|
Episode,
|
||||||
|
QueueItem,
|
||||||
|
SeriesItem,
|
||||||
|
WantedResults,
|
||||||
|
)
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntity
|
from homeassistant.components.sensor import SensorEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -106,7 +113,7 @@ class SonarrCommandsSensor(SonarrSensor):
|
|||||||
|
|
||||||
def __init__(self, sonarr: Sonarr, entry_id: str) -> None:
|
def __init__(self, sonarr: Sonarr, entry_id: str) -> None:
|
||||||
"""Initialize Sonarr Commands sensor."""
|
"""Initialize Sonarr Commands sensor."""
|
||||||
self._commands = []
|
self._commands: list[CommandItem] = []
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
sonarr=sonarr,
|
sonarr=sonarr,
|
||||||
@ -124,7 +131,7 @@ class SonarrCommandsSensor(SonarrSensor):
|
|||||||
self._commands = await self.sonarr.commands()
|
self._commands = await self.sonarr.commands()
|
||||||
|
|
||||||
@property
|
@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."""
|
"""Return the state attributes of the entity."""
|
||||||
attrs = {}
|
attrs = {}
|
||||||
|
|
||||||
@ -144,7 +151,7 @@ class SonarrDiskspaceSensor(SonarrSensor):
|
|||||||
|
|
||||||
def __init__(self, sonarr: Sonarr, entry_id: str) -> None:
|
def __init__(self, sonarr: Sonarr, entry_id: str) -> None:
|
||||||
"""Initialize Sonarr Disk Space sensor."""
|
"""Initialize Sonarr Disk Space sensor."""
|
||||||
self._disks = []
|
self._disks: list[Disk] = []
|
||||||
self._total_free = 0
|
self._total_free = 0
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
@ -165,7 +172,7 @@ class SonarrDiskspaceSensor(SonarrSensor):
|
|||||||
self._total_free = sum(disk.free for disk in self._disks)
|
self._total_free = sum(disk.free for disk in self._disks)
|
||||||
|
|
||||||
@property
|
@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."""
|
"""Return the state attributes of the entity."""
|
||||||
attrs = {}
|
attrs = {}
|
||||||
|
|
||||||
@ -192,7 +199,7 @@ class SonarrQueueSensor(SonarrSensor):
|
|||||||
|
|
||||||
def __init__(self, sonarr: Sonarr, entry_id: str) -> None:
|
def __init__(self, sonarr: Sonarr, entry_id: str) -> None:
|
||||||
"""Initialize Sonarr Queue sensor."""
|
"""Initialize Sonarr Queue sensor."""
|
||||||
self._queue = []
|
self._queue: list[QueueItem] = []
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
sonarr=sonarr,
|
sonarr=sonarr,
|
||||||
@ -210,7 +217,7 @@ class SonarrQueueSensor(SonarrSensor):
|
|||||||
self._queue = await self.sonarr.queue()
|
self._queue = await self.sonarr.queue()
|
||||||
|
|
||||||
@property
|
@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."""
|
"""Return the state attributes of the entity."""
|
||||||
attrs = {}
|
attrs = {}
|
||||||
|
|
||||||
@ -233,7 +240,7 @@ class SonarrSeriesSensor(SonarrSensor):
|
|||||||
|
|
||||||
def __init__(self, sonarr: Sonarr, entry_id: str) -> None:
|
def __init__(self, sonarr: Sonarr, entry_id: str) -> None:
|
||||||
"""Initialize Sonarr Series sensor."""
|
"""Initialize Sonarr Series sensor."""
|
||||||
self._items = []
|
self._items: list[SeriesItem] = []
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
sonarr=sonarr,
|
sonarr=sonarr,
|
||||||
@ -251,7 +258,7 @@ class SonarrSeriesSensor(SonarrSensor):
|
|||||||
self._items = await self.sonarr.series()
|
self._items = await self.sonarr.series()
|
||||||
|
|
||||||
@property
|
@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."""
|
"""Return the state attributes of the entity."""
|
||||||
attrs = {}
|
attrs = {}
|
||||||
|
|
||||||
@ -272,7 +279,7 @@ class SonarrUpcomingSensor(SonarrSensor):
|
|||||||
def __init__(self, sonarr: Sonarr, entry_id: str, days: int = 1) -> None:
|
def __init__(self, sonarr: Sonarr, entry_id: str, days: int = 1) -> None:
|
||||||
"""Initialize Sonarr Upcoming sensor."""
|
"""Initialize Sonarr Upcoming sensor."""
|
||||||
self._days = days
|
self._days = days
|
||||||
self._upcoming = []
|
self._upcoming: list[Episode] = []
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
sonarr=sonarr,
|
sonarr=sonarr,
|
||||||
@ -294,7 +301,7 @@ class SonarrUpcomingSensor(SonarrSensor):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@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."""
|
"""Return the state attributes of the entity."""
|
||||||
attrs = {}
|
attrs = {}
|
||||||
|
|
||||||
@ -315,7 +322,7 @@ class SonarrWantedSensor(SonarrSensor):
|
|||||||
def __init__(self, sonarr: Sonarr, entry_id: str, max_items: int = 10) -> None:
|
def __init__(self, sonarr: Sonarr, entry_id: str, max_items: int = 10) -> None:
|
||||||
"""Initialize Sonarr Wanted sensor."""
|
"""Initialize Sonarr Wanted sensor."""
|
||||||
self._max_items = max_items
|
self._max_items = max_items
|
||||||
self._results = None
|
self._results: WantedResults | None = None
|
||||||
self._total: int | None = None
|
self._total: int | None = None
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
@ -335,9 +342,9 @@ class SonarrWantedSensor(SonarrSensor):
|
|||||||
self._total = self._results.total
|
self._total = self._results.total
|
||||||
|
|
||||||
@property
|
@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."""
|
"""Return the state attributes of the entity."""
|
||||||
attrs = {}
|
attrs: dict[str, str] = {}
|
||||||
|
|
||||||
if self._results is not None:
|
if self._results is not None:
|
||||||
for episode in self._results.episodes:
|
for episode in self._results.episodes:
|
||||||
|
3
mypy.ini
3
mypy.ini
@ -1597,9 +1597,6 @@ ignore_errors = true
|
|||||||
[mypy-homeassistant.components.somfy_mylink.*]
|
[mypy-homeassistant.components.somfy_mylink.*]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.sonarr.*]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.sonos.*]
|
[mypy-homeassistant.components.sonos.*]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
@ -121,7 +121,6 @@ IGNORED_MODULES: Final[list[str]] = [
|
|||||||
"homeassistant.components.solaredge.*",
|
"homeassistant.components.solaredge.*",
|
||||||
"homeassistant.components.somfy.*",
|
"homeassistant.components.somfy.*",
|
||||||
"homeassistant.components.somfy_mylink.*",
|
"homeassistant.components.somfy_mylink.*",
|
||||||
"homeassistant.components.sonarr.*",
|
|
||||||
"homeassistant.components.sonos.*",
|
"homeassistant.components.sonos.*",
|
||||||
"homeassistant.components.spotify.*",
|
"homeassistant.components.spotify.*",
|
||||||
"homeassistant.components.stt.*",
|
"homeassistant.components.stt.*",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user