mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Improve NUT typing (#72002)
This commit is contained in:
parent
7d26be2d4d
commit
39b27e4d38
@ -1,6 +1,7 @@
|
|||||||
"""Config flow for Network UPS Tools (NUT) integration."""
|
"""Config flow for Network UPS Tools (NUT) integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Mapping
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
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}
|
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."""
|
"""Format a host, port, and alias so it can be used for comparison or display."""
|
||||||
host = user_input[CONF_HOST]
|
host = user_input[CONF_HOST]
|
||||||
port = user_input[CONF_PORT]
|
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:
|
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."""
|
"""See if we already have a nut entry matching user input configured."""
|
||||||
existing_host_port_aliases = {
|
existing_host_port_aliases = {
|
||||||
_format_host_port_alias(dict(entry.data))
|
_format_host_port_alias(entry.data)
|
||||||
for entry in self._async_current_entries()
|
for entry in self._async_current_entries()
|
||||||
if CONF_HOST in entry.data
|
if CONF_HOST in entry.data
|
||||||
}
|
}
|
||||||
|
@ -86,14 +86,12 @@ async def async_setup_entry(
|
|||||||
async_add_entities(entities, True)
|
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."""
|
"""Representation of a sensor entity for NUT status values."""
|
||||||
|
|
||||||
coordinator: DataUpdateCoordinator[dict[str, str]]
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: DataUpdateCoordinator,
|
coordinator: DataUpdateCoordinator[dict[str, str]],
|
||||||
sensor_description: SensorEntityDescription,
|
sensor_description: SensorEntityDescription,
|
||||||
data: PyNUTData,
|
data: PyNUTData,
|
||||||
unique_id: str,
|
unique_id: str,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user