Skip to content

Commit

Permalink
feat: Add simple display of target temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
rlperez committed Jan 20, 2022
1 parent 8e2c459 commit c648bb6
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 12 deletions.
17 changes: 9 additions & 8 deletions lib/traits/device_widget_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import 'package:yonomi_device_widgets/traits/slim/base_slim_widget.dart';
import 'package:yonomi_device_widgets/traits/slim/battery_slim_widget.dart';
import 'package:yonomi_device_widgets/traits/slim/lock_slim_widget.dart';
import 'package:yonomi_device_widgets/traits/slim/power_slim_widget.dart';
import 'package:yonomi_device_widgets/traits/slim/thermostat_slim_widget.dart';
import 'package:yonomi_device_widgets/traits/slim/unknown_slim_widget.dart';
import 'package:yonomi_device_widgets/traits/thermostat_widget.dart';
import 'package:yonomi_device_widgets/traits/unknown_widget.dart';
import 'package:yonomi_device_widgets/ui/widget_style_constants.dart';

Expand Down Expand Up @@ -42,7 +44,7 @@ class DeviceWidgetFactory<T> {
case ThermostatProvider:
return Consumer<ThermostatProvider>(
builder: (_, thermostatProvider, child) {
return Text('${thermostatProvider.targetTemperature.toInt()}');
return ThermostatWidget(thermostatProvider, textColor: textColor);
},
);
default:
Expand Down Expand Up @@ -76,13 +78,12 @@ class DeviceWidgetFactory<T> {
});
case ThermostatProvider:
return Consumer<ThermostatProvider>(
builder: (_, thermostatProvider, child) {
return BaseSlimWidget(
leftIcon: Icon(BootstrapIcons.thermometer),
headerText: Text(
'Target Temperature: ${thermostatProvider.targetTemperature.toInt()}'));
},
);
builder: (_, thermostatProvider, child) {
return ThermostatSlimWidget(
thermostatProvider,
backgroundColor: backgroundColor,
);
});
default:
return UnknownSlimWidget(name ?? '', backgroundColor: backgroundColor);
}
Expand Down
21 changes: 21 additions & 0 deletions lib/traits/slim/thermostat_slim_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:bootstrap_icons/bootstrap_icons.dart';
import 'package:flutter/material.dart';
import 'package:yonomi_device_widgets/providers/thermostat_provider.dart';
import 'package:yonomi_device_widgets/traits/slim/base_slim_widget.dart';
import 'package:yonomi_device_widgets/ui/widget_style_constants.dart';

class ThermostatSlimWidget extends BaseSlimWidget {
ThermostatSlimWidget(ThermostatProvider thermostatProvider,
{Color? backgroundColor, Key? key})
: super(
provider: thermostatProvider,
leftIcon: Icon(BootstrapIcons.thermometer,
size: 20.0,
color: WidgetStyleConstants.deviceDetailIconColorActive),
headerText: Text(
'Target Temperature: ${thermostatProvider.targetTemperature.toInt()}\u{00B0}',
style: TextStyle(
fontSize: 20, color: WidgetStyleConstants.darkTextColor)),
backgroundColor: backgroundColor,
key: key);
}
68 changes: 68 additions & 0 deletions lib/traits/thermostat_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import 'package:bootstrap_icons/bootstrap_icons.dart';
import 'package:flutter/material.dart';
import 'package:yonomi_device_widgets/providers/thermostat_provider.dart';
import 'package:yonomi_device_widgets/ui/widget_style_constants.dart';

class ThermostatWidget extends StatelessWidget {
final ThermostatProvider _thermostatProvider;

late final Color _textColor;

ThermostatWidget(this._thermostatProvider,
{Color textColor = WidgetStyleConstants.darkTextColor, Key? key})
: super(key: key) {
this._textColor = textColor;
}

Widget _centerText(TextStyle? style) {
return Row(children: [
Icon(
BootstrapIcons.thermometer,
size: style?.height,
color: style?.color,
),
Text(
'${_thermostatProvider.targetTemperature.toInt()}\u{00B0}',
style: style,
)
]);
}

@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Row(
children: <Widget>[
Text(
_thermostatProvider.displayName,
style: Theme.of(context)
.textTheme
.headline6
?.copyWith(color: _textColor),
textAlign: TextAlign.center,
),
],
),
SizedBox(
height: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: _centerText(Theme.of(context)
.textTheme
.headline2
?.copyWith(color: _textColor)),
)
],
),
SizedBox(
height: 30,
),
],
);
}
}
19 changes: 15 additions & 4 deletions test/traits/detail_screen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import 'package:yonomi_device_widgets/traits/power_widget.dart';
import 'package:yonomi_device_widgets/traits/slim/battery_slim_widget.dart';
import 'package:yonomi_device_widgets/traits/slim/lock_slim_widget.dart';
import 'package:yonomi_device_widgets/traits/slim/power_slim_widget.dart';
import 'package:yonomi_device_widgets/traits/slim/thermostat_slim_widget.dart';
import 'package:yonomi_device_widgets/traits/thermostat_widget.dart';
import 'package:yonomi_device_widgets/ui/widget_style_constants.dart';
import 'package:yonomi_platform_sdk/yonomi-sdk.dart';

Expand Down Expand Up @@ -105,7 +107,8 @@ class DetailScreenTest
BatteryLevelProvider mockBatteryLevelProvider,
ThermostatProvider mockThermostatProvider) {
return MaterialApp(
home: Column(children: [
home: SingleChildScrollView(
child: Column(children: [
MultiProvider(
providers: [
ChangeNotifierProvider<TraitDetailProvider>.value(
Expand All @@ -120,7 +123,7 @@ class DetailScreenTest
],
child: DetailScreenWidget(req, deviceId),
),
]),
])),
);
}
}
Expand Down Expand Up @@ -200,7 +203,8 @@ void main() {
await tester.pumpWidget(test.createDetailScreenWidgetForTraits(
[ThermostatTrait(TargetTemperature(100.0))], request, testedDeviceId));

expect(find.text('100'), findsOneWidget);
expect(find.byType(ThermostatWidget), findsOneWidget);
expect(find.text('100°'), findsOneWidget);
});

testWidgets(
Expand All @@ -223,14 +227,16 @@ void main() {
UnknownTrait('unknown'),
BatteryLevelTrait(BatteryLevel(100)),
PowerTrait(IsOnOff(true)),
LockTrait(IsLocked(false))
LockTrait(IsLocked(false)),
ThermostatTrait(TargetTemperature(99))
], request, testedDeviceId));

expect(find.byType(LockWidget), findsOneWidget);
expect(find.byType(UnknownItemIcon), findsOneWidget);
expect(find.byType(BatterySlimWidget), findsOneWidget);
expect(find.byType(LockSlimWidget), findsOneWidget);
expect(find.byType(PowerSlimWidget), findsOneWidget);
expect(find.byType(ThermostatSlimWidget), findsOneWidget);

expect(find.byType(MultiProvider), findsOneWidget);

Expand All @@ -239,6 +245,11 @@ void main() {
expect(batteryWidget.headerText.data, contains('Battery Level: 100%'));
expect(batteryWidget.headerText.style?.color,
WidgetStyleConstants.globalSuccessColor);

final thermostatWidget =
tester.widget<ThermostatSlimWidget>(find.byType(ThermostatSlimWidget));
expect(
thermostatWidget.headerText.data, contains('Target Temperature: 99°'));
});

testWidgets(
Expand Down

0 comments on commit c648bb6

Please sign in to comment.