Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix battery level convertion for iOS 16.4 #1433

Merged
merged 3 commits into from
May 10, 2023
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
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(),
marandaneto marked this conversation as resolved.
Show resolved Hide resolved
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