-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,121 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,6 @@ services: | |
dockerfile: Dockerfile | ||
args: | ||
GIT_COMMIT: local | ||
DEBUGHELPER: yes | ||
ports: | ||
- "80" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,36 @@ | ||
namespace tuya_mqtt.net.Data | ||
using com.clusterrr.TuyaNet; | ||
using System.Reflection; | ||
|
||
namespace tuya_mqtt.net.Data | ||
{ | ||
public class TuyaCommunicatorOptions | ||
{ | ||
public TuyaCommunicatorOptions() { } | ||
|
||
public string TuyaAPIAccessID { get; set; } = String.Empty; | ||
|
||
public string TuyaAPISecret { get; set; } = String.Empty; | ||
|
||
public TuyaApi.Region TuyaAPIRegion { get; set; } = TuyaApi.Region.WesternEurope; | ||
|
||
public bool Equals(TuyaCommunicatorOptions? x) | ||
{ | ||
return x?.TuyaAPIAccessID == TuyaAPIAccessID && | ||
x?.TuyaAPISecret == TuyaAPISecret && | ||
x?.TuyaAPIRegion.GetHashCode() == TuyaAPIRegion.GetHashCode(); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
Type type = GetType(); | ||
var collectionString = type.Name + " ("; | ||
foreach (PropertyInfo prop in type.GetProperties()) | ||
{ | ||
collectionString += $" {prop.Name}:{prop.GetValue(this)}"; | ||
} | ||
|
||
collectionString += " )"; | ||
return collectionString; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace tuya_mqtt.net.Helper | ||
{ | ||
public class HealthCheckResponse | ||
{ | ||
public static Task WriteResponse(HttpContext context, HealthReport result) | ||
{ | ||
context.Response.ContentType = "application/json"; | ||
|
||
var json = new JObject( | ||
new JProperty("status", result.Status.ToString()), | ||
new JProperty("results", new JObject(result.Entries.Select(pair => | ||
new JProperty(pair.Key, new JObject( | ||
new JProperty("status", pair.Value.Status.ToString()), | ||
new JProperty("description", pair.Value.Description), | ||
new JProperty("data", new JObject(pair.Value.Data.Select( | ||
p => new JProperty(p.Key, p.Value)))))))))); | ||
|
||
return context.Response.WriteAsync( | ||
json.ToString(Formatting.Indented)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace tuya_mqtt.net.Helper | ||
{ | ||
public class RateCounter | ||
{ | ||
private readonly List<DateTime> _counter = new List <DateTime>(); | ||
private readonly TimeSpan _duration; | ||
public RateCounter(TimeSpan duration) | ||
{ | ||
_duration = duration; | ||
|
||
} | ||
public void Clear() | ||
{ | ||
_counter.Clear(); | ||
} | ||
public void Count() | ||
{ | ||
_counter.Add(DateTime.UtcNow); | ||
Cleanup(); | ||
} | ||
|
||
private void Cleanup() | ||
{ | ||
IEnumerable<DateTime> enumerableThing = _counter; | ||
foreach (var x in enumerableThing.Reverse()) | ||
{ | ||
if ((x + _duration) < DateTime.UtcNow ) | ||
_counter.Remove(x); | ||
} | ||
} | ||
|
||
public int Rate | ||
{ | ||
get | ||
{ | ||
Cleanup(); | ||
return _counter.Count; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.