Skip to content

fix: log skipped discovery entities with context instead of a blank ERROR - #180

Merged
KJonline merged 2 commits into
Pyhass:devfrom
matt-thepie:fix/blank-discovery-error-log
Oct 22, 2026
Merged

KJonline merged 2 commits into
Pyhass:devfrom
matt-thepie:fix/blank-discovery-error-log

Conversation

@matt-thepie

Copy link
Copy Markdown
Contributor

Problem

home-assistant/core#172819 reports two ERROR entries at Hive setup, one of them completely blank:

Logger: apyhiveapi.session
Source: components/hive/__init__.py:40
(blank)

Logger: apyhiveapi.helper.hive_helper
getDeviceData - No TRVs found for product xxxxxxxx-...

For a trvcontrol product whose props.trvs list is empty, HiveHelper.get_device_data logged an ERROR and then raised a bare KeyError. DiscoveryMixin.add_list caught it and called _LOGGER.error(error). str(KeyError()) is an empty string, so the second entry had no text. The same blank entry appears for any other KeyError without a message, such as a product whose parent device is missing.

The source line in the report points at Home Assistant's setup call in homeassistant/components/hive/__init__.py:

devices = await hive.session.startSession(hive_config)

Fix

  • get_device_data raises KeyError("no TRVs linked to trvcontrol product <id>") and no longer logs, so the skip is reported once.
  • add_list logs one WARNING with the entity type, the Hive product type and id, and the missing key. It falls back to unknown key for a bare KeyError.

Example:

WARNING apyhiveapi.session.discovery: Skipping climate entity for Hive trvcontrol 1234...: missing data (no TRVs linked to trvcontrol product 1234...)

The level drops from ERROR to WARNING. The integration keeps working and only the affected entity is skipped, which matches Home Assistant's guidance for recoverable data problems.

Verification

  • New tests in tests/unit/test_discovery.py cover a bare KeyError, a KeyError with a message, and product data with no id or type. tests/unit/test_helpers.py now checks the message and that the helper logs nothing at ERROR.
  • Full suite: 1067 passed, 100% coverage. ruff, mypy, pylint 10/10 and detect-secrets clean.
  • Live start_session against a real account with 8 heating and TRV zones: same 73 entities as before, no WARNING or ERROR lines.

Home Assistant impact

No API, return-shape or exception change. add_list still returns None for a skipped entity and start_session returns the same device_list. Only the log level and text change.

🤖 Generated with Claude Code

…RROR

add_list caught KeyError and called _LOGGER.error(error). For a
trvcontrol product with no linked TRVs, get_device_data logged its own
ERROR and then raised a bare KeyError, whose str() is empty, so Home
Assistant showed a second, blank ERROR entry.

get_device_data now raises KeyError with a message and no longer logs,
and add_list logs one WARNING naming the entity type, Hive product type
and id, and the missing key.

Fixes home-assistant/core#172819

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (dev@0294877). Learn more about missing BASE report.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff           @@
##             dev     #180   +/-   ##
======================================
  Coverage       ?   99.96%           
======================================
  Files          ?       30           
  Lines          ?     2643           
  Branches       ?      310           
======================================
  Hits           ?     2642           
  Misses         ?        0           
  Partials       ?        1           
Flag Coverage Δ
unittests 99.96% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/helper/hive_helper.py 100.00% <100.00%> (ø)
src/session/discovery.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KJonline KJonline added the claude-review Run Claude code review on this PR (required for fork PRs) label Oct 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Claude Code Review

Looks good: no bugs found. The PR fixes the blank log entry from a bare KeyError.

Bugs: none.

Minor

  • add_list now logs a skipped entity at WARNING instead of ERROR. That seems reasonable, since the entity is skipped and setup carries on. It does mean anyone filtering on ERROR will no longer see these skips.
  • The log line includes the Hive product/device id. That is an opaque id rather than PII, and the payload itself is not logged, so it is acceptable under the logging rule.

Checked

  • get_device_data has one caller, add_list, which catches the KeyError. Dropping the helper's own _LOGGER.error therefore loses nothing: the caller still logs, now once and with context.
  • The new tests cover the bare KeyError, a KeyError with a message, and data with no id or type. They also cover the helper no longer logging an ERROR. I did not run the suite. Codecov reports the changed lines as covered.

Home Assistant check: I did not fetch the Home Assistant files. Home Assistant only reads device_list and device.status, and this change touches neither the skip behaviour nor any public API. No exception types, aliases or return shapes change. The only effect on Home Assistant is the log level and message when an entity is skipped.

Not reviewed: I did not run the test suite or linters.


Automated review by Claude Code · workflow run

@KJonline
KJonline merged commit 729fc16 into Pyhass:dev Oct 22, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude-review Run Claude code review on this PR (required for fork PRs)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants