Skip to content

Add method to check if device has smarthome capabilities - #134

Merged
mib1185 merged 1 commit into
hthiery:masterfrom
mib1185:add-check-method-if-device-is-smarthome-capable
Sep 21, 2026
Merged

mib1185 merged 1 commit into
hthiery:masterfrom
mib1185:add-check-method-if-device-is-smarthome-capable

Conversation

@mib1185

@mib1185 mib1185 commented Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator

Add has_smarthome_capabilities() to Fritzhome

Checks whether a device supports smart home functionality: first via the TR-064 tr64desc.xml description (X_AVM-DE_Homeauto service), falling back to rest_api_desc.json (/smarthome endpoint) if that fails. Returns True/False, or None if neither could be determined.

Includes fixtures and tests for all paths (found, not found, fallback, failure).

@coveralls

coveralls commented Sep 18, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 96.976% (+0.07%) from 96.909% — mib1185:add-check-method-if-device-is-smarthome-capable into hthiery:master

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new capability check currently hard-codes http://{host} and drops the configured scheme/port from base_url, which can break HTTPS/custom-port configurations.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR adds a new Fritzhome.has_smarthome_capabilities() helper to detect whether a FRITZ!Box exposes smart home functionality by probing the TR-064 device description with a REST API fallback, along with tests and fixtures to validate the behavior.

Changes:

  • Added Fritzhome.has_smarthome_capabilities() to detect smart home support via TR-064 and REST description probing.
  • Added unit tests and new XML/JSON response fixtures for supported/unsupported and error/fallback scenarios.
  • Extended tests.Helper.response() to load fixtures by extension (XML/JSON).
File summaries
File Description
pyfritzhome/fritzhome.py Adds has_smarthome_capabilities() implementation and supporting imports.
tests/test_fritzhome.py Adds coverage for TR-064 detection, REST fallback, and error/parse-failure cases.
tests/helper.py Updates fixture loader to support non-XML fixtures via an extension parameter.
tests/responses/tr64desc.xml New TR-064 fixture including X_AVM-DE_Homeauto service.
tests/responses/tr64desc_no_homeauto.xml New TR-064 fixture without X_AVM-DE_Homeauto service.
tests/responses/rest_api_desc.json New REST description fixture including /smarthome endpoints.
tests/responses/rest_api_desc_no_smarthome.json New REST description fixture without /smarthome endpoints.
Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pyfritzhome/fritzhome.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

There is a concrete robustness issue in REST JSON shape handling (can raise AttributeError instead of returning None) and the encoding cookie placement is broken by the new blank line.

Review details

Suppressed comments (2)

Previously missed (2) — in code that hasn't changed since the last review.

pyfritzhome/fritzhome.py:112

  • json.loads(plain).get(...) and the subsequent endpoint.get(...) assume the REST API description is a dict with an endpoints list of dicts. If the response is valid JSON but has an unexpected shape (e.g., list at the top level), this will raise AttributeError and break the method instead of returning None per the docstring.
    pyfritzhome/fritzhome.py:5
  • The UTF-8 coding cookie must be on the first or second line (PEP 263). The newly added blank line pushes # -*- coding: utf-8 -*- to line 3, so it will be ignored by the interpreter.
  • Files reviewed: 7/7 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The REST fallback can misclassify capability as unsupported when "endpoints" is an iterable non-list (e.g., a dict), returning False instead of None for an indeterminate/invalid schema.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread pyfritzhome/fritzhome.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The added blank line at the top of pyfritzhome/fritzhome.py makes the UTF-8 encoding cookie invalid per PEP 263 and should be corrected.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

pyfritzhome/fritzhome.py:4

  • The encoding cookie must be on the first or second line (PEP 263). The added blank line pushes # -*- coding: utf-8 -*- to line 3, which makes it ineffective (and can break Python 2 parsing if non-ASCII is ever introduced). Move the encoding cookie up to line 2 or remove it entirely.
  • Files reviewed: 7/7 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation matches the stated behavior and the added tests/fixtures cover the expected success, fallback, and failure cases (including IPv6).

Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@mib1185
mib1185 force-pushed the add-check-method-if-device-is-smarthome-capable branch from 7410bdb to 74d2a58 Compare September 18, 2026 16:21
Co-authored-by: Copilot copilot@github.com

ensure correct IPv6 handling

Co-authored-by: Copilot <copilot@github.com>

fetch unexpected JSON response

Co-authored-by: Copilot <copilot@github.com>

apply code review
@mib1185
mib1185 force-pushed the add-check-method-if-device-is-smarthome-capable branch from 74d2a58 to 966130a Compare September 18, 2026 16:24
@mib1185
mib1185 merged commit 629d385 into hthiery:master Sep 21, 2026
12 checks passed
@mib1185
mib1185 deleted the add-check-method-if-device-is-smarthome-capable branch September 21, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants