From 39b27e4d38b91498245e19ded3c5fba6641cbcd4 Mon Sep 17 00:00:00 2001 From: ollo69 <60491700+ollo69@users.noreply.github.com> Date: Tue, 17 May 2022 13:08:38 +0200 Subject: [PATCH] Improve NUT typing (#72002) --- homeassistant/components/nut/config_flow.py | 5 +++-- homeassistant/components/nut/sensor.py | 6 ++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/nut/config_flow.py b/homeassistant/components/nut/config_flow.py index 5ba8024878a..917f004ce32 100644 --- a/homeassistant/components/nut/config_flow.py +++ b/homeassistant/components/nut/config_flow.py @@ -1,6 +1,7 @@ """Config flow for Network UPS Tools (NUT) integration.""" from __future__ import annotations +from collections.abc import Mapping import logging from typing import Any @@ -69,7 +70,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, return {"ups_list": nut_data.ups_list, "available_resources": status} -def _format_host_port_alias(user_input: dict[str, Any]) -> str: +def _format_host_port_alias(user_input: Mapping[str, Any]) -> str: """Format a host, port, and alias so it can be used for comparison or display.""" host = user_input[CONF_HOST] port = user_input[CONF_PORT] @@ -157,7 +158,7 @@ class NutConfigFlow(ConfigFlow, domain=DOMAIN): def _host_port_alias_already_configured(self, user_input: dict[str, Any]) -> bool: """See if we already have a nut entry matching user input configured.""" existing_host_port_aliases = { - _format_host_port_alias(dict(entry.data)) + _format_host_port_alias(entry.data) for entry in self._async_current_entries() if CONF_HOST in entry.data } diff --git a/homeassistant/components/nut/sensor.py b/homeassistant/components/nut/sensor.py index 6992e41366e..6c68f2b6c6b 100644 --- a/homeassistant/components/nut/sensor.py +++ b/homeassistant/components/nut/sensor.py @@ -86,14 +86,12 @@ async def async_setup_entry( async_add_entities(entities, True) -class NUTSensor(CoordinatorEntity, SensorEntity): +class NUTSensor(CoordinatorEntity[DataUpdateCoordinator[dict[str, str]]], SensorEntity): """Representation of a sensor entity for NUT status values.""" - coordinator: DataUpdateCoordinator[dict[str, str]] - def __init__( self, - coordinator: DataUpdateCoordinator, + coordinator: DataUpdateCoordinator[dict[str, str]], sensor_description: SensorEntityDescription, data: PyNUTData, unique_id: str,