Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This project separates **code** from **interface**:

- **The interface is multi-language.** Every user-facing string goes through
Home Assistant's translation system in `custom_components/addhon/translations/`
(currently `en.json` and `it.json`), never hardcoded in the code:
(currently `en.json`, `it.json` and `fr.json`), never hardcoded in the code:
- **Entity names**: set `_attr_translation_key` (entities use
`_attr_has_entity_name`) and add `entity.<platform>.<key>.name` to the
translations. Do not set a hardcoded `name=` / `_attr_name`.
Expand All @@ -32,9 +32,9 @@ This project separates **code** from **interface**:
`tests/test_entity_translation_keys.py`). Free-text values (program names,
raw error codes) are device data and stay unmapped.

`en.json` and `it.json` must keep an identical key structure (enforced by
`tests/test_translations.py` and `tests/test_entity_translation_keys.py`). Add a
key to both languages at once. Use plain text: no emoji, no long dashes.
`en.json`, `it.json` and `fr.json` must keep an identical key structure (enforced
by `tests/test_translations.py` and `tests/test_entity_translation_keys.py`). Add a
key to all three at once. Use plain text: no emoji, no long dashes.

## Running the tests

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- **Smart attribute mapping** — device-specific attribute keys extracted from real diagnostics
- **Full Lovelace support** — integrates seamlessly with Home Assistant UI and automations
- **Two-factor authentication (2FA)** — Two-factor authentication during the login process is supported
- **Multilingual integration** — Currently available in Italian and English, with additional languages available upon request.
- **Multilingual integration** — Currently available in Italian, English, French, Portuguese and Brazilian Portuguese, with additional languages available upon request.

## Installation

Expand Down
34 changes: 34 additions & 0 deletions custom_components/addhon/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,40 @@ the notes were generated automatically carry a link to their diff instead of a s

**Changes**

- **The Laundry Centre is supported, read-only** (#124): a Haier washer and dryer under one
appliance is set up as one device with a Washer and a Dryer child device. Sensors: state,
remaining time, programme name, phase, errors, totals and energy; binary sensors: remote
control, door, lock, pause, auto detergent, auto softener, dryer anti-crease time. No
commands yet.
- **The programme name follows the cycle the cloud describes** (#130): a cycle started on the
panel is named exactly, a favourite is named as the favourite, a shared code resolves to
its dashboard programme, and the name stays after the end while the machine keeps the
code. A push that starts or ends a cycle triggers a context read a few seconds later, so
the name and the options follow within seconds instead of at the next poll.
- **At rest, the programme select shows the programme Start would send** (#130), the
selected or last recovered one, no longer the code the idle machine reports; during a
washer's end-of-cycle tumbling it keeps the cycle's programme. An automation that reads
the select while the machine is idle may see a different value than before.
- **A cycle started on the panel points the active programme at the cycle the machine
runs** (#138): the option selects show that programme's lists and values during the
cycle, and a Start from Home Assistant without reselecting sends that programme. The
diagnostics file records it as `panel`.
- **New anti-crease and Best Ironing switches and a drying time select on tumble dryers**
(#142), all disabled by default: enable them by hand in the entity settings. Anti-crease
and Best Ironing exclude each other, as in the official app; Best Ironing sets the dry
level to Iron dry and gives the programme's own level back when switched off. A drying
time sends dry level 0, and a level chosen afterwards sends drying time 0, exactly the
pair the app sends; the time select reads unknown while the programme dries to a level.
- **Climate and water heater expose the `native_*` temperature properties beside the old
names** (#144): the deprecation warnings of Home Assistant 2026.11 disappear, the values
do not change.
- **French translation** (#143).
- **A statistics answer carrying an error body is discarded and the last statistics kept**
(#138): the cloud answered the statistics service with a 200 that mixed an error with
stale values at alternate polls, and the washes counter swung every minute. The
diagnostics file says `rejected` and the cycle timeline gets a row.
- **The message after a command that could not be refreshed now says the refresh failed,
not the command.**
- **Washers, washer-dryers, dryers and dishwashers read their statistics from the endpoint
the official app uses** (#138): `/commands/v2/statistics` is tried first and, when it
fails or answers nothing, the previous `/commands/v1/statistics` answers instead until
Expand Down
63 changes: 60 additions & 3 deletions custom_components/addhon/client/engine/appliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,34 @@
"temperatureUsage": (dict,),
"loadingPercentage": (list,),
}
# A v2 answer carrying one of these with a value is an error body, whatever else it
# carries: on 2026-11-08 a beta5 dump of an HQD washer showed the cloud answering a 200
# that mixed `errorMessage`/`errorType`/`requestId` with stale statistics (a counter two
# behind, `loadingPercentage` dated at midnight, no `resultCode`, no cleaning maps) at
# every other poll for two hours, and the shape check let it through: the washes counter
# swung every minute. Such an answer is discarded and the last good one kept; the
# version does not change (the next poll asks v2 again).
_STATISTICS_ERROR_KEYS = ("errorMessage", "errorType")


def _statistics_error(answer: Mapping[str, Any]) -> Optional[str]:
"""Why `answer` is an error body and not the statistics, None when it is not: its
`errorType` when that is a bare name the dump can print, `error` otherwise.

A null, empty or blank error field says nothing (review of PR #146): an answer
carrying only those is the statistics. The name is capped at the 64 characters
`diagnostics._statistics_reason` prints, so the dump and the cycle log agree."""
if all(_blank(answer.get(key)) for key in _STATISTICS_ERROR_KEYS):
return None
kind = answer.get("errorType")
if isinstance(kind, str) and kind.isidentifier() and len(kind) <= 64:
return kind
return "error"


def _blank(value: Any) -> bool:
"""Whether an error field carries nothing: None, or a string of only whitespace."""
return value is None or (isinstance(value, str) and not value.strip())


def _statistics_shaped(answer: Mapping[str, Any]) -> bool:
Expand Down Expand Up @@ -196,6 +224,10 @@ def __init__(
# Which statistics endpoint answered last and why v1 did, for the dump
# (`statistics_source`); None before the first read. A fallback is sticky.
self._statistics_source: Optional[dict[str, Any]] = None
# The last v2 answer taken, as it came: what a poll whose v2 answer is an error
# body gets instead (`_read_statistics`); a copy, the merge writes into the one
# returned.
self._statistics_kept: dict[str, Any] = {}
self._statistics_v1_only = False
self._attributes: dict[str, Any] = {}
self._zone = zone
Expand Down Expand Up @@ -412,8 +444,10 @@ def adopt_pushed_parameter(self, name: str, data: Mapping[str, Any]) -> HonAttri
@property
def statistics_source(self) -> Optional[dict[str, Any]]:
"""`{"version": "v2" | "v1", "fallback": None | reason}` of the last statistics
read (issue #138): the reason is `"empty"` or the class name of what v2 raised.
None before the first read. Read by the diagnostics dump only."""
read (issue #138): the reason is `"empty"`, `"shape"` or the class name of what
v2 raised. A v2 answer discarded as an error body adds `"rejected"`, its
`errorType` or `"error"`, until the next answer taken. None before the first
read. Read by the diagnostics dump only."""
return self._statistics_source

@property
Expand Down Expand Up @@ -1269,7 +1303,13 @@ async def _read_statistics(self) -> dict[str, Any]:
v2 is taken when it answers a map carrying at least one of the keys the app
reads (`STATISTICS_KEYS`); an error, an empty answer or another shape falls
back to v1 for good (`_statistics_v1_only`) and is named in
`statistics_source` (`empty`, `shape`, or the error's class name). An API without `load_statistics_v2` reads v1.
`statistics_source` (`empty`, `shape`, or the error's class name). A map that
carries `errorMessage` or `errorType` with a value is an error body the cloud
answered as a 200 (seen mixed with stale statistics at alternate polls, dump of
2026-11-08): it is discarded, the last v2 answer taken is handed back ({} before
one), the version stays v2, `statistics_source` says `rejected` and the cycle
log gets a row. Checked before the shape. An API without `load_statistics_v2`
reads v1.
"""
read_v2 = getattr(self.api, "load_statistics_v2", None)
if (
Expand All @@ -1284,8 +1324,25 @@ async def _read_statistics(self) -> dict[str, Any]:
fallback = type(error).__name__
else:
if isinstance(answer, dict) and answer:
rejected = _statistics_error(answer)
if rejected is not None:
_LOGGER.debug(
"Statistics v2 answered an error body for %s (%s): kept the last",
self.appliance_type,
rejected,
)
self._statistics_source = {
"version": "v2", "fallback": None, "rejected": rejected,
}
if self._cycle_log is not None:
try:
self._cycle_log.statistics_rejected(reason=rejected)
except Exception: # noqa: BLE001 - the log must never cost the poll
_LOGGER.debug("Cycle log failed", exc_info=True)
return dict(self._statistics_kept)
if _statistics_shaped(answer):
self._statistics_source = {"version": "v2", "fallback": None}
self._statistics_kept = dict(answer)
return answer
fallback = "shape"
else:
Expand Down
12 changes: 11 additions & 1 deletion custom_components/addhon/client/engine/cycle_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
- `statistics`: what a poll's `/statistics` added or moved since the last one: the rows of
`loadingPercentage` it did not hold (the load measured and suggested, the start date of
one cycle each) and the scalars that changed, a map's own one level down
(`temperatureUsage.temp40`); the first read of an appliance object only seeds;
(`temperatureUsage.temp40`); the first read of an appliance object only seeds; or a
v2 answer discarded as an error body (`rejected`, its `errorType`), the statistics
held unchanged;
- `entity`: a state one of the entities that show a cycle's options, phase, programme or
machine state published (`key`, the unique_id's suffix), `unknown` and `unavailable`
kept as the text they are; Home Assistant's listener feeds it (`__init__.py`);
Expand Down Expand Up @@ -577,6 +579,14 @@ def statistics(
with self._lock:
self._append("statistics", now, **fields)

def statistics_rejected(self, *, reason: str) -> None:
"""A poll whose `/statistics` answer was an error body and was discarded, the
statistics held unchanged: `reason` is its `errorType` or `error`."""
now = self._clock()
fields = {"rejected": _text(reason)}
with self._lock:
self._append("statistics", now, **fields)

def entity(self, *, key: str, old: str | None, new: str | None) -> None:
"""A state an entity published: `key` names it by its unique_id's suffix."""
now = self._clock()
Expand Down
29 changes: 19 additions & 10 deletions custom_components/addhon/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,10 @@ def _log_token(allowed: frozenset):
"edge": _log_token(_CYCLE_LOG_EDGES), "asked_at": _log_cloud, "reads": _log_reads,
"outcome": _log_token(_CYCLE_LOG_OUTCOMES),
},
"statistics": {"new_rows": _log_loads, "changed": _log_changes, "truncated": _log_int},
"statistics": {
"new_rows": _log_loads, "changed": _log_changes, "truncated": _log_int,
"rejected": _log_text,
},
# A state is text the user can have written (a favourite's name on `program_name`):
# bounded here, masked with the block by `_mask_favourites`.
"entity": {"key": _log_text, "before": _log_text, "after": _log_text},
Expand Down Expand Up @@ -1582,21 +1585,27 @@ def _log_phases(events) -> list:
def _statistics_source(appliance) -> dict | None:
"""`{version, fallback}` of the last statistics read (`HonAppliance.statistics_source`,
issue #138), rebuilt: the version only from the two the engine writes, the fallback
only as `empty` or a bare exception class name; anything else prints as null. None
for an engine without the property or before its first read."""
only as `empty`, `shape` or a bare exception class name; anything else prints as
null. `rejected`, printed only when the engine wrote it (a v2 error body discarded),
takes the same rule as the fallback. None for an engine without the property or
before its first read."""
source = getattr(appliance, "statistics_source", None)
if not isinstance(source, Mapping):
return None
version = source.get("version")
fallback = source.get("fallback")
return {
printed = {
"version": version if type(version) is str and version in _STATISTICS_VERSIONS else None,
"fallback": (
fallback
if type(fallback) is str and fallback.isidentifier() and len(fallback) <= 64
else None
),
"fallback": _statistics_reason(source.get("fallback")),
}
if "rejected" in source:
printed["rejected"] = _statistics_reason(source.get("rejected"))
return printed


def _statistics_reason(reason) -> str | None:
"""A fallback or rejection reason as the dump prints it: a bare name of at most 64
characters, null otherwise."""
return reason if type(reason) is str and reason.isidentifier() and len(reason) <= 64 else None


def _cycle_log_section(appliance) -> dict | None:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/addhon/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"requirements": [
"awsiotsdk>=1.21.0"
],
"version": "5.29.0-beta5"
"version": "5.29.0"
}
4 changes: 2 additions & 2 deletions custom_components/addhon/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -1448,10 +1448,10 @@
"message": "The purifier must be confirmed running to change this."
},
"refresh_after_command_failed": {
"message": "Refresh after the command failed."
"message": "Could not refresh the data after the command."
},
"refresh_after_command_failed_error": {
"message": "Refresh after the command failed: {error}"
"message": "Could not refresh the data after the command: {error}"
},
"swing_not_supported": {
"message": "This device does not support vertical swing."
Expand Down
4 changes: 2 additions & 2 deletions custom_components/addhon/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1448,10 +1448,10 @@
"message": "The purifier must be confirmed running to change this."
},
"refresh_after_command_failed": {
"message": "Refresh after the command failed."
"message": "Could not refresh the data after the command."
},
"refresh_after_command_failed_error": {
"message": "Refresh after the command failed: {error}"
"message": "Could not refresh the data after the command: {error}"
},
"swing_not_supported": {
"message": "This device does not support vertical swing."
Expand Down
Loading
Loading