Skip to content

Commit

Permalink
Merge branch 'dev_and_test'
Browse files Browse the repository at this point in the history
  • Loading branch information
Volker Hänsel committed Oct 5, 2023
2 parents 3dd9a6e + bc6f421 commit f5accd3
Show file tree
Hide file tree
Showing 16 changed files with 596 additions and 397 deletions.
41 changes: 29 additions & 12 deletions tuya_mqtt.net/Data/DP.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
using Newtonsoft.Json.Linq;
using System.Reflection.Metadata.Ecma335;

namespace tuya_mqtt.net.Data
{
// ReSharper disable once InconsistentNaming
public class DP
{
private readonly int _dpNo;
private readonly byte _dpNo;
private readonly string _valueString;

public DP(int dpNo, string value)
public DP(byte dpNo, string value)
{
this._dpNo = dpNo;
this._valueString = value;
}

// ReSharper disable once InconsistentNaming
public static List<DP> ParseCloudJSON(string json)
public static List<DP> ParseCloudJSON(string json, List<byte>? DPList = null)
{
var list = new List<DP>();
try
Expand All @@ -31,10 +32,11 @@ public static List<DP> ParseCloudJSON(string json)

if (value != null && name != null)
{
int id;
if (int.TryParse(name.ToString(), out id))
byte id;
if (byte.TryParse(name.ToString(), out id))
{
list.Add(new DP(id, value.ToString()));
if (IdInList(id, DPList))
list.Add(new DP(id, value.ToString()));
}

}
Expand All @@ -49,8 +51,22 @@ public static List<DP> ParseCloudJSON(string json)
}
}

private static bool IdInList(byte id, List<byte>? dPList)
{
if (dPList == null) return true; //default we take it all
else
{
if (dPList.Count == 0) return true; //empty list means we take all
else
{
if (dPList.Contains(id)) return true;
}
}
return false;
}

// ReSharper disable once InconsistentNaming
public static List<DP> ParseLocalJSON(string json)
public static List<DP> ParseLocalJSON(string json, List<byte>? DPList = null)
{

var list = new List<DP>();
Expand All @@ -64,10 +80,11 @@ public static List<DP> ParseLocalJSON(string json)
{
var name = ((JProperty)d).Name;
var value = d;
int id;
if (int.TryParse(name, out id))
byte id;
if (byte.TryParse(name, out id))
{
list.Add(new DP(id, value.ToObject<string>()!));
if (IdInList(id, DPList))
list.Add(new DP(id, value.ToObject<string>()!));
}
}
}
Expand All @@ -80,7 +97,7 @@ public static List<DP> ParseLocalJSON(string json)
}

// ReSharper disable once InconsistentNaming
public static string FindPropertyByDP(string json, int dpNumber)
public static string FindPropertyByDP(string json, byte dpNumber)
{
try
{
Expand Down Expand Up @@ -109,7 +126,7 @@ public static string FindPropertyByDP(string json, int dpNumber)
}

// ReSharper disable once InconsistentNaming
public int DPNumber { get { return _dpNo; } }
public byte DPNumber { get { return _dpNo; } }
public string Value { get { return _valueString; } }

}
Expand Down
13 changes: 13 additions & 0 deletions tuya_mqtt.net/Data/IBrowserService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.JSInterop;

namespace tuya_mqtt.net.Data
{
internal interface IBrowserService
{
public Task<TimeSpan> GetTimeZoneOffset();
public Task<string> GetBrowserLanguage();
public Task ScrollClassIntoView(string classSearchString, int index);
public Task DownloadStreamAsync(string fileName, Stream fileStream);

}
}
6 changes: 3 additions & 3 deletions tuya_mqtt.net/Data/SubscriptionKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace tuya_mqtt.net.Data
{
public class SubscriptionKey :Tuple<int,string>
public class SubscriptionKey :Tuple<byte,string>
{
public string ID
{
get => base.Item2;
}
public int DpNumber
public byte DpNumber
{
get => base.Item1;
}

public SubscriptionKey(string id, int dp):base(dp,id)
public SubscriptionKey(string id, byte dp):base(dp,id)
{
}

Expand Down
33 changes: 28 additions & 5 deletions tuya_mqtt.net/Data/TuyaDeviceInformation.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using com.clusterrr.TuyaNet;
using Newtonsoft.Json;
// ReSharper disable InconsistentNaming

namespace tuya_mqtt.net.Data
{
public class TuyaDeviceInformation
{
public enum DeviceType
public enum TuyaDeviceType
{
LocalTuya = 1,
LocalTuya0A = 1,
LocalTuya0D = 2,
Cloud =10,

}
Expand All @@ -29,8 +31,8 @@ public TuyaDeviceInformation()
public string Key { get; set; } = string.Empty;
public string Address { get; set; } = string.Empty;
public TuyaProtocolVersion ProtocolVersion { get; set; } = TuyaProtocolVersion.V33;
public DeviceType CommunicationType { get; set; } = DeviceType.LocalTuya;

public TuyaDeviceType CommunicationType { get; set; } = TuyaDeviceType.LocalTuya0A;
}

public class TuyaExtendedDeviceInformation : TuyaDeviceInformation
Expand All @@ -42,11 +44,12 @@ public TuyaExtendedDeviceInformation()
{

}
public TuyaExtendedDeviceInformation(TuyaDeviceInformation device, string name, TimeSpan pollingInterval):base(device)
public TuyaExtendedDeviceInformation(TuyaDeviceInformation device, string name, TimeSpan pollingInterval, List<byte> DPlist):base(device)
{
_name = name;
PollingInterval = pollingInterval;
LastTriggered = DateTime.MinValue;
MonitoredDPs = DPlist;
}

[JsonIgnore]
Expand Down Expand Up @@ -105,5 +108,25 @@ public void SetTrigger()
_locked = false;
}
}

public List<byte> MonitoredDPs { get; set; } = new List<byte>();

/// <summary>
///
/// </summary>
[System.Text.Json.Serialization.JsonIgnore]
public string MonitoredDPsString
{
get
{
string result = String.Empty;
MonitoredDPs.Sort();
foreach (var dp in MonitoredDPs)
{
result += dp.ToString()+ " ";
}
return result.Trim(); //remove last ' ' from list
}
}
}
}
Loading

0 comments on commit f5accd3

Please sign in to comment.