Repository navigation
Fix plantmode write no-op on Elco Aerotop device classified as GALEVO instead of bsb #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| { | ||
| "plantMode": 5, | ||
| "plantModeAsText": "Off", | ||
| "zoneMode": 2, | ||
| "zoneNumber": 1, | ||
| "zoneNumberAsText": "CASA", | ||
| "holidayExpiresOn": null, | ||
| "holidayExpiresOnAsText": "", | ||
| "isZoneFireplace": false, | ||
| "fireplaceExpiresOn": null, | ||
| "isAccessRequestAvailable": false, | ||
| "isAccessRequestGranted": false, | ||
| "isProposedDeroga": false, | ||
| "isZoneDeroga": false, | ||
| "isPilotOn": false, | ||
| "derogaTemp": 0, | ||
| "derogaExpiresOn": null, | ||
| "desiredTemp": { | ||
| "gatewayId": "PLACEHOLDER_GATEWAY_ID", | ||
| "zone": 1, | ||
| "id": "ZoneDesiredTemp", | ||
| "kind": 1, | ||
| "min": -3276.8, | ||
| "max": 3276.7, | ||
| "step": 0.5, | ||
| "value": 24, | ||
| "decimals": 1, | ||
| "options": [], | ||
| "optTexts": [], | ||
| "readOnly": true, | ||
| "error": false, | ||
| "invalid": false, | ||
| "expiresOn": null, | ||
| "unit": "°C" | ||
| }, | ||
| "antifreezeTemp": 5, | ||
| "roomTemp": 0, | ||
| "comfortTemp": 37, | ||
| "reducedTemp": 0, | ||
| "bottomSheetMessage": "", | ||
| "bottomSheetSecondary": "", | ||
| "bottomSheetMessageType": 0, | ||
| "isBottomSheetActionVisible": false, | ||
| "chFlowSetpointTemp": "18.0°C", | ||
| "heatingCircuitPressure": "Non disponibile", | ||
| "outsideTemp": "25 °C", | ||
| "weatherIcon": "gfm-icon--weather-nuvoloso", | ||
| "weatherCreditsUrl": "https://openweathermap.org", | ||
| "isWeatherVisible": true, | ||
| "virtOperativeMode": 1, | ||
| "isOptimumStartRunning": false, | ||
| "dhwCardVisible": false, | ||
| "advSettingsCardVisible": true, | ||
| "bottomSheetPrimaryActionKind": 0, | ||
| "isBottomSheetVisible": false, | ||
| "plantModeEval": 5, | ||
| "isWinter": false, | ||
| "isSummer": false, | ||
| "isHeating": false, | ||
| "isCooling": false, | ||
| "isOff": true, | ||
| "isHoliday": false, | ||
| "isZoneManual": false, | ||
| "isZoneOff": false, | ||
| "isZoneProgram": false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| """ | ||
| Legacy R2 (remocon-net) client. | ||
|
|
||
| Some GALEVO-classified devices (observed on Elco heat pumps with a BSB | ||
| controller) accept writes on the modern REST v2 endpoint | ||
| (`/api/v2/remote/dataItems/{gw}/set`) with a `{"success": true}` response, | ||
| but the command has NO effect on the physical device. | ||
|
|
||
| The official web client (remocon-net.remotethermo.com / ariston-net...) | ||
| for these same devices uses a legacy ASP.NET MVC-style endpoint instead: | ||
|
|
||
| POST /R2/PlantHome/GetData/{gatewayId}?umsys={umsys} (read) | ||
| POST /R2/PlantHome/SetData/{gatewayId}?umsys={umsys} (write) | ||
|
|
||
| This module is a minimal, isolated client for that legacy path, used only | ||
| as a fallback when the modern REST v2 write is confirmed to have no effect | ||
| (see `GalevoDevice.async_set_plant_mode` for the verification/fallback | ||
| logic). It intentionally does NOT share the aiohttp session or auth state | ||
| of the main `AristonAPI` client, since the two use different auth | ||
| mechanisms (session cookies here vs. bearer token there). | ||
|
|
||
| NOTE: `viewModel` returned by the site is NOT available via a clean read | ||
| endpoint - it's built client-side in JS from data embedded in the initial | ||
| page render. This client works around that by keeping a cached "known | ||
| good" viewModel (seeded from a real capture) and patching only the | ||
| plant-mode-related fields before writing. This is pragmatic but not fully | ||
| general - if Elco/Ariston changes the viewModel schema, or if other | ||
| fields turn out to matter for other kinds of writes, this will need | ||
| revisiting. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import logging | ||
| import os | ||
| from typing import Any, Optional | ||
|
|
||
| import aiohttp | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| # Bundled default viewModel template, captured from a real, confirmed- | ||
| # working "set to OFF" action on a specific Elco Aerotop / BSB gateway. | ||
| # IMPORTANT LIMITATION: this is device/account-specific pragmatism, not a | ||
| # general solution. It is used as a best-effort default so the fallback | ||
| # works out of the box for the device it was captured from, but other | ||
| # devices (different firmware/model) may have a different viewModel shape | ||
| # and this template may not apply cleanly. A more general fix would parse | ||
| # the live viewModel out of the initial /R2/Plant/Index page HTML instead | ||
| # of relying on a static bundled capture - left as a future improvement. | ||
| _DEFAULT_TEMPLATE_PATH = os.path.join( | ||
| os.path.dirname(__file__), "default_viewmodel_template.json" | ||
| ) | ||
|
|
||
|
|
||
| def _load_default_viewmodel() -> Optional[dict[str, Any]]: | ||
| try: | ||
| with open(_DEFAULT_TEMPLATE_PATH, "r", encoding="utf-8") as f: | ||
| return json.load(f) | ||
| except (FileNotFoundError, json.JSONDecodeError): | ||
| return None | ||
|
|
||
| _BASE_URL = "https://www.remocon-net.remotethermo.com" | ||
|
|
||
| # Confirmed via real captures. Note the sparse enum (value 3 does not | ||
| # exist) - do NOT derive this from list position/index. | ||
| PLANT_MODE_VALUES: dict[str, int] = { | ||
| "Estate": 0, # Summer (DHW only) | ||
| "Inverno": 1, # Winter (CH + DHW) | ||
| "Solo riscaldamento": 2, # Heating only | ||
| "Solo raffreddamento": 4, # Cooling only | ||
| "OFF": 5, # Off | ||
| } | ||
|
|
||
|
|
||
| class AristonR2LegacyClient: | ||
| """Minimal client for the legacy /R2/ write path, used as a fallback | ||
| when the REST v2 write silently no-ops on certain devices.""" | ||
|
|
||
| def __init__(self, username: str, password: str) -> None: | ||
| self._username = username | ||
| self._password = password | ||
| self._session: Optional[aiohttp.ClientSession] = None | ||
| self._logged_in = False | ||
| # Cached full viewModel from a real capture - see module docstring | ||
| # and _load_default_viewmodel() for the important caveats. | ||
| self._viewmodel_cache: Optional[dict[str, Any]] = _load_default_viewmodel() | ||
|
|
||
| async def _ensure_session(self) -> aiohttp.ClientSession: | ||
|
Check warning on line 90 in ariston/legacy_r2_client.py
|
||
| if self._session is None or self._session.closed: | ||
| self._session = aiohttp.ClientSession( | ||
| headers={ | ||
| "Content-Type": "application/json; charset=UTF-8", | ||
| "Accept": "application/json, text/javascript, */*; q=0.01", | ||
| "X-Requested-With": "XMLHttpRequest", | ||
| "ajax-request": "json", | ||
| } | ||
| ) | ||
| return self._session | ||
|
|
||
| async def _login(self) -> None: | ||
| session = await self._ensure_session() | ||
| url = f"{_BASE_URL}/R2/Account/Login?returnUrl=%2FR2%2FHome" | ||
| payload = { | ||
| "email": self._username, | ||
| "password": self._password, | ||
| "rememberMe": True, | ||
| "language": "Italian", | ||
| } | ||
| async with session.post(url, json=payload) as resp: | ||
| resp.raise_for_status() | ||
| body = await resp.json() | ||
| if not body.get("ok", True): | ||
| raise RuntimeError(f"Legacy R2 login failed: {body}") | ||
| self._logged_in = True | ||
| _LOGGER.debug("Legacy R2 client: login successful") | ||
|
|
||
| async def _get_data(self, gateway_id: str, umsys: str) -> dict[str, Any]: | ||
| session = await self._ensure_session() | ||
| url = f"{_BASE_URL}/R2/PlantHome/GetData/{gateway_id}?umsys={umsys}" | ||
| payload = { | ||
| "filter": {"notEssentials": False, "plant": True, "zone": True, "dhw": True}, | ||
| "useCache": False, | ||
| "zone": 1, | ||
| } | ||
| async with session.post(url, json=payload) as resp: | ||
| resp.raise_for_status() | ||
| body = await resp.json() | ||
| if not body.get("ok"): | ||
| raise RuntimeError(f"Legacy R2 GetData failed: {body}") | ||
| return body["data"] | ||
|
|
||
| async def async_set_plant_mode( | ||
| self, | ||
| gateway_id: str, | ||
| plant_mode_text: str, | ||
| umsys: str = "si", | ||
| ) -> dict[str, Any]: | ||
| """Set plant mode via the legacy /R2/ endpoint. | ||
|
|
||
| `plant_mode_text` must be one of PLANT_MODE_VALUES keys, using the | ||
| *localized* text as returned by the device's own PlantMode | ||
| optTexts (observed in English on some accounts, Italian on | ||
| others - callers should pass the exact text seen in the device's | ||
| own `optTexts`, not a hardcoded assumption). | ||
| """ | ||
| if not self._logged_in: | ||
| await self._login() | ||
|
|
||
| if self._viewmodel_cache is None: | ||
| _LOGGER.warning( | ||
| "Legacy R2 client has no cached viewModel yet; a real " | ||
| "capture must seed it before this fallback can work. " | ||
| "See AristonR2LegacyClient.seed_viewmodel()." | ||
| ) | ||
| raise RuntimeError("No viewModel template available for legacy write") | ||
|
|
||
| data = await self._get_data(gateway_id, umsys) | ||
| items = data["items"] | ||
| features = data["features"] | ||
|
|
||
| value = PLANT_MODE_VALUES.get(plant_mode_text) | ||
| if value is None: | ||
| raise ValueError(f"Unknown plant mode '{plant_mode_text}'") | ||
|
|
||
| view_model = dict(self._viewmodel_cache) # shallow copy is enough here | ||
| view_model["plantMode"] = value | ||
| view_model["plantModeAsText"] = plant_mode_text | ||
| view_model["plantModeEval"] = value | ||
| view_model["isOff"] = plant_mode_text == "OFF" | ||
| view_model["isSummer"] = plant_mode_text == "Estate" | ||
| view_model["isWinter"] = plant_mode_text == "Inverno" | ||
| view_model["isHeating"] = plant_mode_text in ("Inverno", "Solo riscaldamento") | ||
| view_model["isCooling"] = plant_mode_text == "Solo raffreddamento" | ||
| if isinstance(view_model.get("desiredTemp"), dict): | ||
| view_model["desiredTemp"] = dict(view_model["desiredTemp"]) | ||
| view_model["desiredTemp"]["gatewayId"] = gateway_id | ||
|
|
||
| session = await self._ensure_session() | ||
| url = f"{_BASE_URL}/R2/PlantHome/SetData/{gateway_id}?umsys={umsys}" | ||
| payload = {"features": features, "prevItems": items, "viewModel": view_model} | ||
| async with session.post(url, json=payload) as resp: | ||
| resp.raise_for_status() | ||
| body = await resp.json() | ||
| if not body.get("ok"): | ||
| raise RuntimeError(f"Legacy R2 SetData failed: {body}") | ||
| _LOGGER.debug( | ||
| "Legacy R2 SetData succeeded, changedItems=%s", | ||
| body.get("data", {}).get("changedItems"), | ||
| ) | ||
| return body | ||
|
|
||
| def seed_viewmodel(self, viewmodel: dict[str, Any]) -> None: | ||
| """Provide a known-good viewModel captured from a real browser | ||
| session (see project docs / HAR capture instructions). Required | ||
| before async_set_plant_mode can be used, since the site does not | ||
| expose a clean read endpoint for the viewModel itself.""" | ||
| self._viewmodel_cache = dict(viewmodel) | ||
|
|
||
| async def close(self) -> None: | ||
| if self._session and not self._session.closed: | ||
| await self._session.close() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical — The fallback rejects labels returned by the default API locale.
async_set_plant_modepasses the selected text fromPLANT_MODE.optTexts; those labels follow the configuredlanguage_tag, which defaults toen-US. This lookup accepts only Italian labels and uppercaseOFF(while the bundled template itself usesOff), so the fallback raisesValueErrorfor ordinary English labels such asOfforWinterwhen the REST write has no effect. Map the mode by its numeric value to the label expected by the R2 endpoint, or translate the configured label before this lookup.