Skip to content

Commit c4586d1

Browse files
committed
Removing not allowed properties
1 parent 3a1a225 commit c4586d1

File tree

3 files changed

+313
-14
lines changed

3 files changed

+313
-14
lines changed

business/tsextractor/tsextractor.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func extractPropertyNameAndType(thing iotclient.ArduinoThing, propertyID string)
296296
}
297297

298298
func isStringProperty(ptype string) bool {
299-
return ptype == "CHARSTRING" || ptype == "LOCATION"
299+
return iot.IsPropertyString(ptype) || iot.IsPropertyLocation(ptype)
300300
}
301301

302302
func (a *TsExtractor) populateStringTSDataIntoS3(
@@ -460,6 +460,10 @@ func (a *TsExtractor) interfaceToString(value interface{}) string {
460460
}
461461
}
462462

463+
func isLastValueAllowedProperty(prop iotclient.ArduinoProperty) bool {
464+
return prop.UpdateStrategy == "ON_CHANGE" && (isStringProperty(prop.Type) || iot.IsPropertyBool(prop.Type) || iot.IsPropertyNumberType(prop.Type))
465+
}
466+
463467
func (a *TsExtractor) populateLastValueSamplesForOnChangeProperties(
464468
isRaw bool,
465469
thing iotclient.ArduinoThing,
@@ -473,15 +477,16 @@ func (a *TsExtractor) populateLastValueSamplesForOnChangeProperties(
473477
samples := [][]string{}
474478
sampleCount := 0
475479
for _, prop := range thing.Properties {
476-
if prop.UpdateStrategy == "ON_CHANGE" && !slices.Contains(propertiesWithExtractedValue, prop.Id) {
480+
if isLastValueAllowedProperty(prop) && !slices.Contains(propertiesWithExtractedValue, prop.Id) {
477481
if prop.ValueUpdatedAt == nil {
478482
continue
479483
}
484+
propName, propType := extractPropertyNameAndType(thing, prop.Id)
480485
var toAdd []string
481486
if isRaw {
482-
toAdd = composeRawRow(*prop.ValueUpdatedAt, thing.Id, thing.Name, prop.Id, prop.Name, prop.Type, a.interfaceToString(prop.LastValue))
487+
toAdd = composeRawRow(*prop.ValueUpdatedAt, thing.Id, thing.Name, prop.Id, propName, propType, a.interfaceToString(prop.LastValue))
483488
} else {
484-
toAdd = composeRow(*prop.ValueUpdatedAt, thing.Id, thing.Name, prop.Id, prop.Name, prop.Type, a.interfaceToString(prop.LastValue), "LAST_VALUE")
489+
toAdd = composeRow(*prop.ValueUpdatedAt, thing.Id, thing.Name, prop.Id, propName, propType, a.interfaceToString(prop.LastValue), "LAST_VALUE")
485490
}
486491
samples = append(samples, toAdd)
487492
sampleCount++

business/tsextractor/tsextractor_test.go

+20-10
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ func TestExtractionFlow_defaultAggregation(t *testing.T) {
125125
Type: "CHARSTRING",
126126
},
127127
{
128-
Name: "pOnChange",
129-
Id: propertyIdOnChange,
130-
Type: "FLOAT",
128+
Name: "pOnChange",
129+
Id: propertyIdOnChange,
130+
Type: "FLOAT",
131131
UpdateStrategy: "ON_CHANGE",
132-
LastValue: 2.34,
132+
LastValue: 2.34,
133133
ValueUpdatedAt: &lastValueTime,
134-
},
134+
},
135135
},
136136
PropertiesCount: &propCount,
137137
}
@@ -174,6 +174,7 @@ func TestExtractionFlow_rawResolution(t *testing.T) {
174174
propertyId := "c86f4ed9-7f52-4bd3-bdc6-b2936bec68ac"
175175
propertyStringId := "a86f4ed9-7f52-4bd3-bdc6-b2936bec68bb"
176176
propertyIdOnChange := "b77f4ed5-7f52-4bd3-bdc6-b2936bec12de"
177+
propertyIdNotImport := "b88f4ed5-7f52-4bd3-bdc6-b2936bec12de"
177178

178179
// Init client
179180
iotcl := iotMocks.NewAPI(t)
@@ -219,13 +220,21 @@ func TestExtractionFlow_rawResolution(t *testing.T) {
219220
Type: "CHARSTRING",
220221
},
221222
{
222-
Name: "pOnChange",
223-
Id: propertyIdOnChange,
224-
Type: "FLOAT",
223+
Name: "pOnChange",
224+
Id: propertyIdOnChange,
225+
Type: "FLOAT",
226+
UpdateStrategy: "ON_CHANGE",
227+
LastValue: 2.34,
228+
ValueUpdatedAt: &lastValueTime,
229+
},
230+
{
231+
Name: "pNOIMPORT",
232+
Id: propertyIdNotImport,
233+
Type: "SCHEDULER",
225234
UpdateStrategy: "ON_CHANGE",
226-
LastValue: 2.34,
235+
LastValue: "{}",
227236
ValueUpdatedAt: &lastValueTime,
228-
},
237+
},
229238
},
230239
PropertiesCount: &propCount,
231240
}
@@ -257,5 +266,6 @@ func TestExtractionFlow_rawResolution(t *testing.T) {
257266
}
258267
for _, entry := range entries {
259268
assert.Contains(t, string(content), entry)
269+
assert.NotContains(t, string(content), "pNOIMPORT")
260270
}
261271
}

internal/iot/types.go

+284
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,284 @@
1+
// This file is part of arduino aws-sitewise-integration.
2+
//
3+
// Copyright 2024 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the Mozilla Public License Version 2.0,
6+
// which covers the main part of aws-sitewise-integration.
7+
// The terms of this license can be found at:
8+
// https://www.mozilla.org/media/MPL/2.0/index.815ca599c9df.txt
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package iot
17+
18+
type Type string
19+
20+
const (
21+
Analog Type = "ANALOG"
22+
CharString Type = "CHARSTRING"
23+
Float Type = "FLOAT"
24+
Int Type = "INT"
25+
LenghtC Type = "LENGHT_C"
26+
LenghtI Type = "LENGHT_I"
27+
LenghtM Type = "LENGHT_M"
28+
Percentage Type = "PERCENTAGE"
29+
Status Type = "STATUS"
30+
TemperatureC Type = "TEMPERATURE_C"
31+
TemperatureF Type = "TEMPERATURE_F"
32+
Meter Type = "METER"
33+
Kilogram Type = "KILOGRAM"
34+
Gram Type = "GRAM"
35+
Second Type = "SECOND"
36+
Ampere Type = "AMPERE"
37+
Kelvin Type = "KELVIN"
38+
Candela Type = "CANDELA"
39+
Mole Type = "MOLE"
40+
Hertz Type = "HERTZ"
41+
Radian Type = "RADIAN"
42+
Steradian Type = "STERADIAN"
43+
Newton Type = "NEWTON"
44+
Pascal Type = "PASCAL"
45+
Joule Type = "JOULE"
46+
Watt Type = "WATT"
47+
Coulomb Type = "COULOMB"
48+
Volt Type = "VOLT"
49+
Farad Type = "FARAD"
50+
Ohm Type = "OHM"
51+
Siemens Type = "SIEMENS"
52+
Weber Type = "WEBER"
53+
Tesla Type = "TESLA"
54+
Henry Type = "HENRY"
55+
DegreesCelsius Type = "DEGREES_CELSIUS"
56+
Lumen Type = "LUMEN"
57+
Lux Type = "LUX"
58+
Becquerel Type = "BECQUEREL"
59+
Gray Type = "GRAY"
60+
Sievert Type = "SIEVERT"
61+
Katal Type = "KATAL"
62+
SquareMeter Type = "SQUARE_METER"
63+
CubicMeter Type = "CUBIC_METER"
64+
Liter Type = "LITER"
65+
MeterPerSecond Type = "METER_PER_SECOND"
66+
MeterPerSquareSecond Type = "METER_PER_SQUARE_SECOND"
67+
CubicMeterPerSecond Type = "CUBIC_METER_PER_SECOND"
68+
LiterPerSecond Type = "LITER_PER_SECOND"
69+
WattPerSquareMeter Type = "WATT_PER_SQUARE_METER"
70+
CandelaPerSquareMeter Type = "CANDELA_PER_SQUARE_METER"
71+
Bit Type = "BIT"
72+
BitPerSecond Type = "BIT_PER_SECOND"
73+
DegreesLatitude Type = "DEGREES_LATITUDE"
74+
DegreesLongitude Type = "DEGREES_LONGITUDE"
75+
PhValue Type = "PH_VALUE"
76+
Decibel Type = "DECIBEL"
77+
Decibel1w Type = "DECIBEL_1W"
78+
Bel Type = "BEL"
79+
Count Type = "COUNT"
80+
RatioDiv Type = "RATIO_DIV"
81+
RatioMod Type = "RATIO_MOD"
82+
PercentageRelativeHumidity Type = "PERCENTAGE_RELATIVE_HUMIDITY"
83+
PercentageBatteryLevel Type = "PERCENTAGE_BATTERY_LEVEL"
84+
SecondsBatteryLevel Type = "SECONDS_BATTERY_LEVEL"
85+
EventRateSecond Type = "EVENT_RATE_SECOND"
86+
EventRateMinute Type = "EVENT_RATE_MINUTE"
87+
HeartRate Type = "HEART_RATE"
88+
HeartBeats Type = "HEART_BEATS"
89+
SiemensPerMeter Type = "SIEMENS_PER_METER"
90+
// Complex properties
91+
Location Type = "LOCATION"
92+
ColorHSB Type = "COLOR_HSB"
93+
ColorRGB Type = "COLOR_RGB"
94+
GenericComplexProperty = "GENERIC_COMPLEX_PROPERTY"
95+
Schedule Type = "SCHEDULE"
96+
// Alexa Properties
97+
HomeColoredLight = "HOME_COLORED_LIGHT"
98+
HomeDimmedLight = "HOME_DIMMED_LIGHT"
99+
HomeLight Type = "HOME_LIGHT"
100+
HomeContactSensor = "HOME_CONTACT_SENSOR"
101+
HomeMotionSensor = "HOME_MOTION_SENSOR"
102+
HomeSmartPlugType = "HOME_SMART_PLUG"
103+
HomeTemperature = "HOME_TEMPERATURE"
104+
HomeTemperatureC = "HOME_TEMPERATURE_C"
105+
HomeTemperatureF = "HOME_TEMPERATURE_F"
106+
HomeSwitch Type = "HOME_SWITCH"
107+
HomeTelevision = "HOME_TELEVISION"
108+
// New Types based on dimensions
109+
Energy Type = "ENERGY"
110+
Force Type = "FORCE"
111+
Temperature Type = "TEMPERATURE"
112+
Power Type = "POWER"
113+
ElectricCurrent Type = "ELECTRIC_CURRENT"
114+
ElectricPotential = "ELECTRIC_POTENTIAL"
115+
ElectricalResistance = "ELECTRICAL_RESISTANCE"
116+
Capacitance Type = "CAPACITANCE"
117+
Time Type = "TIME"
118+
Frequency Type = "FREQUENCY"
119+
DataRate Type = "DATA_RATE"
120+
Acceleration Type = "ACCELERATION"
121+
Area Type = "AREA"
122+
Length Type = "LENGTH"
123+
Velocity Type = "VELOCITY"
124+
Mass Type = "MASS"
125+
Volume Type = "VOLUME"
126+
FlowRate Type = "FLOW_RATE"
127+
Angle Type = "ANGLE"
128+
Illuminance Type = "ILLUMINANCE"
129+
LuminousFlux Type = "LUMINOUS_FLUX"
130+
Luminance Type = "LUMINANCE"
131+
LuminousIntensity = "LUMINOUS_INTENSITY"
132+
LogarithmicQuantity = "LOGARITHMIC_QUANTITY"
133+
Pressure Type = "PRESSURE"
134+
InformationContent = "INFORMATION_CONTENT"
135+
)
136+
137+
var floatPropertyTypes = []Type{
138+
Analog,
139+
Float,
140+
LenghtC,
141+
LenghtI,
142+
LenghtM,
143+
Percentage,
144+
TemperatureC,
145+
TemperatureF,
146+
Meter,
147+
Kilogram,
148+
Gram,
149+
Second,
150+
Ampere,
151+
Kelvin,
152+
Candela,
153+
Mole,
154+
Hertz,
155+
Radian,
156+
Steradian,
157+
Newton,
158+
Pascal,
159+
Joule,
160+
Watt,
161+
Coulomb,
162+
Volt,
163+
Farad,
164+
Ohm,
165+
Siemens,
166+
Weber,
167+
Tesla,
168+
Henry,
169+
DegreesCelsius,
170+
Lumen,
171+
Lux,
172+
Becquerel,
173+
Gray,
174+
Sievert,
175+
Katal,
176+
SquareMeter,
177+
CubicMeter,
178+
Liter,
179+
MeterPerSecond,
180+
MeterPerSquareSecond,
181+
CubicMeterPerSecond,
182+
LiterPerSecond,
183+
WattPerSquareMeter,
184+
CandelaPerSquareMeter,
185+
Bit,
186+
BitPerSecond,
187+
DegreesLatitude,
188+
DegreesLongitude,
189+
PhValue,
190+
Decibel,
191+
Decibel1w,
192+
Bel,
193+
RatioDiv,
194+
RatioMod,
195+
PercentageRelativeHumidity,
196+
PercentageBatteryLevel,
197+
SecondsBatteryLevel,
198+
EventRateSecond,
199+
EventRateMinute,
200+
HeartRate,
201+
HeartBeats,
202+
SiemensPerMeter,
203+
HomeTemperature,
204+
HomeTemperatureC,
205+
HomeTemperatureF,
206+
Energy,
207+
Force,
208+
Temperature,
209+
Power,
210+
ElectricCurrent,
211+
ElectricPotential,
212+
ElectricalResistance,
213+
Capacitance,
214+
Frequency,
215+
DataRate,
216+
Acceleration,
217+
Area,
218+
Length,
219+
Velocity,
220+
Mass,
221+
Volume,
222+
FlowRate,
223+
Angle,
224+
Illuminance,
225+
LuminousFlux,
226+
Luminance,
227+
LuminousIntensity,
228+
LogarithmicQuantity,
229+
Pressure,
230+
}
231+
232+
var intPropertyTypes = []Type{
233+
Int,
234+
Count,
235+
Time,
236+
InformationContent,
237+
}
238+
239+
var booleanPropertyTypes = []Type{
240+
Status,
241+
HomeLight,
242+
HomeSwitch,
243+
HomeContactSensor,
244+
HomeMotionSensor,
245+
}
246+
247+
func IsPropertyFloat(pType string) bool {
248+
for _, tpy := range floatPropertyTypes {
249+
if pType == string(tpy) {
250+
return true
251+
}
252+
}
253+
return false
254+
}
255+
256+
func IsPropertyInt(pType string) bool {
257+
for _, tpy := range intPropertyTypes {
258+
if pType == string(tpy) {
259+
return true
260+
}
261+
}
262+
return false
263+
}
264+
265+
func IsPropertyNumberType(pType string) bool {
266+
return IsPropertyFloat(pType) || IsPropertyInt(pType)
267+
}
268+
269+
func IsPropertyString(pType string) bool {
270+
return pType == "CHARSTRING"
271+
}
272+
273+
func IsPropertyLocation(pType string) bool {
274+
return Type(pType) == Location
275+
}
276+
277+
func IsPropertyBool(pType string) bool {
278+
for _, tpy := range booleanPropertyTypes {
279+
if pType == string(tpy) {
280+
return true
281+
}
282+
}
283+
return false
284+
}

0 commit comments

Comments
 (0)