zetime: command envelope + battery decode - #47
Conversation
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.
Reviewer's GuideIntroduces 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 replysequenceDiagram
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
Flow diagram for ZeTime frame validation and battery decodeflowchart 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]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Warning Review limit reachedNext included review available in 58 minutes. View limit detailsLimit 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. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Team Run ID: 📒 Files selected for processing (3)
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. Comment |
There was a problem hiding this comment.
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
a misidentified or malformed reply could otherwise report an impossible percentage instead of nothing.
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:
Enhancements:
Tests: