Skip to content

Read heat produced from the web metering page - #9

Merged
wojciech-aniol merged 3 commits into
mainfrom
web-metering
Oct 25, 2026
Merged

wojciech-aniol merged 3 commits into
mainfrom
web-metering

Conversation

@wojciech-aniol

@wojciech-aniol wojciech-aniol commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

The API token gives only the electricity a heat pump used. The heat it produced is only on the web app's metering page, so AristonAPI.get_metering_data / async_get_metering_data now log in to the web app in one cookie session and read R2/PlantMetering/GetData. GALEVO devices with hasMetering get update_metering() and get_metering_total(tab, series, period) for heat produced and COP in the integration (plan 26). Not called from update_energy, so request counts stay the same.

Changes

  • const.py: ARISTON_WEB_USER_AGENT (browser string, the only one tested), web login/data paths, the cookie name, MeteringTab, MeteringSeries, MeteringPeriod (cloud strings) and MeteringData (answer keys).
  • ariston_api.py: get_metering_data(gw_id, features, has_cooling) and the async twin. The web URL is the scheme and host of api_url. One requests.Session / aiohttp.ClientSession (30 s timeout) per call: login, then GetData with X-Requested-With: XMLHttpRequest. Redirects are not followed: the login answer sets the cookie, so the home page is never loaded. Raises ConnectionException:
    • ("Web login failed",): no .AspNet.ApplicationCookie after the login,
    • ("Metering answer is not JSON",): a login page,
    • ("Metering failed", <message>): ok is false,
    • (status,) for other HTTP errors (no retry; the next update tries again),
    • (429, "blocked for N seconds") or (429, ""): blocks the account like API requests. The block is checked before each web request, so an API 429 also stops the web login. API and web share one 429 helper.
    • Web answers are never logged or put in an exception, not even a 429 page (web pages hold personal data).
  • galevo_device.py: update_metering() / async_update_metering() (loads the features first if they are not loaded; no request unless has_metering is True; hasCooling from the PlantMode options 3/4, None when they are unknown, as the web app sends it), metering_data keeps only oldestMonth, isIntensiveLogsActive and asKwhRaw, get_metering_total(...) -> float | None (null fields and non-number values never raise), is_metering_intensive_logs_active.
  • README: "Get heat produced".
  • Tests: FakeSession and a new FakeSyncSession have a cookie jar and record web requests (with allow_redirects). 33 new tests (sync and async): login and body/headers/redirects, refused login, login page, ok false, HTTP error, 429 both ways, a 429 page not logged; device totals, missing row, null values, no metering, features loaded first, hasCooling. The new tests fail on the code before them. 146 tests, ruff clean.

Notes

  • Also checked with real requests and aiohttp against a local server that answers like the web app (302 with the cookie): both paths keep the cookie without following the redirect and send it to GetData; a wrong password gives "Web login failed". One update is 2 HTTP requests.
  • Checked on the real cloud on 2026-10-25 (owner's Nimbus 120 S-T NET R32, head 5a4b3b8): the login answer itself sets .AspNet.ApplicationCookie, so not following the redirect works. hasMetering: True, intensive logs false, 36 rows, and the totals match the research run of the same day (for example 2025 and yesterday's heating and DHW).
  • Unknown, as in the plan: the real answers for a wrong password, an expired session and ok: false.
  • is_plant_mode_options_contains_cooling raises TypeError when the device has no PlantMode item. Left as is (a public property, better fixed in its own PR); the metering code checks for None first.

Review (/code-review)

Fixed: null fields in get_metering_total, the login judged by the home page status (now no redirects), a web 429 page in the log, hasCooling false instead of null, a silent no-op before features are loaded, the 429 code in three copies, the local json name that hid the module, async with for the web response.

Not changed:

  • GetData without GetUiDefinition first: the check script shows at once if it is needed.
  • Only the first matching row is summed: several rows for one tab/series/period are a guess, and adding them all could count energy twice.
  • A custom api_url with a path prefix loses the prefix: the plan says scheme and host, and no such setup is known.
  • A new session and login per update: the plan's choice (no cookies kept).

Check on the real cloud

Done on 2026-10-25 (see Notes). It asks for the login, saves nothing, and prints only the totals (not the gateway):

uv run --with "git+https://github.com/wojciech-aniol/python-ariston-net-api@web-metering" python check_metering.py

check_metering.py:

import asyncio
import getpass

from ariston_net_api import Ariston
from ariston_net_api.const import (
    MeteringPeriod,
    MeteringSeries,
    MeteringTab,
    SystemType,
)


async def main() -> None:
    ariston = Ariston()
    await ariston.async_connect(input("Login: "), getpass.getpass("Password: "))
    devices = await ariston.async_discover()
    gateway = next(d["gw"] for d in devices if d.get("sys") == SystemType.GALEVO.value)
    device = await ariston.async_hello(gateway)
    await device.async_update_state()
    await device.async_update_metering()
    print("hasMetering:", device.has_metering)
    print("intensive logs:", device.is_metering_intensive_logs_active)
    for tab in MeteringTab:
        for series in MeteringSeries:
            for period in MeteringPeriod:
                total = device.get_metering_total(tab, series, period)
                if total is not None:
                    print(f"{tab:20} {series:8} {period:14} {total:10.2f} kWh")


asyncio.run(main())

Expected: hasMetering: True, intensive logs: False, and 36 rows (2 tabs × 3 series × 6 periods) with kWh that match the web app.

🤖 Generated with Claude Code

The API token gives only the electricity a heat pump used. The heat it
produced is only on the web app's metering page, so the API can now log
in to the web app (cookie session) and read PlantMetering/GetData.
GALEVO devices with hasMetering keep the not rounded kWh view and give
totals per tab, series and period. update_energy does not call it, so
request counts stay the same until the integration polls it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wojciech-aniol wojciech-aniol added the minor Auto release: bump the minor version label Oct 25, 2026
@wojciech-aniol wojciech-aniol self-assigned this Oct 25, 2026
@wojciech-aniol
wojciech-aniol marked this pull request as ready for review October 25, 2026 14:57
wojciech-aniol and others added 2 commits October 25, 2026 15:59
# Conflicts:
#	tests/test_galevo_device.py
A null or wrong value in the metering answer no longer raises. The web
login no longer follows its redirect, so a failing home page cannot fail
a good login, one request is saved and no page with personal data is
downloaded. A web 429 keeps only the block time, never the page. The
429 handling is one helper for API and web requests. hasCooling is None
when the plant modes are unknown, as the web app sends it, and a device
loads its features before the first metering update.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wojciech-aniol
wojciech-aniol merged commit 9276324 into main Oct 25, 2026
5 checks passed
@wojciech-aniol
wojciech-aniol deleted the web-metering branch October 25, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor Auto release: bump the minor version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant