Use typed config entry in rainbird (#132031)

* Use typed config entry in rainbird

* Adjust
pull/132040/head
epenet 2024-12-02 07:27:47 +01:00 committed by GitHub
parent 80f28302a1
commit 28eb4f3dff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 14 deletions

View File

@ -9,7 +9,6 @@ import aiohttp
from pyrainbird.async_client import AsyncRainbirdClient, AsyncRainbirdController
from pyrainbird.exceptions import RainbirdApiException, RainbirdAuthException
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_HOST,
CONF_MAC,
@ -46,7 +45,7 @@ DOMAIN = "rainbird"
def _async_register_clientsession_shutdown(
hass: HomeAssistant,
entry: ConfigEntry,
entry: RainbirdConfigEntry,
clientsession: aiohttp.ClientSession,
) -> None:
"""Register cleanup hooks for the clientsession."""
@ -126,7 +125,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: RainbirdConfigEntry) ->
async def _async_fix_unique_id(
hass: HomeAssistant, controller: AsyncRainbirdController, entry: ConfigEntry
hass: HomeAssistant, controller: AsyncRainbirdController, entry: RainbirdConfigEntry
) -> bool:
"""Update the config entry with a unique id based on the mac address."""
_LOGGER.debug("Checking for migration of config entry (%s)", entry.unique_id)
@ -255,6 +254,6 @@ def _async_fix_device_id(
)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_unload_entry(hass: HomeAssistant, entry: RainbirdConfigEntry) -> bool:
"""Unload a config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)

View File

@ -12,17 +12,13 @@ from pyrainbird.data import WifiParams
from pyrainbird.exceptions import RainbirdApiException, RainbirdAuthException
import voluptuous as vol
from homeassistant.config_entries import (
ConfigEntry,
ConfigFlow,
ConfigFlowResult,
OptionsFlow,
)
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult, OptionsFlow
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PASSWORD
from homeassistant.core import callback
from homeassistant.helpers import config_validation as cv, selector
from homeassistant.helpers.device_registry import format_mac
from . import RainbirdConfigEntry
from .const import (
ATTR_DURATION,
CONF_SERIAL_NUMBER,
@ -69,7 +65,7 @@ class RainbirdConfigFlowHandler(ConfigFlow, domain=DOMAIN):
@staticmethod
@callback
def async_get_options_flow(
config_entry: ConfigEntry,
config_entry: RainbirdConfigEntry,
) -> RainBirdOptionsFlowHandler:
"""Define the config flow to handle options."""
return RainBirdOptionsFlowHandler()

View File

@ -15,13 +15,13 @@ from pyrainbird.async_client import (
)
from pyrainbird.data import ModelAndVersion, Schedule
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.debounce import Debouncer
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from .const import DOMAIN, MANUFACTURER, TIMEOUT_SECONDS
from .types import RainbirdConfigEntry
UPDATE_INTERVAL = datetime.timedelta(minutes=1)
# The calendar data requires RPCs for each program/zone, and the data rarely
@ -140,7 +140,7 @@ class RainbirdUpdateCoordinator(DataUpdateCoordinator[RainbirdDeviceState]):
class RainbirdScheduleUpdateCoordinator(DataUpdateCoordinator[Schedule]):
"""Coordinator for rainbird irrigation schedule calls."""
config_entry: ConfigEntry
config_entry: RainbirdConfigEntry
def __init__(
self,

View File

@ -1,13 +1,20 @@
"""Types for Rain Bird integration."""
from __future__ import annotations
from dataclasses import dataclass
from typing import TYPE_CHECKING
from pyrainbird.async_client import AsyncRainbirdController
from pyrainbird.data import ModelAndVersion
from homeassistant.config_entries import ConfigEntry
from .coordinator import RainbirdScheduleUpdateCoordinator, RainbirdUpdateCoordinator
if TYPE_CHECKING:
from .coordinator import (
RainbirdScheduleUpdateCoordinator,
RainbirdUpdateCoordinator,
)
@dataclass