From 1204b4f7000cda093290ecf3d07eaca2d00bdee1 Mon Sep 17 00:00:00 2001
From: Aidan Timson <contact@timmo.xyz>
Date: Sun, 31 Jul 2022 12:26:16 +0100
Subject: [PATCH] Add typings to Certificate Expiry integration (#75945)

---
 .../components/cert_expiry/config_flow.py      | 18 +++++++++++++++---
 homeassistant/components/cert_expiry/helper.py | 12 ++++++++++--
 homeassistant/components/cert_expiry/sensor.py | 10 ++++++++--
 3 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/homeassistant/components/cert_expiry/config_flow.py b/homeassistant/components/cert_expiry/config_flow.py
index 13336c59771..ed294cab981 100644
--- a/homeassistant/components/cert_expiry/config_flow.py
+++ b/homeassistant/components/cert_expiry/config_flow.py
@@ -1,12 +1,15 @@
 """Config flow for the Cert Expiry platform."""
 from __future__ import annotations
 
+from collections.abc import Mapping
 import logging
+from typing import Any
 
 import voluptuous as vol
 
 from homeassistant import config_entries
 from homeassistant.const import CONF_HOST, CONF_PORT
+from homeassistant.data_entry_flow import FlowResult
 
 from .const import DEFAULT_PORT, DOMAIN
 from .errors import (
@@ -29,7 +32,10 @@ class CertexpiryConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
         """Initialize the config flow."""
         self._errors: dict[str, str] = {}
 
-    async def _test_connection(self, user_input=None):
+    async def _test_connection(
+        self,
+        user_input: Mapping[str, Any],
+    ):
         """Test connection to the server and try to get the certificate."""
         try:
             await get_cert_expiry_timestamp(
@@ -48,7 +54,10 @@ class CertexpiryConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
             return True
         return False
 
-    async def async_step_user(self, user_input=None):
+    async def async_step_user(
+        self,
+        user_input: Mapping[str, Any] | None = None,
+    ) -> FlowResult:
         """Step when user initializes a integration."""
         self._errors = {}
         if user_input is not None:
@@ -85,7 +94,10 @@ class CertexpiryConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
             errors=self._errors,
         )
 
-    async def async_step_import(self, user_input=None):
+    async def async_step_import(
+        self,
+        user_input: Mapping[str, Any] | None = None,
+    ) -> FlowResult:
         """Import a config entry.
 
         Only host was required in the yaml file all other fields are optional
diff --git a/homeassistant/components/cert_expiry/helper.py b/homeassistant/components/cert_expiry/helper.py
index c00a99c8e86..fcd808a6521 100644
--- a/homeassistant/components/cert_expiry/helper.py
+++ b/homeassistant/components/cert_expiry/helper.py
@@ -2,6 +2,7 @@
 import socket
 import ssl
 
+from homeassistant.core import HomeAssistant
 from homeassistant.util import dt
 
 from .const import TIMEOUT
@@ -13,7 +14,10 @@ from .errors import (
 )
 
 
-def get_cert(host, port):
+def get_cert(
+    host: str,
+    port: int,
+):
     """Get the certificate for the host and port combination."""
     ctx = ssl.create_default_context()
     address = (host, port)
@@ -23,7 +27,11 @@ def get_cert(host, port):
             return cert
 
 
-async def get_cert_expiry_timestamp(hass, hostname, port):
+async def get_cert_expiry_timestamp(
+    hass: HomeAssistant,
+    hostname: str,
+    port: int,
+):
     """Return the certificate's expiration timestamp."""
     try:
         cert = await hass.async_add_executor_job(get_cert, hostname, port)
diff --git a/homeassistant/components/cert_expiry/sensor.py b/homeassistant/components/cert_expiry/sensor.py
index 9ee79e5c449..0c1b6116cdd 100644
--- a/homeassistant/components/cert_expiry/sensor.py
+++ b/homeassistant/components/cert_expiry/sensor.py
@@ -19,6 +19,7 @@ from homeassistant.helpers.event import async_call_later
 from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
 from homeassistant.helpers.update_coordinator import CoordinatorEntity
 
+from . import CertExpiryDataUpdateCoordinator
 from .const import DEFAULT_PORT, DOMAIN
 
 SCAN_INTERVAL = timedelta(hours=12)
@@ -57,7 +58,9 @@ async def async_setup_platform(
 
 
 async def async_setup_entry(
-    hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
+    hass: HomeAssistant,
+    entry: ConfigEntry,
+    async_add_entities: AddEntitiesCallback,
 ) -> None:
     """Add cert-expiry entry."""
     coordinator = hass.data[DOMAIN][entry.entry_id]
@@ -88,7 +91,10 @@ class SSLCertificateTimestamp(CertExpiryEntity, SensorEntity):
 
     _attr_device_class = SensorDeviceClass.TIMESTAMP
 
-    def __init__(self, coordinator) -> None:
+    def __init__(
+        self,
+        coordinator: CertExpiryDataUpdateCoordinator,
+    ) -> None:
         """Initialize a Cert Expiry timestamp sensor."""
         super().__init__(coordinator)
         self._attr_name = f"Cert Expiry Timestamp ({coordinator.name})"