Enable strict typing for nightscout (#107307)
parent
b22cd2deaa
commit
c30bf1f6e1
|
@ -289,6 +289,7 @@ homeassistant.components.netatmo.*
|
|||
homeassistant.components.network.*
|
||||
homeassistant.components.nextdns.*
|
||||
homeassistant.components.nfandroidtv.*
|
||||
homeassistant.components.nightscout.*
|
||||
homeassistant.components.nissan_leaf.*
|
||||
homeassistant.components.no_ip.*
|
||||
homeassistant.components.notify.*
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Config flow for Nightscout integration."""
|
||||
from asyncio import TimeoutError as AsyncIOTimeoutError
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from aiohttp import ClientError, ClientResponseError
|
||||
from py_nightscout import Api as NightscoutAPI
|
||||
|
@ -8,6 +9,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant import config_entries, exceptions
|
||||
from homeassistant.const import CONF_API_KEY, CONF_URL
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
|
||||
from .const import DOMAIN
|
||||
from .utils import hash_from_url
|
||||
|
@ -17,10 +19,10 @@ _LOGGER = logging.getLogger(__name__)
|
|||
DATA_SCHEMA = vol.Schema({vol.Required(CONF_URL): str, vol.Optional(CONF_API_KEY): str})
|
||||
|
||||
|
||||
async def _validate_input(data):
|
||||
async def _validate_input(data: dict[str, Any]) -> dict[str, str]:
|
||||
"""Validate the user input allows us to connect."""
|
||||
url = data[CONF_URL]
|
||||
api_key = data.get(CONF_API_KEY)
|
||||
url: str = data[CONF_URL]
|
||||
api_key: str | None = data.get(CONF_API_KEY)
|
||||
try:
|
||||
api = NightscoutAPI(url, api_secret=api_key)
|
||||
status = await api.get_server_status()
|
||||
|
@ -40,9 +42,11 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
|
||||
VERSION = 1
|
||||
|
||||
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."""
|
||||
errors = {}
|
||||
errors: dict[str, str] = {}
|
||||
|
||||
if user_input is not None:
|
||||
unique_id = hash_from_url(user_input[CONF_URL])
|
||||
|
|
|
@ -40,7 +40,7 @@ class NightscoutSensor(SensorEntity):
|
|||
_attr_native_unit_of_measurement = "mg/dL"
|
||||
_attr_icon = "mdi:cloud-question"
|
||||
|
||||
def __init__(self, api: NightscoutAPI, name, unique_id) -> None:
|
||||
def __init__(self, api: NightscoutAPI, name: str, unique_id: str | None) -> None:
|
||||
"""Initialize the Nightscout sensor."""
|
||||
self.api = api
|
||||
self._attr_unique_id = unique_id
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
"""Nightscout util functions."""
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
|
||||
|
||||
def hash_from_url(url: str):
|
||||
def hash_from_url(url: str) -> str:
|
||||
"""Hash url to create a unique ID."""
|
||||
return hashlib.sha256(url.encode("utf-8")).hexdigest()
|
||||
|
|
10
mypy.ini
10
mypy.ini
|
@ -2651,6 +2651,16 @@ disallow_untyped_defs = true
|
|||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.nightscout.*]
|
||||
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.nissan_leaf.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
|
|
Loading…
Reference in New Issue