diff options
author | Scott Murray <scott.murray@konsulko.com> | 2023-12-08 10:28:48 +0900 |
---|---|---|
committer | Scott Murray <scott.murray@konsulko.com> | 2023-12-08 10:54:30 +0900 |
commit | 71d46d03850653c0229c678de197c6f94fceb477 (patch) | |
tree | b91915e70c9092d304d3172b93eb61ffb0c287c5 /lib/presentation/screens/hvac | |
parent | dca5f5bc58fc3b25972bedc82827b71300d66adc (diff) |
More signaling fixes
Changes:
- Fixed parsing of engine speed from databroker response to use
uint32 again to match VSS type.
- Shifted engine speed definitions in Vehicle class next to
vehicle speed since that seems a bit saner than having it down at
the bottom with the temperature values.
- Removed duplicate temperature state from temperature control
widget, and pushed the use of the providers from the HVAC widget.
The existing scheme was somewhat broken with respect to having the
values managed with RiverPod, e.g. new values from external updates
would not show up until switching away and back to the HVAC tab.
- Moved HVAC "SYNC" button state into the Vehicle state class to
manage it with RiverPod, and allow use from both the HVAC and
temperature widgets so that the expected behavior can actually be
implemented.
- Fixed brace usage in a couple of debugPrint statements.
Bug-AGL: SPEC-4999
Change-Id: I07ea49d20fedca47e6f9e54f45ad34296e0a873c
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
Diffstat (limited to 'lib/presentation/screens/hvac')
3 files changed, 56 insertions, 58 deletions
diff --git a/lib/presentation/screens/hvac/hvac_content.dart b/lib/presentation/screens/hvac/hvac_content.dart index 73fd439..e541efd 100644 --- a/lib/presentation/screens/hvac/hvac_content.dart +++ b/lib/presentation/screens/hvac/hvac_content.dart @@ -13,15 +13,8 @@ class HVACState extends ConsumerState<HVAC> { bool isFanFocusLeftBottomSelected = true; bool isFanFocusRightBottomSelected = false; - late bool isACSelected; - bool isSYNCSelected = true; - late bool isFrontDefrostSelected; bool isAutoSelected = true; - late bool isRecirculationSelected; - late bool isRearDefrostSelected; - int temperatureLeft = 26; - int temperatureRight = 26; @override void initState() { super.initState(); @@ -52,14 +45,12 @@ class HVACState extends ConsumerState<HVAC> { @override Widget build(BuildContext context) { - final vehicle = ref.watch(vehicleProvider.select((vehicle) => vehicle)); - isACSelected = vehicle.isAirConditioningActive; - isFrontDefrostSelected = vehicle.isFrontDefrosterActive; - isRearDefrostSelected = vehicle.isRearDefrosterActive; - isRecirculationSelected = vehicle.isRecirculationActive; + bool isACSelected = ref.watch(vehicleProvider.select((vehicle) => vehicle.isAirConditioningActive)); + bool isFrontDefrostSelected = ref.watch(vehicleProvider.select((vehicle) => vehicle.isFrontDefrosterActive)); + bool isRearDefrostSelected = ref.watch(vehicleProvider.select((vehicle) => vehicle.isRearDefrosterActive)); + bool isRecirculationSelected = ref.watch(vehicleProvider.select((vehicle) => vehicle.isRecirculationActive)); + bool isSYNCSelected = ref.watch(vehicleProvider.select((vehicle) => vehicle.temperatureSynced)); Size size = MediaQuery.sizeOf(context); - temperatureLeft = vehicle.driverTemperature; - temperatureRight = vehicle.passengerTemperature; return Column( crossAxisAlignment: CrossAxisAlignment.stretch, @@ -155,14 +146,8 @@ class HVACState extends ConsumerState<HVAC> { Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - TemperatureControl( - temperature: temperatureLeft, - side: Side.left, - ), - TemperatureControl( - temperature: temperatureRight, - side: Side.right, - ) + TemperatureControl(side: Side.left), + TemperatureControl(side: Side.right) ], ), const SizedBox( @@ -190,9 +175,15 @@ class HVACState extends ConsumerState<HVAC> { )), ClimateControls( onPressed: () { - setState(() { - isSYNCSelected = !isSYNCSelected; - }); + if (!isSYNCSelected) { + int temperature = ref.read(vehicleProvider.select((vehicle) => vehicle.driverTemperature)); + ref + .read(vehicleProvider.notifier) + .setTemperature(side: Side.right, value: temperature); + } + ref + .read(vehicleProvider.notifier) + .setTemperatureSynced(!isSYNCSelected); }, isSelected: isSYNCSelected, child: Text( diff --git a/lib/presentation/screens/hvac/widgets/fan_speed_controls.dart b/lib/presentation/screens/hvac/widgets/fan_speed_controls.dart index ac813ca..e9a9719 100644 --- a/lib/presentation/screens/hvac/widgets/fan_speed_controls.dart +++ b/lib/presentation/screens/hvac/widgets/fan_speed_controls.dart @@ -69,8 +69,7 @@ class FanSpeedControlsState extends ConsumerState<FanSpeedControls> double iconSize = 80; - final vehicle = ref.watch(vehicleProvider.select((vehicle) => vehicle)); - selectedFanSpeed = vehicle.fanSpeed; + int selectedFanSpeed = ref.watch(vehicleProvider.select((vehicle) => vehicle.fanSpeed)); controlProgress = selectedFanSpeed * 0.3; return Stack( diff --git a/lib/presentation/screens/hvac/widgets/temperature_control.dart b/lib/presentation/screens/hvac/widgets/temperature_control.dart index 77d6dbc..31875ca 100644 --- a/lib/presentation/screens/hvac/widgets/temperature_control.dart +++ b/lib/presentation/screens/hvac/widgets/temperature_control.dart @@ -6,8 +6,7 @@ enum Side { left, right } class TemperatureControl extends ConsumerStatefulWidget { const TemperatureControl( - {super.key, required this.temperature, required this.side}); - final int temperature; + {super.key, required this.side}); final Side side; @override @@ -16,48 +15,57 @@ class TemperatureControl extends ConsumerStatefulWidget { class TemperatureControlState extends ConsumerState<TemperatureControl> { late Timer tempButtonTimer; - int temperature = 0; bool isUpButtonHighlighted = false; bool isDownButtonHighlighted = false; - @override - void initState() { - super.initState(); - setState(() { - temperature = widget.temperature; - }); - } - onPressed({required String type, required Side side}) { - setState(() { - if (type == "add") { - temperature = temperature + 1; - } else if (type == "subtract") { - temperature = temperature - 1; - } - // limit the temperature to 60-100F - if (temperature <= 15) { - temperature = 15; - } else if (temperature >= 38) { - temperature = 38; - } - if (widget.side == Side.left) { + int temperature = 0; + if (side == Side.left) { + temperature = ref.read(vehicleProvider.select((vehicle) => vehicle.driverTemperature)); + } else { + temperature = ref.read(vehicleProvider.select((vehicle) => vehicle.passengerTemperature)); + } + if (type == "add") { + temperature = temperature + 1; + } else if (type == "subtract") { + temperature = temperature - 1; + } + // limit the temperature to 60-100F + if (temperature <= 15) { + temperature = 15; + } else if (temperature >= 38) { + temperature = 38; + } + bool isSynced = ref.read(vehicleProvider.select((vehicle) => vehicle.temperatureSynced)); + if (widget.side == Side.left) { + ref + .read(vehicleProvider.notifier) + .setTemperature(side: Side.left, value: temperature); + if (isSynced) { ref .read(vehicleProvider.notifier) - .setTemperature(side: Side.left, value: temperature); - } else { + .setTemperature(side: Side.right, value: temperature); + } + } else { + if (isSynced) { ref .read(vehicleProvider.notifier) - .setTemperature(side: Side.right, value: temperature); + .setTemperatureSynced(false); } - }); + ref + .read(vehicleProvider.notifier) + .setTemperature(side: Side.right, value: temperature); + } } @override Widget build(BuildContext context) { - //final temperature = ref.watch(vehicleProvider.select((vehicle) => vehicle)); - // final outsideTemperature = ref - // .watch(vehicleProvider.select((vehicle) => vehicle.outsideTemperature)); + int temperature = 0; + if (widget.side == Side.left) { + temperature = ref.watch(vehicleProvider.select((vehicle) => vehicle.driverTemperature)); + } else { + temperature = ref.watch(vehicleProvider.select((vehicle) => vehicle.passengerTemperature)); + } final tempUnit = ref.watch(unitStateProvider.select((unit) => unit.temperatureUnit)); |