Enable retries on rainbird devices by loading model and version (#96190)
Update rainbird to load device model and versionpull/96229/head
parent
995fb993e6
commit
32b3fa1734
|
@ -2,10 +2,12 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from pyrainbird.async_client import AsyncRainbirdClient, AsyncRainbirdController
|
||||
from pyrainbird.exceptions import RainbirdApiException
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import CONF_SERIAL_NUMBER
|
||||
|
@ -29,11 +31,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
entry.data[CONF_PASSWORD],
|
||||
)
|
||||
)
|
||||
try:
|
||||
model_info = await controller.get_model_and_version()
|
||||
except RainbirdApiException as err:
|
||||
raise ConfigEntryNotReady from err
|
||||
coordinator = RainbirdUpdateCoordinator(
|
||||
hass,
|
||||
name=entry.title,
|
||||
controller=controller,
|
||||
serial_number=entry.data[CONF_SERIAL_NUMBER],
|
||||
model_info=model_info,
|
||||
)
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ from typing import TypeVar
|
|||
|
||||
import async_timeout
|
||||
from pyrainbird.async_client import AsyncRainbirdController, RainbirdApiException
|
||||
from pyrainbird.data import ModelAndVersion
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
@ -42,6 +43,7 @@ class RainbirdUpdateCoordinator(DataUpdateCoordinator[RainbirdDeviceState]):
|
|||
name: str,
|
||||
controller: AsyncRainbirdController,
|
||||
serial_number: str,
|
||||
model_info: ModelAndVersion,
|
||||
) -> None:
|
||||
"""Initialize ZoneStateUpdateCoordinator."""
|
||||
super().__init__(
|
||||
|
@ -54,6 +56,7 @@ class RainbirdUpdateCoordinator(DataUpdateCoordinator[RainbirdDeviceState]):
|
|||
self._controller = controller
|
||||
self._serial_number = serial_number
|
||||
self._zones: set[int] | None = None
|
||||
self._model_info = model_info
|
||||
|
||||
@property
|
||||
def controller(self) -> AsyncRainbirdController:
|
||||
|
@ -72,6 +75,8 @@ class RainbirdUpdateCoordinator(DataUpdateCoordinator[RainbirdDeviceState]):
|
|||
name=f"{MANUFACTURER} Controller",
|
||||
identifiers={(DOMAIN, self._serial_number)},
|
||||
manufacturer=MANUFACTURER,
|
||||
model=self._model_info.model_name,
|
||||
sw_version=f"{self._model_info.major}.{self._model_info.minor}",
|
||||
)
|
||||
|
||||
async def _async_update_data(self) -> RainbirdDeviceState:
|
||||
|
|
|
@ -35,6 +35,8 @@ SERIAL_NUMBER = 0x12635436566
|
|||
|
||||
# Get serial number Command 0x85. Serial is 0x12635436566
|
||||
SERIAL_RESPONSE = "850000012635436566"
|
||||
# Model and version command 0x82
|
||||
MODEL_AND_VERSION_RESPONSE = "820006090C"
|
||||
# Get available stations command 0x83
|
||||
AVAILABLE_STATIONS_RESPONSE = "83017F000000" # Mask for 7 zones
|
||||
EMPTY_STATIONS_RESPONSE = "830000000000"
|
||||
|
@ -183,7 +185,13 @@ def mock_api_responses(
|
|||
|
||||
These are returned in the order they are requested by the update coordinator.
|
||||
"""
|
||||
return [stations_response, zone_state_response, rain_response, rain_delay_response]
|
||||
return [
|
||||
MODEL_AND_VERSION_RESPONSE,
|
||||
stations_response,
|
||||
zone_state_response,
|
||||
rain_response,
|
||||
rain_delay_response,
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture(name="responses")
|
||||
|
|
|
@ -70,6 +70,8 @@ async def test_set_value(
|
|||
device = device_registry.async_get_device({(DOMAIN, SERIAL_NUMBER)})
|
||||
assert device
|
||||
assert device.name == "Rain Bird Controller"
|
||||
assert device.model == "ST8x-WiFi"
|
||||
assert device.sw_version == "9.12"
|
||||
|
||||
aioclient_mock.mock_calls.clear()
|
||||
responses.append(mock_response(ACK_ECHO))
|
||||
|
|
Loading…
Reference in New Issue