mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Small typing improvements for Plugwise (#80722)
This commit is contained in:
parent
f311c03741
commit
1913804755
@ -41,20 +41,22 @@ from .const import (
|
||||
)
|
||||
|
||||
|
||||
def _base_gw_schema(discovery_info):
|
||||
def _base_gw_schema(discovery_info: ZeroconfServiceInfo | None) -> vol.Schema:
|
||||
"""Generate base schema for gateways."""
|
||||
base_gw_schema = {}
|
||||
base_gw_schema = vol.Schema({vol.Required(CONF_PASSWORD): str})
|
||||
|
||||
if not discovery_info:
|
||||
base_gw_schema[vol.Required(CONF_HOST)] = str
|
||||
base_gw_schema[vol.Optional(CONF_PORT, default=DEFAULT_PORT)] = int
|
||||
base_gw_schema[vol.Required(CONF_USERNAME, default=SMILE)] = vol.In(
|
||||
{SMILE: FLOW_SMILE, STRETCH: FLOW_STRETCH}
|
||||
base_gw_schema = base_gw_schema.extend(
|
||||
{
|
||||
vol.Required(CONF_HOST): str,
|
||||
vol.Optional(CONF_PORT, default=DEFAULT_PORT): int,
|
||||
vol.Required(CONF_USERNAME, default=SMILE): vol.In(
|
||||
{SMILE: FLOW_SMILE, STRETCH: FLOW_STRETCH}
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
base_gw_schema.update({vol.Required(CONF_PASSWORD): str})
|
||||
|
||||
return vol.Schema(base_gw_schema)
|
||||
return base_gw_schema
|
||||
|
||||
|
||||
async def validate_gw_input(hass: HomeAssistant, data: dict[str, Any]) -> Smile:
|
||||
|
@ -1,8 +1,9 @@
|
||||
"""DataUpdateCoordinator for Plugwise."""
|
||||
from datetime import timedelta
|
||||
from typing import Any, NamedTuple
|
||||
from typing import NamedTuple, cast
|
||||
|
||||
from plugwise import Smile
|
||||
from plugwise.constants import DeviceData, GatewayData
|
||||
from plugwise.exceptions import PlugwiseException, XMLDataMissingError
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -15,8 +16,8 @@ from .const import DEFAULT_SCAN_INTERVAL, DOMAIN, LOGGER
|
||||
class PlugwiseData(NamedTuple):
|
||||
"""Plugwise data stored in the DataUpdateCoordinator."""
|
||||
|
||||
gateway: dict[str, Any]
|
||||
devices: dict[str, dict[str, Any]]
|
||||
gateway: GatewayData
|
||||
devices: dict[str, DeviceData]
|
||||
|
||||
|
||||
class PlugwiseDataUpdateCoordinator(DataUpdateCoordinator[PlugwiseData]):
|
||||
@ -52,4 +53,7 @@ class PlugwiseDataUpdateCoordinator(DataUpdateCoordinator[PlugwiseData]):
|
||||
) from err
|
||||
except PlugwiseException as err:
|
||||
raise UpdateFailed(f"Updated failed for: {self.api.smile_name}") from err
|
||||
return PlugwiseData(*data)
|
||||
return PlugwiseData(
|
||||
gateway=cast(GatewayData, data[0]),
|
||||
devices=cast(dict[str, DeviceData], data[1]),
|
||||
)
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""Generic Plugwise Entity Class."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
from plugwise.constants import DeviceData
|
||||
|
||||
from homeassistant.const import ATTR_NAME, ATTR_VIA_DEVICE, CONF_HOST
|
||||
from homeassistant.helpers.device_registry import (
|
||||
@ -72,7 +72,7 @@ class PlugwiseEntity(CoordinatorEntity[PlugwiseDataUpdateCoordinator]):
|
||||
)
|
||||
|
||||
@property
|
||||
def device(self) -> dict[str, Any]:
|
||||
def device(self) -> DeviceData:
|
||||
"""Return data for this device."""
|
||||
return self.coordinator.data.devices[self._dev_id]
|
||||
|
||||
|
@ -82,7 +82,7 @@ async def async_setup_entry_gw(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry_gw(hass: HomeAssistant, entry: ConfigEntry):
|
||||
async def async_unload_entry_gw(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
if unload_ok := await hass.config_entries.async_unload_platforms(
|
||||
entry, PLATFORMS_GATEWAY
|
||||
|
Loading…
x
Reference in New Issue
Block a user