Keg-change detection previously fired only when the pour counter reset to 0 while the keg read near full. That misses the common case where the user swaps the keg and pours immediately, so pours never reads 0. Detection now also fires on two volume-based signals (independent of the pour counter): (b) remaining volume jumping from below 80% to at least 95%, and (c) any upward jump of at least 50 percentage points. The decision logic is extracted to a dependency-free keg_detection module with unit tests covering each trigger and the swap-then-pour case. Adds a "Mark Keg Changed" button as a deterministic manual override, wired to the freshness sensor via a dispatcher signal; the sensor now tracks and restores last_volume alongside last_pours. Bumps version to 0.3.0. Co-authored-by: Cursor <cursoragent@cursor.com>
28 lines
784 B
Python
28 lines
784 B
Python
DOMAIN = "perfectdraft"
|
|
|
|
API_BASE_URL = "https://api.perfectdraft.com"
|
|
API_KEY = "cAyzERqthCJXYVExjNAhr9CzE8ncLN2cQK3WGK10"
|
|
|
|
RECAPTCHA_SITE_KEY = "6LcZQiUoAAAAAAO3JUjLiT470c-pNXbWyepuvMtV"
|
|
RECAPTCHA_ACTION = "Magento/login"
|
|
|
|
COGNITO_REGION = "eu-west-1"
|
|
COGNITO_CLIENT_ID = "57ddq2ppqg2jcpup06r2g1deur"
|
|
|
|
DEFAULT_SCAN_INTERVAL = 900 # 15 minutes
|
|
MIN_SCAN_INTERVAL = 60 # 1 minute
|
|
|
|
CONF_REFRESH_TOKEN = "refresh_token"
|
|
CONF_ACCESS_TOKEN = "access_token"
|
|
CONF_ID_TOKEN = "id_token"
|
|
CONF_USER_ID = "user_id"
|
|
CONF_MACHINE_ID = "machine_id"
|
|
CONF_SCAN_INTERVAL = "scan_interval"
|
|
|
|
PLATFORMS = ["sensor", "button"]
|
|
|
|
|
|
def keg_changed_signal(machine_id: str) -> str:
|
|
"""Dispatcher signal fired when the keg is manually marked as changed."""
|
|
return f"{DOMAIN}_keg_changed_{machine_id}"
|