Skip to content

Add internal schedule control for Plugwise Circle(+) and Stealth devices - #517

Merged
bouwew merged 5 commits into
plugwise:mainfrom
blb4github:feature/internal-schedule-control
Dec 5, 2026
Merged

bouwew merged 5 commits into
plugwise:mainfrom
blb4github:feature/internal-schedule-control

Conversation

@blb4github

@blb4github blb4github commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Addresses #516. This adds an explicit API to enable or disable an existing
on-device schedule while preserving its contents.

Circle and Stealth devices, including their coordinator variants, advertise
NodeFeature.SCHEDULE_CONTROL when their firmware supports protocol 2.0.
Call await node.set_schedule_enabled(enabled) to control the schedule.

The library sends request 0040 with 0101 to enable or 0001 to disable.
It validates the matching MAC address, sequence and node acknowledgement
(00E4 or 00E5), then attempts a fresh relay read. The API returns the
requested setting after the matching acknowledgement. The protocol messages
and firmware tested did not expose a reliable way to read the current schedule
state, so the capability is exposed as an action.

Schedule transactions serialize per node through all attempts and the relay
refresh. This prevents an earlier enable retry from following a later
confirmed disable. Cancellation while waiting drops the queued action.
An in-flight transaction finishes before cancellation propagates. Other nodes
and regular polling continue through the existing USB queue.

Validation

  • All 57 library tests passed on Python 3.14.10. Simulated responses cover
    enable and disable on Circle, Circle+, Stealth, Stealth+ and Stealth M+,
    as well as firmware gating, retry ordering, cancellation, terminal timeout,
    relay refresh and independent operation of different nodes.
  • An integrated physical test on Home Assistant Core 2026.11.3 confirmed
    8 enables and 10 disables across a Circle and Circle+. All succeeded on the
    first attempt. The trace captured 17 of 18 relay readbacks, and both devices
    ended with a confirmed disable.
  • The hardware trace confirmed command order on the wire. The hardware retest
    did not encounter a timeout or independently establish service-call overlap.
    Stealth variants were tested in simulation. Autonomous relay switching at a
    known scheduled time, persistence across a device power cycle and live
    schedule-state readback remain unverified.

See the protocol findings and validation details
and the hardware retest procedure.

@blb4github
blb4github requested a review from a team as a code owner December 2, 2026 14:54
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 22a3a8b8-112a-419f-9ebd-c4969aec1ffd
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Comment thread plugwise_usb/nodes/circle.py Outdated
Comment on lines +1022 to +1034
def _setup_circle_protocol(
self,
firmware: dict[datetime, SupportedVersions],
features: tuple[NodeFeature, ...],
) -> None:
"""Set up features for Circles and related hardware."""
# A Stealth+ shares the Circle+ node type. Require an identified Circle model.
hardware_model = HW_MODELS.get(self._node_info.version or "", "")
if self.node_type in (NodeType.CIRCLE, NodeType.CIRCLE_PLUS) and (
hardware_model == "Circle" or hardware_model.startswith("Circle ")
):
features += (NodeFeature.SCHEDULE_CONTROL,)
self._setup_protocol(firmware, features)

@bouwew bouwew Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this bit of code is required when you add the NodeFeature.SCHEDULE_CONTROL to the CIRCLE_FEATURES constant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think this bit of code is required when you add the NodeFeature.SCHEDULE_CONTROL to the CIRCLE_FEATURES constant.

I added this check because PlugwiseStealth inherits the Circle setup and Stealth+ shares the Circle+ node type. Adding SCHEDULE_CONTROL directly to the shared feature lists would also expose it on those models. I’ve only verified schedule control on Circle and Circle+. Is there an existing model-specific feature check I could reuse here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Circles and Stealths share the same functions so no need to limit this functionality to Circles only.

@bouwew bouwew Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@blb4github please implement the above suggestion: add the NodeFeature.SCHEDULE_CONTROL to the CIRCLE_FEATURES constant, remove the _setup_circle_protocol() change.

And fully remove the update of the get_state() function shown below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@bouwew, I’ve addressed your feedback in 5d3af93. SCHEDULE_CONTROL now uses the existing feature lists for Circle and Stealth devices, including the coordinator variants. I removed _setup_circle_protocol() and the schedule-specific handling in get_state(). All 57 tests passed. Could you take another look?

Comment thread plugwise_usb/nodes/circle.py Outdated
self, features: tuple[NodeFeature, ...]
) -> dict[NodeFeature, Any]:
"""Update latest state for given feature."""
if NodeFeature.SCHEDULE_CONTROL in features:

@bouwew bouwew Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You don't want to store the state of this feature?

This depends on how it's implemented in the custom_component.
I'm thinking of a schedule_enabled switch: enabled = schedule enabled, disabled = schedule disabled.
If you agree, just add to the existing match-feature-case construct.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A switch would make sense if we could read the current schedule state from the device. I have done an attempt to find the state but in my tests, 36 Node Information replies and 36 Clock Information replies showed no reproducible change after enabling or disabling the schedule. The device acknowledges the command, so the only value we could store today is the last acknowledged setting. After a restart, that could give Home Assistant a misleading state.

That’s why the companion integration uses two configuration buttons, Enable internal schedule and Disable internal schedule, and treats SCHEDULE_CONTROL as an action-only capability. Do you know of a command or response field that reports the current schedule state? If so, I’d be happy to test it on my Circle and Circle+.

@bouwew bouwew Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Now that I've slept on it, I realize that too, a getter-function is required for what I have in mind.
I've found a way to look inside the Source windows files, I'll have a look to see if such a getter-function exists.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would suggest to fully remove this code-change-chunk, the feature will be ignored because there is no match-case entry for the new feature.

@bouwew

bouwew commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

@blb4github Very nice addition! Please see my feedback below 🙂

Hmm, only two comments are shown here, I added 3. I would suggest you read them in the Files changed view.

@bouwew bouwew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the update can be simplified somewhat, please see my comments.

@blb4github

Copy link
Copy Markdown
Contributor Author

@blb4github Very nice addition! Please see my feedback below 🙂

Hmm, only two comments are shown here, I added 3. I would suggest you read them in the Files changed view.

I checked the Files changed view too. I can see the comments about CIRCLE_FEATURES and the proposed schedule_enabled switch but not a third one, sorry. Could you send me the permalink to the third comment, or repost it?

Comment thread plugwise_usb/nodes/circle.py Resolved
@bouwew

bouwew commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Sorry, I forget to finish that comment, it's visible now 🙂

@bouwew

bouwew commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

@blb4github I've looked in the Source files, I could not find anything on how to see if a Circle has a schedule enabled, or not.
The 0040 request is there, and also some other request that are listed as todo in the requests.py file. But there are more related to the contents of a schedule it looks like.

Do you remember if there is something in Source that shows this?
If yes, we could enable debugging to capture the communication.

If not, then I will need to retract my comment on the name with enabled. set_schedule_enabled is then suitable.

Also, my comment on getting the state is then not correct.

My comment on _setup_circle_protocol still stands, a Stealth is a Circle in a different form-factor, they can be present in a schedule just like any Circle.

Advertise schedule control through normal firmware capability setup for
Circle and Stealth families. Restore the standard state polling path and
cover hardware variants and firmware gating with simulated responses.
@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

@blb4github blb4github changed the title Add internal schedule control for Plugwise Circle and Circle+ Add internal schedule control for Plugwise Circle(+) and Stealth devices Dec 4, 2026

@bouwew bouwew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved after addressing the comments, thanks!

@bouwew
bouwew merged commit 2df17f6 into plugwise:main Dec 5, 2026
4 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Dec 5, 2026

This branch was successfully deployed

1 active deployment
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