Skip to content

Commit 773ac2e

Browse files
authored
Merge pull request #97 from osmanhadzic/feature/implement-allow-unest-mapping
Implement allow unest mapping
2 parents cdd49a2 + 64fb3ce commit 773ac2e

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

AstarteDeviceSDKCSharp/Protocol/AstarteDevicePropertyInterface.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,25 @@ public void UnsetProperty(string path)
8484
throw new AstarteTransportException("No available transport");
8585
}
8686

87-
transport.SendIndividualValue(this, path, null);
87+
bool allowUnset = this.FindMappingInInterface(path).AllowUnset;
8888

89-
try
89+
if (allowUnset)
9090
{
91-
propertyStorage.RemoveStoredPath(GetInterfaceName(), path, GetMajorVersion());
91+
transport.SendIndividualValue(this, path, null);
92+
93+
try
94+
{
95+
propertyStorage.RemoveStoredPath(GetInterfaceName(), path, GetMajorVersion());
96+
}
97+
catch (AstartePropertyStorageException e)
98+
{
99+
throw new AstarteTransportException("Property storage failure", e);
100+
}
92101
}
93-
catch (AstartePropertyStorageException e)
102+
else
94103
{
95-
throw new AstarteTransportException("Property storage failure", e);
104+
throw new AstarteInvalidValueException(
105+
$"Unset operation not allowed for path {path}");
96106
}
97107
}
98108
}

AstarteDeviceSDKCSharp/Protocol/AstarteInterfaceMapping.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class AstarteInterfaceMapping
2727
public string? Path { get; set; }
2828
public Type? MapType { get; set; }
2929
public Type? PrimitiveArrayType { get; set; }
30+
public bool AllowUnset { get; set; } = false;
3031

3132
public static AstarteInterfaceMapping FromAstarteInterfaceMapping(Mapping astarteMapping)
3233
{
@@ -40,6 +41,7 @@ protected void ParseMappingFromAstarteInterface(Mapping astarteMappingObject)
4041
Path = astarteMappingObject.Endpoint;
4142
MapType = StringToCSharpType(astarteMappingObject.Type);
4243
PrimitiveArrayType = StringToPrimitiveArrayCSharpType(astarteMappingObject.Type);
44+
AllowUnset = astarteMappingObject.AllowUnset;
4345
}
4446

4547
public string? GetPath()

AstarteDeviceSDKCSharp/Protocol/AstarteInterfaceModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,8 @@ public class Mapping
7373
[JsonProperty("expiry")]
7474
public int? Expiry { get; set; }
7575

76+
[JsonProperty("allow_unset")]
77+
public bool AllowUnset { get; set; } = false;
78+
7679
}
7780
}

AstarteDeviceSDKExample/Resources/standard-interfaces/org.astarte-platform.genericsensors.AvailableSensors.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
"endpoint": "/%{sensor_id}/name",
1212
"type": "string",
1313
"description": "Sensor name.",
14+
"allow_unset": true,
1415
"doc": "An arbitrary sensor name."
1516
},
1617
{
1718
"endpoint": "/%{sensor_id}/unit",
1819
"type": "string",
1920
"description": "Sample data measurement unit.",
21+
"allow_unset": true,
2022
"doc": "SI unit such as m, kg, K, etc..."
2123
}
2224
]

0 commit comments

Comments
 (0)