Metadata-Version: 2.4
Name: aioaquarea-ng
Version: 1.5.0
Summary: Asynchronous library to control Panasonic Aquarea devices
Author-email: "Carlos J. Aliaga" <dev@cjaliaga.net>
Maintainer: wpatrik14
License: MIT License
        
        Copyright (c) 2022 Carlos J. Aliaga
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/wpatrik14/aioaquarea
Project-URL: Bug Tracker, https://github.com/wpatrik14/aioaquarea/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: aiohttp>=3.9
Requires-Dist: beautifulsoup4
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-asyncio; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Requires-Dist: aioresponses; extra == "test"
Requires-Dist: aiohttp<3.14; extra == "test"
Provides-Extra: lint
Requires-Dist: ruff; extra == "lint"
Dynamic: license-file

# aioaquarea-ng

[![PyPI](https://img.shields.io/pypi/v/aioaquarea-ng)](https://pypi.org/project/aioaquarea-ng/)

Asynchronous Python library for Panasonic Aquarea heat pumps, through the Panasonic Aquarea Smart Cloud API. It powers the [home-assistant-aquarea](https://github.com/wpatrik14/home-assistant-aquarea) integration.

This is the maintained fork of [cjaliaga/aioaquarea](https://github.com/cjaliaga/aioaquarea), originally written by Carlos J. Aliaga. Upstream has had no merges or releases since May 2026, and Panasonic has started enforcing multi-factor authentication on logins ([cjaliaga/aioaquarea#92](https://github.com/cjaliaga/aioaquarea/issues/92)), so development continues here. The package name changed; the import name did not.

## Installation

```bash
pip install aioaquarea-ng
```

```python
import aioaquarea  # same import name as the original package
```

Don't install it next to the original `aioaquarea` package: both provide the `aioaquarea` module.

## Status

- **Multi-factor authentication:** accounts with Panasonic's MFA (SMS or authenticator app code) are supported. `Client.login()` raises `MfaRequiredError` (an `AuthenticationError` with code `MFA_REQUIRED`) carrying an `MfaChallenge`; pass the code to `Client.complete_mfa()`. See [Multi-factor authentication](#multi-factor-authentication).
- **Water pressure:** `Device.water_pressure` (bar), when the unit reports it (live reads only; `Device.status_data_mode` is `CACHED` when the library had to fall back to the cloud's cached status, which has no water pressure).
- **Eco / comfort presets:** `Device.special_status` reads the preset (`SpecialStatus.ECO`, `SpecialStatus.COMFORT`, or `None`); `Device.set_special_status()` switches it, moving the zone setpoints by the preset offsets like the app does.
- **On/off state:** `Device.operation_status` is ON while any zone or the tank is on.
- **Zones:** built from the device status, with the names set in the app (`DeviceZone.name`), the raw zone type/sensor values and cooling support from `coolMode`. Unconfigured placeholder zones are no longer reported.
- **More device fields (read only):** `bivalent`, `bivalent_actual`, `external_heater`, `electric_anode`, `control_box`, `uncontrollable`, `service_type`, `multi_od_connection`, `model_series_selection`, `stand_alone`, `connection_status`, `dhw_flag` (raw values; `None` when the unit does not report them).
- **Consumption:** `Client.get_device_consumption()` (day / month / year buckets) and `Client.get_device_consumption_report()` with the tariff and currency, last year's months (year view) and `Consumption.is_future` for buckets that are still in the future.
- **Weekly timer (read only):** `Client.get_weekly_timer()` / `Device.get_weekly_timer()` return the schedule (7 days x 6 slots) and the setpoint limits.
- **Agreements:** when Panasonic publishes new terms (error 4103) requests raise `AgreementNotAcceptedError`; accept them in the Panasonic Comfort Cloud app. `Client.get_agreement_status()` lists the accepted versions.

What the cloud API offers, and what has been verified, is described in [docs/api-map.md](docs/api-map.md).

Bug reports and pull requests are welcome in this repository.

## Requirements

This library requires:

- Python >= 3.11
- asyncio
- aiohttp

## Usage
The library supports the production environment of the Panasonic Aquarea Smart Cloud API and also the Demo environment. One of the main usages of this library is to integrate the Panasonic Aquarea Smart Cloud API with Home Assistant via [home-assistant-aquarea](https://github.com/wpatrik14/home-assistant-aquarea)

Here is a simple example of how to use the library via getting a device object to interact with it:

```python
from aioaquarea import (
    Client,
    AquareaEnvironment,
    UpdateOperationMode
)

import aiohttp
import asyncio
import logging
from datetime import timedelta

async def main():
    async with aiohttp.ClientSession() as session:
        client = Client(
            username="USERNAME",
            password="PASSWORD",
            session=session,
            device_direct=True,
            refresh_login=True,
            environment=AquareaEnvironment.PRODUCTION,
        )

        # The library is designed to retrieve a device object and interact with it:
        devices = await client.get_devices(include_long_id=True)

        # Picking the first device associated with the account:
        device_info = devices[0]

        device = await client.get_device(
            device_info=device_info, consumption_refresh_interval=timedelta(minutes=1)
        )

        # Or the device can also be retrieved by its long id if we know it:
        device = await client.get_device(
            device_id="LONG ID", consumption_refresh_interval=timedelta(minutes=1)
        )

        # Then we can interact with the device:
        await device.set_mode(UpdateOperationMode.HEAT)

        # The device can automatically refresh its data:
        await device.refresh_data()
```

## Multi-factor authentication

```python
from aioaquarea import Client, MfaRequiredError

client = Client(session, username, password)
try:
    await client.login()
except MfaRequiredError as err:
    challenge = err.challenge  # factor "sms" or "otp", masked destination, code_sent
    # For SMS the code has been texted already; ask the user for the code, then:
    await client.complete_mfa(code)  # logged in now, like after a normal login
    # await client.resend_mfa_code()  # SMS only
```

`complete_mfa` raises `AuthenticationError` with code `MFA_INVALID_CODE` for a wrong code (retry with another one), `MFA_EXPIRED` when the MFA transaction timed out (call `login()` again) and `API_ERROR` (naming the step) for anything unexpected. Pages or factors that are not supported (for example push notifications) raise a plain `MFA_REQUIRED` error without a challenge. Pass `mfa_send_code=False` to the client for background logins that must not text a code.

**Avoiding MFA on every login:** the login asks for the `offline_access` scope, so the token response normally carries a refresh token. Store `client.refresh_token` (a secret) and pass it as `Client(session, username, password, refresh_token=...)`; `login()` then refreshes the token without the password or an MFA code, and only falls back to the password (and MFA) when Panasonic rejects the refresh token. The refresh token can rotate: pass `refresh_token_callback=` (a plain function taking the new token) to be told whenever a login or refresh returned a different one.

## App version

Panasonic's login gate rejects app versions it no longer accepts with HTTP 401 / code 4106 ("New version app has been published"), and the version shown in the app stores is not always the accepted one. So the library does not trust a single source: it probes the gate (with a dummy token, no credentials) with candidates from Google Play, the App Store, the last version that worked and built-in constants, and uses the first one the gate accepts. The result is cached for the lifetime of the process and re-checked once if a login gets a 4106. When every candidate is rejected, `Client.login()` raises `AppVersionRejectedError` (an `AuthenticationError` subclass, code `APP_VERSION_REJECTED`): that is a Panasonic-side change and not a credentials problem, and the fix is a new release of this library.

### App version canary

The workflow [`app-version-canary.yml`](.github/workflows/app-version-canary.yml) runs [`scripts/check_app_version_gate.py`](scripts/check_app_version_gate.py) daily (and on demand via "Run workflow"). It runs the same credential-free probe and, when every candidate version is rejected or the gate answers something unexpected, opens one issue titled "Panasonic gate rejects app version" with the `panasonic-gate` label (created if missing; no second issue while one is open). It uses no secrets, only the default token with `contents: read` and `issues: write`. Run it locally with `python scripts/check_app_version_gate.py` (exit code 0 = a version is accepted).

## Acknowledgements

The original library is by [Carlos J. Aliaga](https://github.com/cjaliaga) ([cjaliaga/aioaquarea](https://github.com/cjaliaga/aioaquarea)), MIT licensed.


Big thanks to [ronhks](https://github.com/ronhks) for his awesome work on the [Panasonic Aquarea Smart Cloud integration with MQTT](https://github.com/ronhks/panasonic-aquarea-smart-cloud-mqtt).
