Skip to content

Commit

Permalink
Fix battery level convertion for iOS 16.4 (#1433)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored May 10, 2023
1 parent 3a43905 commit bf4aed7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixes

- Fix battery level convertion for iOS 16.4 ([#1433](https://github.com/getsentry/sentry-dart/pull/1433))
- Adds a namespace for compatibility with AGP 8.0. ([#1427](https://github.com/getsentry/sentry-dart/pull/1427))

## 7.5.2
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 bf4aed7

Please sign in to comment.