mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Enable strict typing for cert_expiry (#107860)
This commit is contained in:
parent
2508b55b0f
commit
7023ac7366
@ -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.*
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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(
|
||||
|
@ -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 ""
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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,
|
||||
|
10
mypy.ini
10
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user