Skip to content

Commit

Permalink
Fix battery level convertion for iOS 16.4
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed May 10, 2023
1 parent 0006698 commit fdecca6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- Fix battery level convertion for iOS 16.4 ([#1424](https://github.com/getsentry/sentry-dart/pull/1424))

## 7.5.2

### Fixes
Expand Down
4 changes: 3 additions & 1 deletion dart/lib/src/protocol/sentry_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ class SentryDevice {
model: data['model'],
modelId: data['model_id'],
arch: data['arch'],
batteryLevel: data['battery_level'],
batteryLevel:
(data['battery_level'] is num ? data['battery_level'] as num : null)
?.toDouble(),
orientation: data['orientation'] == 'portrait'
? SentryOrientation.portrait
: data['orientation'] == 'landscape'
Expand Down
33 changes: 33 additions & 0 deletions dart/test/protocol/sentry_device_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,39 @@ void main() {
true,
);
});

test('batery level converts int to double', () {
final map = {'battery_level': 1};

final sentryDevice = SentryDevice.fromJson(map);

expect(
sentryDevice.batteryLevel,
1.0,
);
});

test('batery level maps double', () {
final map = {'battery_level': 1.0};

final sentryDevice = SentryDevice.fromJson(map);

expect(
sentryDevice.batteryLevel,
1.0,
);
});

test('batery level ignores if not a num', () {
final map = {'battery_level': 'abc'};

final sentryDevice = SentryDevice.fromJson(map);

expect(
sentryDevice.batteryLevel,
null,
);
});
});

group('copyWith', () {
Expand Down

0 comments on commit fdecca6

Please sign in to comment.