Skip to content

Commit

Permalink
add component
Browse files Browse the repository at this point in the history
  • Loading branch information
rido-min committed Dec 17, 2021
1 parent 94116f8 commit 46cb0fe
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Rido.IoTClient/AzBroker/TopicBindings/Component.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using MQTTnet.Client;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Rido.IoTClient.AzBroker.TopicBindings
{
public abstract class Component
{
readonly string name;
readonly IPropertyStoreWriter update;

public Component(IMqttClient connection, string name)
{
this.name = name;
update = UpdateTwinBinder.GetInstance(connection);
}

public async Task<int> ReportPropertyAsync(CancellationToken token = default)
{
Dictionary<string, Dictionary<string, object>> dict = new Dictionary<string, Dictionary<string, object>>
{
{ name, new Dictionary<string, object>() }
};
dict[name] = this.ToJsonDict();
dict[name].Add("__t", "c");
var v = await update.ReportPropertyAsync(dict, token);
return v;
}

public abstract Dictionary<string, object> ToJsonDict();
}
}

0 comments on commit 46cb0fe

Please sign in to comment.