Skip to content

Commit c10a8cb

Browse files
author
danny
committed
Fixing unsavable color
1 parent 703b01e commit c10a8cb

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

macless_haystack/lib/accessory/accessory_model.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,13 @@ class Accessory {
209209
isActive = json['isActive'],
210210
isDeployed = json['isDeployed'],
211211
_icon = json['icon'],
212-
color = Color(int.parse(json['color'], radix: 16)),
212+
color = Color(int.parse(json['color'].substring(0, 8), radix: 16)),
213213
usesDerivation = json['usesDerivation'] ?? false,
214214
symmetricKey = json['symmetricKey'],
215215
lastDerivationTimestamp = json['lastDerivationTimestamp'],
216216
updateInterval = json['updateInterval'],
217217
oldestRelevantSymmetricKey = json['oldestRelevantSymmetricKey'],
218+
lastBatteryStatus = json['lastBatteryStatus'] != null ? AccessoryBatteryStatus.values.byName(json['lastBatteryStatus']) : null,
218219
hashes = json['hashes'] != null
219220
? (json['hashes'] as List).map((e) => e.toString()).toSet()
220221
: <String>{},
@@ -242,14 +243,15 @@ class Accessory {
242243
'isActive': isActive,
243244
'isDeployed': isDeployed,
244245
'icon': _icon,
245-
'color': color.toString().split('(0x')[1].split(')')[0],
246+
'color': color.value.toRadixString(16).padLeft(8, '0'),
246247
'usesDerivation': usesDerivation,
247248
'hashes': hashes.toList(),
248249
'symmetricKey': symmetricKey,
249250
'lastDerivationTimestamp': lastDerivationTimestamp,
250251
'updateInterval': updateInterval,
251252
'oldestRelevantSymmetricKey': oldestRelevantSymmetricKey,
252253
'additionalKeys': additionalKeys,
254+
...lastBatteryStatus != null ? {'lastBatteryStatus': lastBatteryStatus!.name} : {}
253255
};
254256

255257
/// Returns the Base64 encoded hash of the advertisement key

0 commit comments

Comments
 (0)