// SPDX-License-Identifier: Apache-2.0 import 'dart:io'; import 'package:meta/meta.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:grpc/grpc.dart'; import 'package:flutter_hvac/generated/kuksa/val/v1/val.pbgrpc.dart'; import 'package:flutter_hvac/generated/kuksa/val/v1/types.pb.dart'; import 'package:flutter_hvac/config.dart'; import 'package:flutter_hvac/vehicle-signals/vss_client.dart'; import 'package:flutter_hvac/vehicle-signals/vss_signal_providers.dart'; import 'package:flutter_hvac/vehicle-signals/vss_path.dart'; class HvacVssClient extends VssClient { @override final List signals = [ VSSPath.vehicleFrontLeftTemp, VSSPath.vehicleFrontRightTemp, VSSPath.vehicleFrontLeftFanSpeed ]; HvacVssClient({required super.config, required super.channel, required super.stub, required super.ref}); @override void handleSignalUpdates(EntryUpdate update) { switch (update.entry.path) { case VSSPath.vehicleFrontLeftTemp: if (update.entry.value.hasInt32()) { ref .read(LeftClimateTempProvider.notifier) .update(update.entry.value.int32); } break; case VSSPath.vehicleFrontRightTemp: if (update.entry.value.hasInt32()) { ref .read(RightClimateTempProvider.notifier) .update(update.entry.value.int32); } break; case VSSPath.vehicleFrontLeftFanSpeed: if (update.entry.value.hasInt32()) { ref .read(fanSpeedProvider.notifier) .update(update.entry.value.int32); } break; default: print("ERROR: Unexpected path ${update.entry.path}"); break; } } } final vssClientProvider = Provider((ref) { var config = ref.read(kuksaConfigProvider); debugPrint("Using ${config.hostname}:${config.port}"); ChannelCredentials creds; if (config.use_tls && config.ca_certificate.isNotEmpty) { print("Using TLS"); if (config.tls_server_name.isNotEmpty) creds = ChannelCredentials.secure(certificates: config.ca_certificate, authority: config.tls_server_name); else creds = ChannelCredentials.secure(certificates: config.ca_certificate); } else { creds = ChannelCredentials.insecure(); } final channel = ClientChannel(config.hostname, port: config.port, options: ChannelOptions(credentials: creds)); final stub = VALClient(channel); return HvacVssClient(config: config, channel: channel, stub: stub, ref: ref); });