using InnovEnergy.Lib.Protocols.DBus.Protocol; using InnovEnergy.Lib.Protocols.DBus.Protocol.DataTypes; namespace InnovEnergy.Lib.Victron.VeDBus; using VeDict = IReadOnlyDictionary; public readonly record struct VeProperty(ObjectPath ObjectPath, Object Value, String Text, Boolean Writeable = true) { public VeProperty(ObjectPath objectPath, Object value, Boolean writeable = false) : this(objectPath, value, value.ToString()!, writeable) { } public static VeProperty Decode(Message m) { var dict = (VeDict) m.Payload!; var text = (String) dict["Text"].Value; var value = dict["Value"].Value; var path = m.ObjectPath!.Value; return new VeProperty(path, value, text); } public Boolean Equals(VeProperty other) { return ObjectPath.Path == other.ObjectPath.Path && Text == other.Text && Value.Equals(other.Value); } public override Int32 GetHashCode() { return HashCode.Combine(ObjectPath.Path, Value, Text); } public Dictionary GetItem() { return new Dictionary { ["Text"] = Text.Variant(), ["Value"] = Value.Variant() }; } public object SetProperty(object? payload) { throw new NotImplementedException(); } }