summaryrefslogtreecommitdiffstats
path: root/lib/Buttons/defrost_recirculate.dart
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2023-09-20 12:26:45 -0400
committerScott Murray <scott.murray@konsulko.com>2023-09-20 12:48:19 -0400
commit6a853805d2479bf7b111511b1f94907e425c607a (patch)
tree343a651a5e4a944de525f585eceb752d9ed3840a /lib/Buttons/defrost_recirculate.dart
parent20d76f947ef9d4a9093df0e5ad04476963655173 (diff)
Rework to use KUKSA.val databroker gRPC API
Rework to move from the WebSocket API with the older KUKSA.val server to the gRPC "VAL" API of the databroker. Changes include: - All VISS WebSocket API code has been removed, and the signal providers replumbed to be driven by a new VssClient class with a hvac-specific child class to hold all the gRPC API handling. - The generated code for the VAL API and its dependencies has been checked in under lib/generated, as there still does not seem to be a good way to generate it during the Flutter build. - The configuration file is now expected to be "hvac.yaml" instead of "hvac_config.yaml". The authorization token field name has been renamed to "authorization", and there are new "use-tls" and "ca-certificate" configuration fields. TLS is disabled by default for now, and the default CA certificate is /etc/kuksa.val/CA.pem. - Bumped minimum SDK version to 2.18 in pubspec.yaml to enable "super" keyword support. This matches what the version was set to in flutter-homescreen. - The Vehicle and VehicleSignals classes have been reworked into a VehicleAcStatus class + provider, and users have been updated to use the Riverpod provider select functionality to attempt to reduce naive over-updating. - VSS paths have been rationalized to use the definitions in the VSSPath class so only one location will need to be updated on any signal name changes. - Added .gitignore file from flutter-homescreen to keep things clean in the future. Bug-AGL: SPEC-4762 Signed-off-by: Scott Murray <scott.murray@konsulko.com> Change-Id: Idbabb54ead52bf38796f264a3c8a270aa170e2cd
Diffstat (limited to 'lib/Buttons/defrost_recirculate.dart')
-rw-r--r--lib/Buttons/defrost_recirculate.dart85
1 files changed, 34 insertions, 51 deletions
diff --git a/lib/Buttons/defrost_recirculate.dart b/lib/Buttons/defrost_recirculate.dart
index 909bbf5..69adb89 100644
--- a/lib/Buttons/defrost_recirculate.dart
+++ b/lib/Buttons/defrost_recirculate.dart
@@ -5,20 +5,16 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg_provider/flutter_svg_provider.dart';
-import 'package:flutter_hvac/kuksa-server/vehicle-class.dart';
-import 'package:flutter_hvac/kuksa-server/vehicle-provider.dart';
-import 'package:flutter_hvac/kuksa-server/vehicle_methods.dart';
+import 'package:flutter_hvac/vehicle-signals/vehicle_ac_status_provider.dart';
+import 'package:flutter_hvac/vehicle-signals/vss_provider.dart';
+import 'package:flutter_hvac/vehicle-signals/vss_path.dart';
import 'package:flutter_hvac/size.dart';
class CustomButton extends ConsumerStatefulWidget {
- WebSocket socket;
- String serverPath;
String img;
String type;
CustomButton({
Key? key,
- required this.serverPath,
- required this.socket,
required this.img,
required this.type,
}) : super(key: key);
@@ -30,7 +26,9 @@ class CustomButton extends ConsumerStatefulWidget {
class _CustomButtonState extends ConsumerState<CustomButton>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
- late vehicle vehicledata;
+ late bool isFrontDefrosterActive;
+ late bool isRearDefrosterActive;
+ late bool isRecirculationActive;
late Animation<Color?> _colorAnimation;
@override
@@ -51,35 +49,18 @@ class _CustomButtonState extends ConsumerState<CustomButton>
});
_controller.addStatusListener((status) {
- if (status == AnimationStatus.completed) {
- if (widget.type == 'Front_defrost') {
- VISS.set(widget.socket,ref, widget.serverPath,
- vehicledata.isFrontDefrosterActive.toString());
- }
- if (widget.type == "Rear_defrost") {
- VISS.set(widget.socket,ref, widget.serverPath,
- vehicledata.isRearDefrosterActive.toString());
- }
- if (widget.type == "Recirculation") {
- VISS.set(widget.socket,ref, widget.serverPath,
- vehicledata.isRecirculationActive.toString());
- }
-
-
-
- }
- if (status == AnimationStatus.dismissed) {
- if (widget.type == 'Front_defrost') {
- VISS.set(widget.socket, ref,widget.serverPath,
- vehicledata.isFrontDefrosterActive.toString());
- }
- if (widget.type == "Rear_defrost") {
- VISS.set(widget.socket, ref,widget.serverPath,
- vehicledata.isRearDefrosterActive.toString());
- }
- if (widget.type == "Recirculation") {
- VISS.set(widget.socket, ref,widget.serverPath,
- vehicledata.isRecirculationActive.toString());
+ if (status == AnimationStatus.completed || status == AnimationStatus.dismissed) {
+ var vss = ref.read(vssClientProvider);
+ if (vss != null) {
+ if (widget.type == 'Front_defrost') {
+ vss.setBool(VSSPath.vehicleIsFrontDefrosterActive, isFrontDefrosterActive, true);
+ }
+ if (widget.type == "Rear_defrost") {
+ vss.setBool(VSSPath.vehicleIsRearDefrosterActive, isRearDefrosterActive, true);
+ }
+ if (widget.type == "Recirculation") {
+ vss.setBool(VSSPath.vehicleIsRecirculationActive, isRecirculationActive, true);
+ }
}
}
});
@@ -94,7 +75,10 @@ class _CustomButtonState extends ConsumerState<CustomButton>
@override
Widget build(BuildContext context) {
- vehicledata = ref.watch(vehicleProvider);
+ isFrontDefrosterActive = ref.watch(vehicleAcStatusProvider.select((p) => p.isFrontDefrosterActive));
+ isRearDefrosterActive = ref.watch(vehicleAcStatusProvider.select((p) => p.isRearDefrosterActive));
+ isRecirculationActive = ref.watch(vehicleAcStatusProvider.select((p) => p.isRecirculationActive));
+
return AnimatedBuilder(
animation: _controller,
builder: (BuildContext context, _) {
@@ -108,20 +92,20 @@ class _CustomButtonState extends ConsumerState<CustomButton>
decoration: BoxDecoration(
gradient: widget.type == "Front_defrost"
- ? vehicledata.isFrontDefrosterActive
+ ? isFrontDefrosterActive
? RadialGradient(
colors: [Colors.black, Colors.lightBlue],
radius: 2,
)
: null
: widget.type == "Rear_defrost"
- ? vehicledata.isRearDefrosterActive
+ ? isRearDefrosterActive
? RadialGradient(
colors: [Colors.black, Colors.lightBlue],
radius: 2,
)
: null
- : vehicledata.isRecirculationActive
+ : isRecirculationActive
? RadialGradient(
colors: [Colors.black, Colors.lightBlue],
radius: 2,
@@ -149,26 +133,25 @@ class _CustomButtonState extends ConsumerState<CustomButton>
),
onTap: () {
if (widget.type == "Front_defrost") {
- vehicledata.isFrontDefrosterActive
+ isFrontDefrosterActive
? _controller.reverse()
: _controller.forward();
- ref.read(vehicleProvider.notifier).update(
- isFrontDefrosterActive:
- !vehicledata.isFrontDefrosterActive);
+ ref.read(vehicleAcStatusProvider.notifier).update(
+ isFrontDefrosterActive: !isFrontDefrosterActive);
}
if (widget.type == "Rear_defrost") {
- vehicledata.isRearDefrosterActive
+ isRearDefrosterActive
? _controller.reverse()
: _controller.forward();
- ref.read(vehicleProvider.notifier).update(
- isRearDefrosterActive: !vehicledata.isRearDefrosterActive);
+ ref.read(vehicleAcStatusProvider.notifier).update(
+ isRearDefrosterActive: !isRearDefrosterActive);
}
if (widget.type == "Recirculation") {
- vehicledata.isRecirculationActive
+ isRecirculationActive
? _controller.reverse()
: _controller.forward();
- ref.read(vehicleProvider.notifier).update(
- isRecirculationActive: !vehicledata.isRecirculationActive);
+ ref.read(vehicleAcStatusProvider.notifier).update(
+ isRecirculationActive: !isRecirculationActive);
}
},
);