Skip to content

Type the characteristic writes as HAP JSON - #550

Merged
ikalchev merged 3 commits into
ikalchev:devfrom
RaHehl:type-characteristic-writes
Nov 10, 2026
Merged

ikalchev merged 3 commits into
ikalchev:devfrom
RaHehl:type-characteristic-writes

Conversation

@RaHehl

@RaHehl RaHehl commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Follow-up to the review of #536, which went in with #537: the write queries were typed as dict[str, Any].

CharacteristicWrite is a TypedDict for one characteristic of a PUT /characteristics request, next to HAPValue in pyhap.characteristic. aid and iid are always present, value, ev and r are optional. _run_characteristic_writes and _notify use it. Typing only, no behaviour change.

AI use: written with the help of an AI coding assistant (Opus 5.5). I reviewed and tested the changes myself (pytest, ruff, ty).

A TypedDict instead of dict[str, Any] for one characteristic of a write,
with aid and iid always present and value, ev and r optional.
@codecov

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.79%. Comparing base (6818241) to head (555775a).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #550      +/-   ##
==========================================
+ Coverage   91.77%   91.79%   +0.01%     
==========================================
  Files          27       27              
  Lines        4367     4376       +9     
  Branches      558      558              
==========================================
+ Hits         4008     4017       +9     
  Misses        251      251              
  Partials      108      108              
Files with missing lines Coverage Δ
pyhap/accessory_driver.py 93.75% <100.00%> (ø)
pyhap/characteristic.py 97.96% <100.00%> (+0.07%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread pyhap/characteristic.py
iid: int


class CharacteristicWrite(_CharacteristicWriteTarget, total=False):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

TIL that you can pass total to control if fields are opt or not. 👍

@ikalchev
ikalchev merged commit a7058ee into ikalchev:dev Nov 10, 2026
7 checks passed
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.

2 participants