Enable strict typing for doorbird (#98778)

This commit is contained in:
J. Nick Koston 2023-08-21 15:22:25 -05:00 committed by GitHub
parent d0d160f11c
commit d582e60a6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 14 deletions

View File

@ -104,6 +104,7 @@ homeassistant.components.dhcp.*
homeassistant.components.diagnostics.* homeassistant.components.diagnostics.*
homeassistant.components.dlna_dmr.* homeassistant.components.dlna_dmr.*
homeassistant.components.dnsip.* homeassistant.components.dnsip.*
homeassistant.components.doorbird.*
homeassistant.components.dormakaba_dkey.* homeassistant.components.dormakaba_dkey.*
homeassistant.components.dsmr.* homeassistant.components.dsmr.*
homeassistant.components.dunehd.* homeassistant.components.dunehd.*

View File

@ -157,7 +157,9 @@ async def _update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
@callback @callback
def _async_import_options_from_data_if_missing(hass: HomeAssistant, entry: ConfigEntry): def _async_import_options_from_data_if_missing(
hass: HomeAssistant, entry: ConfigEntry
) -> None:
options = dict(entry.options) options = dict(entry.options)
modified = False modified = False
for importable_option in (CONF_EVENTS,): for importable_option in (CONF_EVENTS,):

View File

@ -87,7 +87,7 @@ class DoorBirdCamera(DoorBirdEntity, Camera):
self._last_update = datetime.datetime.min self._last_update = datetime.datetime.min
self._attr_unique_id = f"{self._mac_addr}_{camera_id}" self._attr_unique_id = f"{self._mac_addr}_{camera_id}"
async def stream_source(self): async def stream_source(self) -> str | None:
"""Return the stream source.""" """Return the stream source."""
return self._stream_url return self._stream_url

View File

@ -23,7 +23,9 @@ from .util import get_mac_address_from_door_station_info
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
def _schema_with_defaults(host=None, name=None): def _schema_with_defaults(
host: str | None = None, name: str | None = None
) -> vol.Schema:
return vol.Schema( return vol.Schema(
{ {
vol.Required(CONF_HOST, default=host): str, vol.Required(CONF_HOST, default=host): str,
@ -39,7 +41,9 @@ def _check_device(device: DoorBird) -> tuple[tuple[bool, int], dict[str, Any]]:
return device.ready(), device.info() return device.ready(), device.info()
async def validate_input(hass: core.HomeAssistant, data): async def validate_input(
hass: core.HomeAssistant, data: dict[str, Any]
) -> dict[str, str]:
"""Validate the user input allows us to connect.""" """Validate the user input allows us to connect."""
device = DoorBird(data[CONF_HOST], data[CONF_USERNAME], data[CONF_PASSWORD]) device = DoorBird(data[CONF_HOST], data[CONF_USERNAME], data[CONF_PASSWORD])
try: try:
@ -78,13 +82,15 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
VERSION = 1 VERSION = 1
def __init__(self): def __init__(self) -> None:
"""Initialize the DoorBird config flow.""" """Initialize the DoorBird config flow."""
self.discovery_schema = {} self.discovery_schema: vol.Schema | None = None
async def async_step_user(self, user_input=None): async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle the initial step.""" """Handle the initial step."""
errors = {} errors: dict[str, str] = {}
if user_input is not None: if user_input is not None:
info, errors = await self._async_validate_or_error(user_input) info, errors = await self._async_validate_or_error(user_input)
if not errors: if not errors:
@ -128,7 +134,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
return await self.async_step_user() return await self.async_step_user()
async def _async_validate_or_error(self, user_input): async def _async_validate_or_error(
self, user_input: dict[str, Any]
) -> tuple[dict[str, Any], dict[str, Any]]:
"""Validate doorbird or error.""" """Validate doorbird or error."""
errors = {} errors = {}
info = {} info = {}
@ -159,7 +167,9 @@ class OptionsFlowHandler(config_entries.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=None): async def async_step_init(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle options flow.""" """Handle options flow."""
if user_input is not None: if user_input is not None:
events = [event.strip() for event in user_input[CONF_EVENTS].split(",")] events = [event.strip() for event in user_input[CONF_EVENTS].split(",")]

View File

@ -2,7 +2,7 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
from typing import Any from typing import Any, cast
from doorbirdpy import DoorBird from doorbirdpy import DoorBird
@ -131,7 +131,7 @@ class ConfiguredDoorBird:
for fav_id in favs["http"]: for fav_id in favs["http"]:
if favs["http"][fav_id]["value"] == url: if favs["http"][fav_id]["value"] == url:
return fav_id return cast(str, fav_id)
return None return None

View File

@ -1,6 +1,8 @@
"""Describe logbook events.""" """Describe logbook events."""
from __future__ import annotations from __future__ import annotations
from collections.abc import Callable
from homeassistant.components.logbook import ( from homeassistant.components.logbook import (
LOGBOOK_ENTRY_ENTITY_ID, LOGBOOK_ENTRY_ENTITY_ID,
LOGBOOK_ENTRY_MESSAGE, LOGBOOK_ENTRY_MESSAGE,
@ -14,11 +16,16 @@ from .models import DoorBirdData
@callback @callback
def async_describe_events(hass: HomeAssistant, async_describe_event): def async_describe_events(
hass: HomeAssistant,
async_describe_event: Callable[
[str, str, Callable[[Event], dict[str, str | None]]], None
],
) -> None:
"""Describe logbook events.""" """Describe logbook events."""
@callback @callback
def async_describe_logbook_event(event: Event): def async_describe_logbook_event(event: Event) -> dict[str, str | None]:
"""Describe a logbook event.""" """Describe a logbook event."""
return { return {
LOGBOOK_ENTRY_NAME: "Doorbird", LOGBOOK_ENTRY_NAME: "Doorbird",

View File

@ -802,6 +802,16 @@ disallow_untyped_defs = true
warn_return_any = true warn_return_any = true
warn_unreachable = true warn_unreachable = true
[mypy-homeassistant.components.doorbird.*]
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.dormakaba_dkey.*] [mypy-homeassistant.components.dormakaba_dkey.*]
check_untyped_defs = true check_untyped_defs = true
disallow_incomplete_defs = true disallow_incomplete_defs = true