Skip to content

Commit 76625e7

Browse files
committed
refactor: add lux
1 parent 1cc5f01 commit 76625e7

4 files changed

Lines changed: 39 additions & 16 deletions

File tree

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
Features__SendToInflux: 'true'
1010
KnxSender__Endpoint: http://functional-living-knx-sender:9001
1111
InfluxDb__Endpoint: http://functional-living-influx:9999
12-
InfluxDb_Token: ODWCQ0YnLUPb9Gw321z5ONnzoBSHpthbsdve3QLAxbPGl5ytcK0gMK9XjiAnmy5c7Iq0nIF3YDNyqTL0hVrn2A==
12+
InfluxDb__Token: JBU-kgjsFW2q9lKmklFgHaVSHs8kp1nff6iMUxg_Xuj-KeuuY2Dc2LFDfJ5HDDvbvWqQeSEeb5c62Flr9X6QVA==
1313
InfluxDb__Bucket: functional-living
1414
InfluxDb__Organisation: cumps
1515
InfluxDb__LogLevel: None
@@ -95,6 +95,7 @@ services:
9595

9696
volumes:
9797
influxdb:
98+
name: functional-living-influx
9899

99100
# docker exec -it influxdb /bin/bash
100101
# influx setup

src/FunctionalLiving/Knx/KnxCommandHandlerModule.cs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,13 @@ public KnxCommandHandlerModule(
109109
value);
110110

111111
if (sendToInflux.FeatureEnabled)
112-
WriteTemperature(
112+
Write(
113113
influxWrite,
114-
description,
115-
functionalTemp);
114+
new Temperature
115+
{
116+
Location = description,
117+
Value = functionalTemp
118+
});
116119
}
117120
else if (LightStrength.TryGetValue(groupAddress, out description))
118121
{
@@ -125,6 +128,15 @@ public KnxCommandHandlerModule(
125128
"LUX",
126129
description,
127130
value);
131+
132+
if (sendToInflux.FeatureEnabled)
133+
Write(
134+
influxWrite,
135+
new Lux
136+
{
137+
Location = description,
138+
Value = functionalLightStrength
139+
});
128140
}
129141
else if (Times.TryGetValue(groupAddress, out description))
130142
{
@@ -201,23 +213,15 @@ private static void Log(
201213
value);
202214
}
203215

204-
private static void WriteTemperature(
216+
private static void Write<T>(
205217
Func<WriteApi> writeApi,
206-
string location,
207-
double value)
218+
T measurement)
208219
{
209-
var temperature = new Temperature
210-
{
211-
Location = location,
212-
Value = value,
213-
Time = DateTime.UtcNow
214-
};
215-
216220
using (var writeClient = writeApi())
217221
{
218222
writeClient.WriteMeasurement(
219223
WritePrecision.Ns,
220-
temperature);
224+
measurement);
221225

222226
writeClient.Flush();
223227
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace FunctionalLiving.Measurements
2+
{
3+
using System;
4+
using InfluxDB.Client.Core;
5+
6+
[Measurement("lux")]
7+
public class Lux
8+
{
9+
[Column("location", IsTag = true)]
10+
public string Location { get; set; }
11+
12+
[Column("value")]
13+
public double Value { get; set; }
14+
15+
[Column(IsTimestamp = true)]
16+
public DateTime Time { get; set; } = DateTime.UtcNow;
17+
}
18+
}

src/FunctionalLiving/Measurements/Temperature.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ public class Temperature
1313
public double Value { get; set; }
1414

1515
[Column(IsTimestamp = true)]
16-
public DateTime Time;
16+
public DateTime Time { get; set; } = DateTime.UtcNow;
1717
}
1818
}

0 commit comments

Comments
 (0)