Skip to content

Add Adaptive Lighting transition codec and interpolator - #588

Open
xDhii wants to merge 2 commits into
ikalchev:devfrom
xDhii:adaptive-lighting-codec
Open

xDhii wants to merge 2 commits into
ikalchev:devfrom
xDhii:adaptive-lighting-codec

Conversation

@xDhii

@xDhii xDhii commented Dec 1, 2026 •

Copy link
Copy Markdown

Part of #495. This is the first of two PRs: the protocol side of Adaptive Lighting, with no controller wiring yet.

What it adds

  • pyhap.tlv.decode_ordered: a TLV8 decode that keeps record order, duplicates and empty records. The Adaptive Lighting curve repeats the same tag separated by empty records, which decode() collapses into a dict.
  • pyhap.adaptive_lighting: parsing of the TransitionControl write (curve points, update interval, notify threshold, multiplier range), interpolation of colour temperature and the brightness adjustment factor at a given time (including the duration hold), and to_dict/from_dict so a consumer can persist an active transition. The clock is injectable.
  • A docs page and 25 tests, including a real schedule written by the Home app (42 points over 24 hours), curve end, hold windows and malformed writes.

Not in this PR

The controller that wires this to a Lightbulb service, schedules the updates and persists state. It follows as a second PR once the shape here is agreed.

Where it comes from

The logic is ported from my Home Assistant HomeKit bridge change (home-assistant/core#182265), which has been driving real lights for weeks, with a few extra guards against malformed payloads. Together with the controller in the follow-up PR, this port has been running in my own Home Assistant since December 1st, driving real lights, without errors.

The full test suite and ruff check/ruff format pass locally.

I used AI assistance (Devin and Claude) to port and test this.

devin-ai-integration Bot and others added 2 commits December 1, 2026 14:33
First step towards a reusable AdaptiveLightingController (issue ikalchev#495):
decode the TransitionControl TLV8 schedule the Home app writes, expose
the parsed curve and interpolate the current colour temperature and
brightness factor at any moment, and serialise the state so a consumer
can persist it. No controller or HomeKit service wiring yet.

- pyhap.tlv.decode_ordered: TLV8 decode preserving record order,
  duplicates and empty records (used as list delimiters), rejoining
  255-byte chunks
- pyhap.adaptive_lighting: variable-width uint codec, TLV helpers,
  CurveEntry/ActiveTransition model, parse_transition_control /
  parse_transition_update with injectable clock, interpolate /
  interpolate_point with hold-duration and brightness-factor
  interpolation, ActiveTransition.to_dict/from_dict
- tests cover the real Home app payload, curve end, hold windows,
  brightness factor smoothness, malformed writes and state roundtrip

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parse_transition_update now looks up the configuration record by its
TAG_CFG_IID tag instead of assuming it is the first record, so updates
carrying extra records still parse. decode_ordered documents that
rejoining same-tag chunks is a heuristic bounded by the 255-byte
length rule and its inherent ambiguity.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@xDhii
xDhii marked this pull request as ready for review December 2, 2026 03:46
Copilot AI balanced review requested due to automatic review settings December 2, 2026 03:46

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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