Innovenergy_trunk/csharp/lib/Victron/VeDBus/VeProperty.cs

48 lines
1.4 KiB
C#

using InnovEnergy.Lib.Protocols.DBus.Protocol;
using InnovEnergy.Lib.Protocols.DBus.Protocol.DataTypes;
namespace InnovEnergy.Lib.Victron.VeDBus;
using VeDict = IReadOnlyDictionary<String, Variant>;
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<String, Variant> GetItem()
{
return new Dictionary<String, Variant>
{
["Text"] = Text.Variant(),
["Value"] = Value.Variant()
};
}
public object SetProperty(object? payload)
{
throw new NotImplementedException();
}
}