Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/src/huami_legacy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,18 @@ const int kHuamiMaxFetchCount = 129600;
if (count > kHuamiMaxFetchCount) return null;
if (b.length < 15) return null;
final tz = b[14] >= 0x80 ? b[14] - 0x100 : b[14];
final wall = DateTime.utc(b[7] | (b[8] << 8), b[9], b[10], b[11], b[12], b[13]);
final year = b[7] | (b[8] << 8);
final wall = DateTime.utc(year, b[9], b[10], b[11], b[12], b[13]);
// an unclocked band sends zeros; month 13 / feb 31 would silently roll over.
if (year < 2000 ||
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
year > 2100 ||
wall.month != b[9] ||
wall.day != b[10] ||
wall.hour != b[11] ||
wall.minute != b[12] ||
wall.second != b[13]) {
return null;
}
return (
count: count,
startSec: wall.millisecondsSinceEpoch ~/ 1000 - tz * 15 * 60,
Expand Down
10 changes: 10 additions & 0 deletions test/huami_legacy_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ void main() {
expect(parseHuamiFetchStart([0x10, 0x01, 0x02]), isNull);
});

test('start response: implausible or rolled-over date is refused', () {
List<int> f(int y, int mo, int d) =>
[0x10, 0x01, 0x01, 60, 0, 0, 0, y & 0xff, y >> 8, mo, d, 0, 0, 0, 0];
expect(parseHuamiFetchStart(f(0, 0, 0)), isNull);
expect(parseHuamiFetchStart(f(65535, 1, 1)), isNull);
expect(parseHuamiFetchStart(f(2026, 13, 1)), isNull);
expect(parseHuamiFetchStart(f(2026, 2, 31)), isNull);
expect(parseHuamiFetchStart(f(2026, 10, 3)), isNotNull);
});

test('samples: kind inheritance, no-reading HR, minute timestamps', () {
final buf = HuamiActivityBuffer()
..add([0, 0x09, 10, 0, 55, 0x00, 5, 0, 0xff])
Expand Down
Loading