diff options
Diffstat (limited to 'lib/core/constants/val_client_helper.dart')
-rw-r--r-- | lib/core/constants/val_client_helper.dart | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/core/constants/val_client_helper.dart b/lib/core/constants/val_client_helper.dart new file mode 100644 index 0000000..0d7a284 --- /dev/null +++ b/lib/core/constants/val_client_helper.dart @@ -0,0 +1,58 @@ +import 'package:protos/protos.dart'; + +class ValClientHelper { + final ClientChannel channel; + final VALClient stub; + + ValClientHelper({required this.channel, required this.stub}); + + void setUint32(String path, int value, [bool actuator = true]) async { + var dp = Datapoint()..uint32 = value; + set(path, dp, actuator); + } + + void setInt32(String path, int value, [bool actuator = true]) async { + var dp = Datapoint()..int32 = value; + set(path, dp, actuator); + } + + void setBool(String path, bool value, [bool actuator = true]) async { + var dp = Datapoint()..bool_12 = value; + set(path, dp, actuator); + } + + void setString(String path, String value, [bool actuator = true]) async { + var dp = Datapoint()..string = value; + set(path, dp, actuator); + } + + void setFloat(String path, double value, [bool actuator = true]) async { + var dp = Datapoint()..float = value; + set(path, dp, actuator); + } + + void setDouble(String path, double value, [bool actuator = true]) async { + var dp = Datapoint()..double_18 = value; + set(path, dp, actuator); + } + + void set(String path, Datapoint dp, bool actuator) async { + var entry = DataEntry()..path = path; + var update = EntryUpdate(); + if (actuator) { + entry.actuatorTarget = dp; + update.fields.add(Field.FIELD_ACTUATOR_TARGET); + } else { + entry.value = dp; + update.fields.add(Field.FIELD_VALUE); + } + update.entry = entry; + var request = SetRequest(); + request.updates.add(update); + Map<String, String> metadata = {}; + // if (config.authorization.isNotEmpty) { + // metadata = {'authorization': "Bearer ${config.authorization}"}; + // } + await stub.set(request, options: CallOptions(metadata: metadata)); + } +} |