diff --git a/.strict-typing b/.strict-typing index 93d603204f0..f92ede38c19 100644 --- a/.strict-typing +++ b/.strict-typing @@ -114,6 +114,7 @@ homeassistant.components.button.* homeassistant.components.calendar.* homeassistant.components.camera.* homeassistant.components.canary.* +homeassistant.components.cert_expiry.* homeassistant.components.clickatell.* homeassistant.components.clicksend.* homeassistant.components.climate.* diff --git a/homeassistant/components/cert_expiry/__init__.py b/homeassistant/components/cert_expiry/__init__.py index 391bb3ef8f3..d46cecc7edb 100644 --- a/homeassistant/components/cert_expiry/__init__.py +++ b/homeassistant/components/cert_expiry/__init__.py @@ -14,8 +14,8 @@ PLATFORMS = [Platform.SENSOR] async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Load the saved entities.""" - host = entry.data[CONF_HOST] - port = entry.data[CONF_PORT] + host: str = entry.data[CONF_HOST] + port: int = entry.data[CONF_PORT] coordinator = CertExpiryDataUpdateCoordinator(hass, host, port) @@ -25,7 +25,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: if entry.unique_id is None: hass.config_entries.async_update_entry(entry, unique_id=f"{host}:{port}") - async def _async_finish_startup(_): + async def _async_finish_startup(_: HomeAssistant) -> None: await coordinator.async_refresh() await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) diff --git a/homeassistant/components/cert_expiry/config_flow.py b/homeassistant/components/cert_expiry/config_flow.py index ed294cab981..b3ceb95d301 100644 --- a/homeassistant/components/cert_expiry/config_flow.py +++ b/homeassistant/components/cert_expiry/config_flow.py @@ -35,7 +35,7 @@ class CertexpiryConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): async def _test_connection( self, user_input: Mapping[str, Any], - ): + ) -> bool: """Test connection to the server and try to get the certificate.""" try: await get_cert_expiry_timestamp( diff --git a/homeassistant/components/cert_expiry/coordinator.py b/homeassistant/components/cert_expiry/coordinator.py index 6a125758f70..abb0b4ca727 100644 --- a/homeassistant/components/cert_expiry/coordinator.py +++ b/homeassistant/components/cert_expiry/coordinator.py @@ -4,6 +4,7 @@ from __future__ import annotations from datetime import datetime, timedelta import logging +from homeassistant.core import HomeAssistant from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from .const import DEFAULT_PORT @@ -16,11 +17,11 @@ _LOGGER = logging.getLogger(__name__) class CertExpiryDataUpdateCoordinator(DataUpdateCoordinator[datetime | None]): """Class to manage fetching Cert Expiry data from single endpoint.""" - def __init__(self, hass, host, port): + def __init__(self, hass: HomeAssistant, host: str, port: int) -> None: """Initialize global Cert Expiry data updater.""" self.host = host self.port = port - self.cert_error = None + self.cert_error: ValidationFailure | None = None self.is_cert_valid = False display_port = f":{port}" if port != DEFAULT_PORT else "" diff --git a/homeassistant/components/cert_expiry/helper.py b/homeassistant/components/cert_expiry/helper.py index 6618dbc8a01..cde9364214e 100644 --- a/homeassistant/components/cert_expiry/helper.py +++ b/homeassistant/components/cert_expiry/helper.py @@ -19,7 +19,7 @@ from .errors import ( @cache -def _get_default_ssl_context(): +def _get_default_ssl_context() -> ssl.SSLContext: """Return the default SSL context.""" return ssl.create_default_context() @@ -40,7 +40,7 @@ async def async_get_cert( server_hostname=host, ) try: - return transport.get_extra_info("peercert") + return transport.get_extra_info("peercert") # type: ignore[no-any-return] finally: transport.close() diff --git a/homeassistant/components/cert_expiry/sensor.py b/homeassistant/components/cert_expiry/sensor.py index 645642067e6..68e18fddc14 100644 --- a/homeassistant/components/cert_expiry/sensor.py +++ b/homeassistant/components/cert_expiry/sensor.py @@ -2,6 +2,7 @@ from __future__ import annotations from datetime import datetime, timedelta +from typing import Any import voluptuous as vol @@ -12,7 +13,7 @@ from homeassistant.components.sensor import ( ) from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.const import CONF_HOST, CONF_PORT, EVENT_HOMEASSISTANT_START -from homeassistant.core import HomeAssistant, callback +from homeassistant.core import Event, HomeAssistant, callback import homeassistant.helpers.config_validation as cv from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -42,12 +43,12 @@ async def async_setup_platform( """Set up certificate expiry sensor.""" @callback - def schedule_import(_): + def schedule_import(_: Event) -> None: """Schedule delayed import after HA is fully started.""" async_call_later(hass, 10, do_import) @callback - def do_import(_): + def do_import(_: datetime) -> None: """Process YAML import.""" hass.async_create_task( hass.config_entries.flow.async_init( @@ -80,7 +81,7 @@ class CertExpiryEntity(CoordinatorEntity[CertExpiryDataUpdateCoordinator]): _attr_has_entity_name = True @property - def extra_state_attributes(self): + def extra_state_attributes(self) -> dict[str, Any]: """Return additional sensor state attributes.""" return { "is_valid": self.coordinator.is_cert_valid, diff --git a/mypy.ini b/mypy.ini index bdb854183f6..bd975096ea4 100644 --- a/mypy.ini +++ b/mypy.ini @@ -900,6 +900,16 @@ disallow_untyped_defs = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.cert_expiry.*] +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.clickatell.*] check_untyped_defs = true disallow_incomplete_defs = true