A module that is online but cut off from the control box keeps serving and publishing a full document of blank and default values. Read literally that is an idle spa: no temperatures, salt level 0, lights and jets off, and controls that accept a value and snap back. - The spa counts as reporting only while telemetry is fresh (something arrived in the last five minutes) and carries control-box data. Otherwise every entity is unavailable, and the reason is logged once per change. - The entry still loads in that state, so entities return on their own when the spa reports again. - A watchdog catches silence between updates, and reloads the entry when the broker connection stays down for three minutes. The broker is the only control path and its credentials rotate; paho reconnects with the old ones, so only a fresh sign-in recovers it. - Version 0.2.0. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
54 lines
1.9 KiB
Python
54 lines
1.9 KiB
Python
"""Number entity: FreshWater salt system output level (0-10, settable)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from homeassistant.components.number import NumberEntity, NumberMode
|
|
from homeassistant.core import HomeAssistant, callback
|
|
from homeassistant.helpers.device_registry import DeviceInfo
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from . import HotSpringConfigEntry
|
|
from .constants import DOMAIN, MANUFACTURER, SALT_LEVEL_MAX, SALT_LEVEL_MIN
|
|
from .coordinator import HotSpringCoordinator
|
|
from .entity import HotSpringEntity
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
entry: HotSpringConfigEntry,
|
|
async_add_entities: AddEntitiesCallback,
|
|
) -> None:
|
|
async_add_entities([HotSpringSaltLevel(entry.runtime_data)])
|
|
|
|
|
|
class HotSpringSaltLevel(HotSpringEntity, NumberEntity):
|
|
_attr_has_entity_name = True
|
|
_attr_translation_key = "salt_output_level"
|
|
_attr_native_min_value = SALT_LEVEL_MIN
|
|
_attr_native_max_value = SALT_LEVEL_MAX
|
|
_attr_native_step = 1
|
|
_attr_mode = NumberMode.SLIDER
|
|
_attr_icon = "mdi:shaker-outline"
|
|
|
|
def __init__(self, coordinator: HotSpringCoordinator) -> None:
|
|
super().__init__(coordinator)
|
|
root = coordinator.spa_info.root_topic if coordinator.spa_info else "spa"
|
|
self._attr_unique_id = f"{root}_salt_output_level"
|
|
self._attr_device_info = DeviceInfo(
|
|
identifiers={(DOMAIN, root)},
|
|
manufacturer=MANUFACTURER,
|
|
name=coordinator.spa_info.name if coordinator.spa_info else "Hot Spring Spa",
|
|
model="Connected Spa",
|
|
)
|
|
|
|
@property
|
|
def native_value(self) -> float | None:
|
|
return self.coordinator.spa.salt_output_level() if self.coordinator.spa else None
|
|
|
|
async def async_set_native_value(self, value: float) -> None:
|
|
await self.coordinator.async_set_salt_level(int(value))
|
|
|
|
@callback
|
|
def _handle_coordinator_update(self) -> None:
|
|
self.async_write_ha_state()
|