diff options
author | Scott Murray <scott.murray@konsulko.com> | 2023-09-14 14:01:24 -0400 |
---|---|---|
committer | Scott Murray <scott.murray@konsulko.com> | 2023-09-14 14:37:02 -0400 |
commit | cbbb9f40e283d12f6c52ad28609516f390316f7a (patch) | |
tree | d8d2cd8f4641299dd35a3138c0e28f11443928d6 /lib/vehicle-signals/viss_methods.dart | |
parent | 5ce59ba69f1451ec18c565b7b18301856553f574 (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 homescreen-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 "homescreen.yaml"
instead of "homescreen_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.
- Updated .gitignore to cover a couple of generated files that
weren't included.
Bug-AGL: SPEC-4762, SPEC-4903
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
Change-Id: I1b95ed27a72435364d54ec846f2be88e3d8bb092
Diffstat (limited to 'lib/vehicle-signals/viss_methods.dart')
-rw-r--r-- | lib/vehicle-signals/viss_methods.dart | 116 |
1 files changed, 0 insertions, 116 deletions
diff --git a/lib/vehicle-signals/viss_methods.dart b/lib/vehicle-signals/viss_methods.dart deleted file mode 100644 index 8adcc80..0000000 --- a/lib/vehicle-signals/viss_methods.dart +++ /dev/null @@ -1,116 +0,0 @@ -// 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<String, dynamic> 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<String, dynamic> 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<String, dynamic> 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<String, dynamic> map = { - "action": "subscribe", - "tokens": config.kuksaAuthToken, - "path": path, - "requestId": requestId - }; - socket.add(jsonEncode(map)); - } - - static void parseData(WidgetRef ref, String data) { - Map<String, dynamic> dataMap = jsonDecode(data); - if (dataMap["action"] == "subscription" || dataMap["action"] == "get") { - if (dataMap.containsKey("data")) { - if ((dataMap["data"] as Map<String, dynamic>).containsKey("dp") && - (dataMap["data"] as Map<String, dynamic>).containsKey("path")) { - String path = dataMap["data"]["path"]; - Map<String, dynamic> 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<String, dynamic>) - .containsKey("path")) { - print("ERROR: Invalid VIS response, no 'path' key"); - } else if ((dataMap["data"] as Map<String, dynamic>) - .containsKey("dp")) { - print("ERROR: Invalid VIS response, no 'dp' key"); - } - } else { - print("ERROR: Invalid VIS response, no 'data' key"); - } - } - } -} |