Files
homeassistant-dkncloudna/custom_components/dkncloudna/const.py
T
thatguygriff 494c6df2c3
Validate / Hassfest validation (pull_request) Has been skipped
Validate / HACS validation (pull_request) Has been skipped
fix(climate): keep optimistic state until DKN cloud catches up
The DKN cloud REST endpoint lags behind the unit for several seconds
after a write, even though the unit itself and the DKN app reflect
the change immediately. The previous 2.5s optimistic-overlay TTL
expired well before the cloud caught up, so the next coordinator
publish (REST poll or socket device-data push) carried stale values
and the HA UI reverted to the previous setting.

Extend the overlay TTL to 30s as a safety bound, and track the
underlying device key + expected device value alongside each overlay.
On every coordinator publish, clear overlays whose device key now
reports the expected value (cloud has confirmed). The TTL still
caps how long a silently-failed write can hold a wrong value.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 09:49:04 -03:00

70 lines
1.9 KiB
Python

"""Constants for DKN Cloud NA integration."""
from __future__ import annotations
import logging
DOMAIN = "dkncloudna"
LOGGER = logging.getLogger(__package__)
MANUFACTURER = "Daikin"
# API
BASE_URL = "https://dkncloudna.com"
API_BASE = "/api/v1"
API_LOGIN = f"{API_BASE}/auth/login/dknUsa"
API_IS_LOGGED_IN = f"{API_BASE}/users/isLoggedIn/dknUsa"
API_REFRESH_TOKEN = f"{API_BASE}/auth/refreshToken/{{refresh_token}}/dknUsa"
API_INSTALLATIONS = f"{API_BASE}/installations/dknUsa"
API_SOCKET_PATH = f"{API_BASE}/devices/socket.io/"
API_USERS_NAMESPACE = "/users"
# The DKN Cloud NA API requires a mobile-like User-Agent.
# This matches what the official DKN Cloud NA iOS app sends.
USER_AGENT = (
"Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) "
"AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"
)
REQUEST_TIMEOUT = 30 # seconds
SOCKET_RECONNECT_ATTEMPTS = 5
# Config/options keys
CONF_SCAN_INTERVAL = "scan_interval"
CONF_EXPOSE_PII = "expose_pii"
CONF_USER_TOKEN = "user_token"
CONF_REFRESH_TOKEN = "refresh_token"
# Defaults
DEFAULT_SCAN_INTERVAL = 60 # seconds
MIN_SCAN_INTERVAL = 30
MAX_SCAN_INTERVAL = 300
# Optimistic overlay: safety bound for cloud-propagation lag. Overlays
# normally clear earlier via reconciliation once the device echoes the
# requested value; this TTL guarantees the UI cannot get stuck on a
# locally-set value indefinitely if the write was silently rejected.
OPTIMISTIC_TTL_SEC: float = 30.0
# Post-write coordinator refresh: coalesced delay after a device command.
POST_WRITE_REFRESH_DELAY_SEC: float = 1.0
# Device modes (from homebridge plugin src/types.ts)
# DeviceMode: 1=Auto, 2=Cool, 3=Heat, 4=Fan, 5=Dry
DEVICE_MODE_AUTO = 1
DEVICE_MODE_COOL = 2
DEVICE_MODE_HEAT = 3
DEVICE_MODE_FAN = 4
DEVICE_MODE_DRY = 5
# Fan speeds (SpeedState)
SPEED_AUTO = 0
SPEED_20 = 2
SPEED_40 = 3
SPEED_60 = 4
SPEED_80 = 5
SPEED_100 = 6
# Temperature units
TEMP_CELSIUS = 0
TEMP_FAHRENHEIT = 1