Skip to content

Waterius #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ThinkingHome.Console/ThinkingHome.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<ProjectReference Include="..\ThinkingHome.Plugins.Timer\ThinkingHome.Plugins.Timer.csproj" />
<ProjectReference Include="..\ThinkingHome.Plugins.Scripts\ThinkingHome.Plugins.Scripts.csproj" />
<ProjectReference Include="..\ThinkingHome.Plugins.Scripts.WebApi\ThinkingHome.Plugins.Scripts.WebApi.csproj" />
<ProjectReference Include="..\ThinkingHome.Plugins.Waterius\ThinkingHome.Plugins.Waterius.csproj" />
<ProjectReference Include="..\ThinkingHome.Plugins.WebServer\ThinkingHome.Plugins.WebServer.csproj" />
<ProjectReference Include="..\ThinkingHome.Plugins.WebServer.UrlValidation\ThinkingHome.Plugins.WebServer.UrlValidation.csproj" />
<ProjectReference Include="..\ThinkingHome.Plugins.Cron\ThinkingHome.Plugins.Cron.csproj" />
Expand Down
3 changes: 3 additions & 0 deletions ThinkingHome.Console/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
"useSSL": false,
"disableCertificateValidation": true
},
"ThinkingHome.Plugins.Waterius.WateriusPlugin": {
"mqttTopic": "waterius/slon/"
},
"ThinkingHome.Plugins.Mqtt.MqttPlugin": {
"host": "localhost",
"port": 1883,
Expand Down
2 changes: 1 addition & 1 deletion ThinkingHome.Core.Plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class MyPlugin : PluginBase
{
private readonly OtherPlugin otherPlugin;

public PluginBase(OtherPlugin otherPlugin) {
public MyPlugin(OtherPlugin otherPlugin) {
// сохраняем полученный экземпляр плагина в поле своего плагина
this.otherPlugin = otherPlugin;
}
Expand Down
2 changes: 1 addition & 1 deletion ThinkingHome.Plugins.Tmp/ThinkingHome.Plugins.Tmp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<ProjectReference Include="../ThinkingHome.Plugins.Mqtt/ThinkingHome.Plugins.Mqtt.csproj"/>
<ProjectReference Include="../ThinkingHome.Plugins.Cron/ThinkingHome.Plugins.Cron.csproj"/>
<ProjectReference Include="../ThinkingHome.Plugins.TelegramBot\ThinkingHome.Plugins.TelegramBot.csproj"/>
<ProjectReference Include="..\ThinkingHome.Plugins.WebUi\ThinkingHome.Plugins.WebUi.csproj"/>
<ProjectReference Include="../ThinkingHome.Plugins.WebUi/ThinkingHome.Plugins.WebUi.csproj"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.1"/>
Expand Down
8 changes: 8 additions & 0 deletions ThinkingHome.Plugins.Waterius/Model/MeterData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace ThinkingHome.Plugins.Waterius.Model;

public class MeterData {
public Guid Id { get; set; }
public DateTime Date { get; set; }
public float Value0 { get; set; }
public float Value1 { get; set; }
}
24 changes: 24 additions & 0 deletions ThinkingHome.Plugins.Waterius/Model/Migrations/Migration01.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Data;
using ThinkingHome.Migrator.Framework;

namespace ThinkingHome.Plugins.Waterius.Model.Migrations;

[Migration(1)]
public class Migration01 : Migration
{

public override void Apply()
{
Database.AddTable("Waterius_MeterData",
new Column("Id", DbType.Guid, ColumnProperty.PrimaryKey),
new Column("Date", DbType.Date, ColumnProperty.NotNull),
new Column("Value0", DbType.Decimal, ColumnProperty.Null),
new Column("Value1", DbType.Decimal, ColumnProperty.Null)
);
}

public override void Revert()
{
Database.RemoveTable("Waterius_MeterData");
}
}
19 changes: 19 additions & 0 deletions ThinkingHome.Plugins.Waterius/ThinkingHome.Plugins.Waterius.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>ThinkingHome plugin that receives water meter readings and stores them in a database. The following device is used to interact with water meters https://waterius.ru</Description>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ThinkingHome.Core.Plugins\ThinkingHome.Core.Plugins.csproj" />
<ProjectReference Include="..\ThinkingHome.Plugins.Mqtt\ThinkingHome.Plugins.Mqtt.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="ThinkingHome.Migrator.Framework" Version="3.9.0" />
</ItemGroup>

</Project>
50 changes: 50 additions & 0 deletions ThinkingHome.Plugins.Waterius/WateriusPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.Text;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using ThinkingHome.Core.Plugins;
using ThinkingHome.Plugins.Database;
using ThinkingHome.Plugins.Mqtt;
using ThinkingHome.Plugins.Mqtt.DynamicConfiguration;
using ThinkingHome.Plugins.Waterius.Model;

namespace ThinkingHome.Plugins.Waterius;

public class WateriusPlugin : PluginBase {

[DbModelBuilder]
public void InitModel(ModelBuilder modelBuilder)
{
modelBuilder.Entity<MeterData>(cfg => cfg.ToTable("Waterius_MeterData"));
}

[ConfigureMqtt]
public void WateriusListeners(MqttConfigurationBuilder config)
{
config.RegisterListener(MqttTopic?.Trim('/') + "/#", HandleMqttMessage);
}

private void HandleMqttMessage(string topic, byte[] payload)
{
var str = Encoding.UTF8.GetString(payload);

Logger.LogInformation($"{topic}: {str}");
}
public string? MqttTopic => Configuration["mqttTopic"];

private readonly MqttPlugin mqttPlugin;

public WateriusPlugin(MqttPlugin mqttPlugin)
{
this.mqttPlugin = mqttPlugin;
}

public override void InitPlugin()
{
if (string.IsNullOrWhiteSpace(MqttTopic)) {
Logger.LogWarning("MQTT Topic is undefined");
}
else {
Logger.LogInformation("Listen to waterius in topic: {MqttTopic}...", MqttTopic);
}
}
}
15 changes: 15 additions & 0 deletions ThinkingHome.sln
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThinkingHome.Plugins.Telegr
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThinkingHome.Plugins.WebUi", "ThinkingHome.Plugins.WebUi\ThinkingHome.Plugins.WebUi.csproj", "{003AE996-5F8D-414E-A084-CB93B91D10B1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThinkingHome.Plugins.Waterius", "ThinkingHome.Plugins.Waterius\ThinkingHome.Plugins.Waterius.csproj", "{207620D4-55C5-4D8E-9463-3BDE0BA31A15}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -148,6 +150,18 @@ Global
{003AE996-5F8D-414E-A084-CB93B91D10B1}.Release|x64.Build.0 = Release|Any CPU
{003AE996-5F8D-414E-A084-CB93B91D10B1}.Release|x86.ActiveCfg = Release|Any CPU
{003AE996-5F8D-414E-A084-CB93B91D10B1}.Release|x86.Build.0 = Release|Any CPU
{207620D4-55C5-4D8E-9463-3BDE0BA31A15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{207620D4-55C5-4D8E-9463-3BDE0BA31A15}.Debug|Any CPU.Build.0 = Debug|Any CPU
{207620D4-55C5-4D8E-9463-3BDE0BA31A15}.Release|Any CPU.ActiveCfg = Release|Any CPU
{207620D4-55C5-4D8E-9463-3BDE0BA31A15}.Release|Any CPU.Build.0 = Release|Any CPU
{207620D4-55C5-4D8E-9463-3BDE0BA31A15}.Debug|x64.ActiveCfg = Debug|Any CPU
{207620D4-55C5-4D8E-9463-3BDE0BA31A15}.Debug|x64.Build.0 = Debug|Any CPU
{207620D4-55C5-4D8E-9463-3BDE0BA31A15}.Debug|x86.ActiveCfg = Debug|Any CPU
{207620D4-55C5-4D8E-9463-3BDE0BA31A15}.Debug|x86.Build.0 = Debug|Any CPU
{207620D4-55C5-4D8E-9463-3BDE0BA31A15}.Release|x64.ActiveCfg = Release|Any CPU
{207620D4-55C5-4D8E-9463-3BDE0BA31A15}.Release|x64.Build.0 = Release|Any CPU
{207620D4-55C5-4D8E-9463-3BDE0BA31A15}.Release|x86.ActiveCfg = Release|Any CPU
{207620D4-55C5-4D8E-9463-3BDE0BA31A15}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -169,6 +183,7 @@ Global
{CDCBFFD1-7FBD-496E-BD42-581F66BEB085} = {5DF04DCB-BC26-42FA-B7D6-CFC24963F1A8}
{960A9C44-3D0F-42F4-8F81-F89588EAC9E0} = {5DF04DCB-BC26-42FA-B7D6-CFC24963F1A8}
{003AE996-5F8D-414E-A084-CB93B91D10B1} = {5DF04DCB-BC26-42FA-B7D6-CFC24963F1A8}
{207620D4-55C5-4D8E-9463-3BDE0BA31A15} = {5DF04DCB-BC26-42FA-B7D6-CFC24963F1A8}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
Policies = $0
Expand Down