Skip to content

zetime: command envelope + battery decode - #47

Merged
abdulsaheel merged 4 commits into
mainfrom
feat/zetime-protocol
Sep 5, 2026
Merged

zetime: command envelope + battery decode#47
abdulsaheel merged 4 commits into
mainfrom
feat/zetime-protocol

Conversation

@abdulsaheel

@abdulsaheel abdulsaheel commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

mykronoz zetime frame codec. preamble/cmd/action/len/end envelope plus a battery-level reply decode. pairs-only groundwork, no history/step/sleep/hr commands touched here.

Summary by Sourcery

Add initial MyKronoz ZeTime framing and battery decoding support.

New Features:

  • Add ZeTime protocol support for constructing command requests and decoding battery-level replies.
  • Export the ZeTime codec through the package's public library barrel.

Enhancements:

  • Validate ZeTime frame structure and reject malformed or incomplete messages.

Tests:

  • Add coverage for request framing, battery decoding, and malformed frame rejection.

pairs-only groundwork for mykronoz zetime. frame codec (preamble/cmd/action/
len/end) plus a battery-level reply decode. no history/step/sleep/hr
commands touched.
@sourcery-ai

sourcery-ai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Reviewer's Guide

Introduces a publicly exported, pairs-only ZeTime codec for fixed command envelopes and battery replies, with strict framing validation and focused layout-based tests; history, steps, sleep, and heart-rate commands remain intentionally out of scope.

Sequence diagram for ZeTime battery request and reply

sequenceDiagram
    participant Host
    participant ZeTime
    Host->>ZeTime: zetimeRequestFrame(kZeTimeCmdBattery)
    ZeTime-->>Host: notify value
    Host->>Host: parseZeTimeFrame(value)
    alt valid battery frame
        Host->>Host: zetimeBatteryLevel(frame)
        Host-->>Host: battery level 0-100
    else malformed or non-battery frame
        Host-->>Host: null
    end
Loading

Flow diagram for ZeTime frame validation and battery decode

flowchart TD
    A[Notify characteristic value] --> B{"parseZeTimeFrame(value)"}
    B -->|invalid length, preamble, payload size, or end byte| C[Drop frame]
    B -->|valid envelope| D[ZeTimeFrame]
    D --> E{"zetimeBatteryLevel(frame)"}
    E -->|battery command with payload| F[Battery level from payload byte]
    E -->|other command or empty payload| G[No battery level]
Loading

File-Level Changes

Change Details Files
Adds a public ZeTime protocol module that constructs request envelopes, strictly parses complete notify frames, and extracts battery levels.
  • Defines ZeTime framing, action, acknowledgement, and battery command constants.
  • Builds the documented seven-byte request shape with the fixed declared length and end marker.
  • Validates preamble, nonzero declared length, exact frame size, and end marker before returning a decoded frame.
  • Exposes battery extraction only for battery-command replies, leaving unverified health-history commands unsupported.
lib/src/zetime.dart
Makes the ZeTime codec available through the package API and verifies its wire-layout behavior.
  • Exports the new ZeTime module from the package barrel.
  • Tests request construction, battery decoding, non-battery filtering, and malformed-frame rejection.
lib/openstrap_protocol.dart
test/zetime_test.dart

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 58 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: e6e38ef1-6395-4983-af98-97c4c9a8cbf4

📥 Commits

Reviewing files that changed from the base of the PR and between c78c176 and db18584.

📒 Files selected for processing (3)
  • lib/openstrap_protocol.dart
  • lib/src/zetime.dart
  • test/zetime_test.dart

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 @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai Bot 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.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="lib/src/zetime.dart" line_range="90" />
<code_context>
+/// Battery level, 0-100, from a battery-command reply. Null when [f] is not a
+/// battery reply or carries no level byte.
+int? zetimeBatteryLevel(ZeTimeFrame f) =>
+    f.cmd == kZeTimeCmdBattery && f.payload.isNotEmpty ? f.payload[0] : null;
</code_context>
<issue_to_address>
**issue (bug_risk):** zetimeBatteryLevel returns any payload byte as a battery percentage, including impossible values such as 101 or 255, despite documenting the result as 0-100. A malformed or misidentified reply therefore produces an invalid battery reading instead of null.

**Triggers:** When a battery-command frame carries an out-of-range level byte.

**Suggested fix:** Return the byte only when it is between 0 and 100 inclusive; otherwise return null.

```suggestion
    f.cmd == kZeTimeCmdBattery &&
            f.payload.isNotEmpty &&
            f.payload[0] >= 0 &&
            f.payload[0] <= 100
        ? f.payload[0]
        : null;
```
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: lib/src/zetime.dart:90


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread lib/src/zetime.dart Outdated
a misidentified or malformed reply could otherwise report an impossible
percentage instead of nothing.

@sourcery-ai sourcery-ai Bot 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.

Sourcery assessment

Approved.

@abdulsaheel
abdulsaheel merged commit b8430e4 into main Sep 5, 2026
1 check was pending
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.

1 participant