Skip to content

Commit

Permalink
Display firmware versions OK
Browse files Browse the repository at this point in the history
  • Loading branch information
lupyuen committed Jun 21, 2020
1 parent bd0cca9 commit d235741
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 11 deletions.
8 changes: 7 additions & 1 deletion lib/models/device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Device extends Equatable {
final DateTime lastUpdated;
final String location;
final BluetoothDevice bluetoothDevice;
final String activeFirmwareVersion;
final String standbyFirmwareVersion;

const Device({
this.condition,
Expand All @@ -38,7 +40,9 @@ class Device extends Equatable {
this.created,
this.lastUpdated,
this.location,
this.bluetoothDevice
this.bluetoothDevice,
this.activeFirmwareVersion,
this.standbyFirmwareVersion
});

@override
Expand All @@ -53,6 +57,8 @@ class Device extends Equatable {
lastUpdated,
location,
bluetoothDevice,
activeFirmwareVersion,
standbyFirmwareVersion
];

static Device fromJson(dynamic json) {
Expand Down
9 changes: 4 additions & 5 deletions lib/repositories/device_api_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ class DeviceApiClient {
body.addAll(response2.sublist(8)); // Remove the 8-byte header
final decodedBody = decodeCBOR(body);
print('Decoded Response: $decodedBody\n');
final images = decodedBody[0]['images'];
final image = images[0];
final version = image['version'];
print('${ version }\n');
final images = decodedBody[0]['images'] as List<dynamic>;

// Return the device state
final device = Device(
Expand All @@ -109,7 +106,9 @@ class DeviceApiClient {
locationId: 0,
lastUpdated: DateTime.now(),
location: '${ bluetoothDevice.name } ${ bluetoothDevice.id.toString() }',
bluetoothDevice: bluetoothDevice
bluetoothDevice: bluetoothDevice,
activeFirmwareVersion: (images.length >= 1) ? images[0]['version'] : '',
standbyFirmwareVersion: (images.length >= 2) ? images[1]['version'] : '',
);
return device;
}
Expand Down
38 changes: 38 additions & 0 deletions lib/widgets/device_firmware.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Widget to display firmware versions in a device
import 'package:flutter/material.dart';
import '../blocs/blocs.dart';

class DeviceFirmware extends StatelessWidget {
final String activeFirmwareVersion;
final String standbyFirmwareVersion;

DeviceFirmware({
Key key,
this.activeFirmwareVersion,
this.standbyFirmwareVersion
}) : super(key: key);

@override
Widget build(BuildContext context) {
return Column(
children: [
Text(
'Active Firmware: $activeFirmwareVersion',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w100,
color: Colors.white,
),
),
Text(
'Standby Firmware: $standbyFirmwareVersion',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w100,
color: Colors.white,
),
)
],
);
}
}
8 changes: 3 additions & 5 deletions lib/widgets/device_summary.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ class DeviceSummary extends StatelessWidget {
padding: EdgeInsets.all(20.0),
child: BlocBuilder<SettingsBloc, SettingsState>(
builder: (context, state) {
return Temperature(
temperature: device.temp,
high: device.maxTemp,
low: device.minTemp,
units: state.temperatureUnits,
return DeviceFirmware(
activeFirmwareVersion: device.activeFirmwareVersion,
standbyFirmwareVersion: device.standbyFirmwareVersion,
);
},
),
Expand Down
1 change: 1 addition & 0 deletions lib/widgets/widgets.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export './city_selection.dart';
export './combined_weather_temperature.dart';
export './device.dart';
export './device_firmware.dart';
export './device_summary.dart';
export './find_device.dart';
export './gradient_container.dart';
Expand Down

0 comments on commit d235741

Please sign in to comment.