From 4fbd3fdb9e01c197d972b78961f0d033534a5cc7 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Wed, 28 Dec 2022 15:05:26 -0500 Subject: Add volume control to bottom panel Changes: - Import a reworked version of the KUKSA.val client code from the Flutter dashboard app, with the aggregated signal Riverpod provider replaced with per-signal providers for the signal the homescreen needs and a couple of temperature ones it might use. Using separate providers is more in-line with recommended Riverpod best practices. - Various tweaks to enable using Riverpod. - Split the bottom panel out into its own widget, and add a stack in it to layer the default logo panel with the volume control slider, which has been added as a new widget definition to provide the hook to drive timer based lowering behavior like the Qt homescreen does. - The KUKSA.val connection widget has been added to the bottom panel rather than overriding the top-level widget as in the dashboard and HVAC apps. This seems preferable with respect to still providing some functionality in the event KUKSA.val is unavailable. - Remove the old demo dashboard and HVAC pages that are now unused, along with the image assets they needed, to allow cleaning up pubspec.yaml and ease maintenance. Bug-AGL: SPEC-4659 Signed-off-by: Scott Murray Change-Id: I5d9180a3461948a58321564e71134c4961ce0ef7 --- lib/vehicle-signals/viss_methods.dart | 116 ++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 lib/vehicle-signals/viss_methods.dart (limited to 'lib/vehicle-signals/viss_methods.dart') diff --git a/lib/vehicle-signals/viss_methods.dart b/lib/vehicle-signals/viss_methods.dart new file mode 100644 index 0000000..8adcc80 --- /dev/null +++ b/lib/vehicle-signals/viss_methods.dart @@ -0,0 +1,116 @@ +// SPDX-License-Identifier: Apache-2.0 +import 'dart:convert'; +import 'dart:io'; + +import 'package:flutter_homescreen/vehicle-signals/vss_providers.dart'; +import 'package:flutter_homescreen/vehicle-signals/vss_path.dart'; +import 'package:flutter_homescreen/config.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; + +class VISS { + static const requestId = "test-id"; + + static void init(WebSocket socket, WidgetRef ref) { + authorize(socket, ref); + subscribe(socket, ref, VSSPath.vehicleMediaVolume); + } + + static void update(WebSocket socket, WidgetRef ref) { + get(socket, ref, VSSPath.vehicleMediaVolume); + } + + static void authorize(WebSocket socket, WidgetRef ref) { + final config = ref.read(ConfigStateprovider); + + Map map = { + "action": "authorize", + "tokens": config.kuksaAuthToken, + "requestId": requestId + }; + socket.add(jsonEncode(map)); + } + + static void get(WebSocket socket, WidgetRef ref, String path) { + final config = ref.read(ConfigStateprovider); + + Map map = { + "action": "get", + "tokens": config.kuksaAuthToken, + "path": path, + "requestId": requestId + }; + socket.add(jsonEncode(map)); + } + + static void set(WebSocket socket, WidgetRef ref, String path, String value) { + final config = ref.read(ConfigStateprovider); + Map map = { + "action": "set", + "tokens": config.kuksaAuthToken, + "path": path, + "requestId": requestId, + "value": value + }; + socket.add(jsonEncode(map)); + } + + static void subscribe(WebSocket socket, WidgetRef ref, String path) { + final config = ref.read(ConfigStateprovider); + + Map map = { + "action": "subscribe", + "tokens": config.kuksaAuthToken, + "path": path, + "requestId": requestId + }; + socket.add(jsonEncode(map)); + } + + static void parseData(WidgetRef ref, String data) { + Map dataMap = jsonDecode(data); + if (dataMap["action"] == "subscription" || dataMap["action"] == "get") { + if (dataMap.containsKey("data")) { + if ((dataMap["data"] as Map).containsKey("dp") && + (dataMap["data"] as Map).containsKey("path")) { + String path = dataMap["data"]["path"]; + Map dp = dataMap["data"]["dp"]; + if (dp.containsKey("value")) { + if (dp["value"] != "---") { + switch (path) { + case VSSPath.vehicleMediaVolume: + ref + .read(vehicleSignalMediaVolumeProvider.notifier) + .update(volume: dp["value"]); + break; + case VSSPath.vehicleInsideTemperature: + ref + .read(vehicleSignalInsideTempProvider.notifier) + .update(temp: dp["value"]); + break; + case VSSPath.vehicleOutsideTemperature: + ref + .read(vehicleSignalOutsideTempProvider.notifier) + .update(temp: dp["value"]); + break; + default: + break; + } + } else { + print("ERROR: Invalid VIS response, data not available"); + } + } else { + print("ERROR: Invalid VIS response, no 'value' key"); + } + } else if ((!dataMap["data"] as Map) + .containsKey("path")) { + print("ERROR: Invalid VIS response, no 'path' key"); + } else if ((dataMap["data"] as Map) + .containsKey("dp")) { + print("ERROR: Invalid VIS response, no 'dp' key"); + } + } else { + print("ERROR: Invalid VIS response, no 'data' key"); + } + } + } +} -- cgit 1.2.3-korg