Skip to content

Commit eb4e910

Browse files
committed
New attributes implementation
1 parent db67e86 commit eb4e910

File tree

130 files changed

+6868
-6229
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+6868
-6229
lines changed

Generator/ClusterGenerator.cs

Lines changed: 156 additions & 144 deletions
Large diffs are not rendered by default.

Generator/GeneratorUtil.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,22 @@ namespace Generator
1616
{
1717
public class GeneratorUtil
1818
{
19-
public static string SanitizeName(string name, bool paramName = false)
19+
public static string SanitizeName(string name, bool paramName = false, bool trimSuffix = true, string? ensureSuffix = null)
2020
{
21-
if (name.EndsWith("struct", StringComparison.InvariantCultureIgnoreCase))
22-
name = name.Substring(0, name.Length - 6);
23-
if (name.EndsWith("enum", StringComparison.InvariantCultureIgnoreCase))
24-
name = name.Substring(0, name.Length - 4);
25-
if (name.EndsWith("bitmap", StringComparison.InvariantCultureIgnoreCase))
26-
name = name.Substring(0, name.Length - 6);
21+
if (name == "event")
22+
name = "@event";
23+
if (trimSuffix)
24+
{
25+
if (name.EndsWith("struct", StringComparison.InvariantCultureIgnoreCase))
26+
name = name.Substring(0, name.Length - 6);
27+
else if (name.EndsWith("enum", StringComparison.InvariantCultureIgnoreCase))
28+
name = name.Substring(0, name.Length - 4);
29+
else if (name.EndsWith("bitmap", StringComparison.InvariantCultureIgnoreCase))
30+
name = name.Substring(0, name.Length - 6);
31+
}
32+
else if (!name.EndsWith(ensureSuffix ?? string.Empty))
33+
name += ensureSuffix;
34+
2735
bool cap = !paramName;
2836
StringBuilder ret = new StringBuilder(name.Length);
2937
if (name.Length > 0 && Char.IsNumber(name[0]))

MatterDotNet/Clusters/Appliances/DishwasherAlarmCluster.cs

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using MatterDotNet.Protocol.Payloads;
1818
using MatterDotNet.Protocol.Sessions;
1919
using MatterDotNet.Protocol.Subprotocols;
20+
using System.Diagnostics.CodeAnalysis;
2021

2122
namespace MatterDotNet.Clusters.Appliances
2223
{
@@ -31,9 +32,24 @@ public class DishwasherAlarm : ClusterBase
3132
/// <summary>
3233
/// Attributes and commands for configuring the Dishwasher alarm.
3334
/// </summary>
34-
public DishwasherAlarm(ushort endPoint) : base(CLUSTER_ID, endPoint) { }
35+
[SetsRequiredMembers]
36+
public DishwasherAlarm(ushort endPoint) : this(CLUSTER_ID, endPoint) { }
3537
/// <inheritdoc />
36-
protected DishwasherAlarm(uint cluster, ushort endPoint) : base(cluster, endPoint) { }
38+
[SetsRequiredMembers]
39+
protected DishwasherAlarm(uint cluster, ushort endPoint) : base(cluster, endPoint) {
40+
Mask = new ReadAttribute<Alarm>(cluster, endPoint, 0) {
41+
Deserialize = x => (Alarm)DeserializeEnum(x)!
42+
};
43+
Latch = new ReadAttribute<Alarm>(cluster, endPoint, 1) {
44+
Deserialize = x => (Alarm)DeserializeEnum(x)!
45+
};
46+
State = new ReadAttribute<Alarm>(cluster, endPoint, 2) {
47+
Deserialize = x => (Alarm)DeserializeEnum(x)!
48+
};
49+
Supported = new ReadAttribute<Alarm>(cluster, endPoint, 3) {
50+
Deserialize = x => (Alarm)DeserializeEnum(x)!
51+
};
52+
}
3753

3854
#region Enums
3955
/// <summary>
@@ -56,29 +72,11 @@ public enum Alarm : uint {
5672
/// Nothing Set
5773
/// </summary>
5874
None = 0,
59-
/// <summary>
60-
/// Water inflow is abnormal
61-
/// </summary>
6275
InflowError = 0x0001,
63-
/// <summary>
64-
/// Water draining is abnormal
65-
/// </summary>
6676
DrainError = 0x0002,
67-
/// <summary>
68-
/// Door or door lock is abnormal
69-
/// </summary>
7077
DoorError = 0x0004,
71-
/// <summary>
72-
/// Unable to reach normal temperature
73-
/// </summary>
7478
TempTooLow = 0x0008,
75-
/// <summary>
76-
/// Temperature is too high
77-
/// </summary>
7879
TempTooHigh = 0x0010,
79-
/// <summary>
80-
/// Water level is abnormal
81-
/// </summary>
8280
WaterLevelError = 0x0020,
8381
}
8482
#endregion Enums
@@ -150,32 +148,24 @@ public async Task<bool> Supports(SecureSession session, Feature feature)
150148
}
151149

152150
/// <summary>
153-
/// Get the Mask attribute
151+
/// Mask Attribute
154152
/// </summary>
155-
public async Task<Alarm> GetMask(SecureSession session) {
156-
return (Alarm)await GetEnumAttribute(session, 0);
157-
}
153+
public required ReadAttribute<Alarm> Mask { get; init; }
158154

159155
/// <summary>
160-
/// Get the Latch attribute
156+
/// Latch Attribute
161157
/// </summary>
162-
public async Task<Alarm> GetLatch(SecureSession session) {
163-
return (Alarm)await GetEnumAttribute(session, 1);
164-
}
158+
public required ReadAttribute<Alarm> Latch { get; init; }
165159

166160
/// <summary>
167-
/// Get the State attribute
161+
/// State Attribute
168162
/// </summary>
169-
public async Task<Alarm> GetState(SecureSession session) {
170-
return (Alarm)await GetEnumAttribute(session, 2);
171-
}
163+
public required ReadAttribute<Alarm> State { get; init; }
172164

173165
/// <summary>
174-
/// Get the Supported attribute
166+
/// Supported Attribute
175167
/// </summary>
176-
public async Task<Alarm> GetSupported(SecureSession session) {
177-
return (Alarm)await GetEnumAttribute(session, 3);
178-
}
168+
public required ReadAttribute<Alarm> Supported { get; init; }
179169
#endregion Attributes
180170

181171
/// <inheritdoc />

MatterDotNet/Clusters/Appliances/LaundryDryerControlsCluster.cs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using MatterDotNet.Protocol.Parsers;
1616
using MatterDotNet.Protocol.Sessions;
17+
using System.Diagnostics.CodeAnalysis;
1718

1819
namespace MatterDotNet.Clusters.Appliances
1920
{
@@ -28,9 +29,24 @@ public class LaundryDryerControls : ClusterBase
2829
/// <summary>
2930
/// This cluster provides a way to access options associated with the operation of a laundry dryer device type.
3031
/// </summary>
31-
public LaundryDryerControls(ushort endPoint) : base(CLUSTER_ID, endPoint) { }
32+
[SetsRequiredMembers]
33+
public LaundryDryerControls(ushort endPoint) : this(CLUSTER_ID, endPoint) { }
3234
/// <inheritdoc />
33-
protected LaundryDryerControls(uint cluster, ushort endPoint) : base(cluster, endPoint) { }
35+
[SetsRequiredMembers]
36+
protected LaundryDryerControls(uint cluster, ushort endPoint) : base(cluster, endPoint) {
37+
SupportedDrynessLevels = new ReadAttribute<DrynessLevel[]>(cluster, endPoint, 0) {
38+
Deserialize = x => {
39+
FieldReader reader = new FieldReader((IList<object>)x!);
40+
DrynessLevel[] list = new DrynessLevel[reader.Count];
41+
for (int i = 0; i < reader.Count; i++)
42+
list[i] = (DrynessLevel)reader.GetUShort(i)!.Value;
43+
return list;
44+
}
45+
};
46+
SelectedDrynessLevel = new ReadWriteAttribute<DrynessLevel?>(cluster, endPoint, 1, true) {
47+
Deserialize = x => (DrynessLevel?)DeserializeEnum(x)
48+
};
49+
}
3450

3551
#region Enums
3652
/// <summary>
@@ -58,29 +74,14 @@ public enum DrynessLevel : byte {
5874

5975
#region Attributes
6076
/// <summary>
61-
/// Get the Supported Dryness Levels attribute
77+
/// Supported Dryness Levels Attribute
6278
/// </summary>
63-
public async Task<DrynessLevel[]> GetSupportedDrynessLevels(SecureSession session) {
64-
FieldReader reader = new FieldReader((IList<object>)(await GetAttribute(session, 0))!);
65-
DrynessLevel[] list = new DrynessLevel[reader.Count];
66-
for (int i = 0; i < reader.Count; i++)
67-
list[i] = (DrynessLevel)reader.GetUShort(i)!.Value;
68-
return list;
69-
}
79+
public required ReadAttribute<DrynessLevel[]> SupportedDrynessLevels { get; init; }
7080

7181
/// <summary>
72-
/// Get the Selected Dryness Level attribute
82+
/// Selected Dryness Level Attribute
7383
/// </summary>
74-
public async Task<DrynessLevel?> GetSelectedDrynessLevel(SecureSession session) {
75-
return (DrynessLevel?)await GetEnumAttribute(session, 1, true);
76-
}
77-
78-
/// <summary>
79-
/// Set the Selected Dryness Level attribute
80-
/// </summary>
81-
public async Task SetSelectedDrynessLevel (SecureSession session, DrynessLevel? value) {
82-
await SetAttribute(session, 1, value, true);
83-
}
84+
public required ReadWriteAttribute<DrynessLevel?> SelectedDrynessLevel { get; init; }
8485
#endregion Attributes
8586

8687
/// <inheritdoc />

MatterDotNet/Clusters/Appliances/LaundryWasherControlsCluster.cs

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using MatterDotNet.Protocol.Parsers;
1616
using MatterDotNet.Protocol.Sessions;
17+
using System.Diagnostics.CodeAnalysis;
1718

1819
namespace MatterDotNet.Clusters.Appliances
1920
{
@@ -28,9 +29,36 @@ public class LaundryWasherControls : ClusterBase
2829
/// <summary>
2930
/// This cluster supports remotely monitoring and controlling the different types of functionality available to a washing device, such as a washing machine.
3031
/// </summary>
31-
public LaundryWasherControls(ushort endPoint) : base(CLUSTER_ID, endPoint) { }
32+
[SetsRequiredMembers]
33+
public LaundryWasherControls(ushort endPoint) : this(CLUSTER_ID, endPoint) { }
3234
/// <inheritdoc />
33-
protected LaundryWasherControls(uint cluster, ushort endPoint) : base(cluster, endPoint) { }
35+
[SetsRequiredMembers]
36+
protected LaundryWasherControls(uint cluster, ushort endPoint) : base(cluster, endPoint) {
37+
SpinSpeeds = new ReadAttribute<string[]>(cluster, endPoint, 0) {
38+
Deserialize = x => {
39+
FieldReader reader = new FieldReader((IList<object>)x!);
40+
string[] list = new string[reader.Count];
41+
for (int i = 0; i < reader.Count; i++)
42+
list[i] = reader.GetString(i, false)!;
43+
return list;
44+
}
45+
};
46+
SpinSpeedCurrent = new ReadWriteAttribute<byte?>(cluster, endPoint, 1, true) {
47+
Deserialize = x => (byte?)(dynamic?)x
48+
};
49+
NumberOfRinses = new ReadWriteAttribute<NumberOfRinsesEnum>(cluster, endPoint, 2) {
50+
Deserialize = x => (NumberOfRinsesEnum)DeserializeEnum(x)!
51+
};
52+
SupportedRinses = new ReadAttribute<NumberOfRinsesEnum[]>(cluster, endPoint, 3) {
53+
Deserialize = x => {
54+
FieldReader reader = new FieldReader((IList<object>)x!);
55+
NumberOfRinsesEnum[] list = new NumberOfRinsesEnum[reader.Count];
56+
for (int i = 0; i < reader.Count; i++)
57+
list[i] = (NumberOfRinsesEnum)reader.GetUShort(i)!.Value;
58+
return list;
59+
}
60+
};
61+
}
3462

3563
#region Enums
3664
/// <summary>
@@ -51,7 +79,7 @@ public enum Feature {
5179
/// <summary>
5280
/// Number Of Rinses
5381
/// </summary>
54-
public enum NumberOfRinses : byte {
82+
public enum NumberOfRinsesEnum : byte {
5583
/// <summary>
5684
/// This laundry washer mode does not perform rinse cycles
5785
/// </summary>
@@ -94,54 +122,24 @@ public async Task<bool> Supports(SecureSession session, Feature feature)
94122
}
95123

96124
/// <summary>
97-
/// Get the Spin Speeds attribute
125+
/// Spin Speeds Attribute
98126
/// </summary>
99-
public async Task<string[]> GetSpinSpeeds(SecureSession session) {
100-
FieldReader reader = new FieldReader((IList<object>)(await GetAttribute(session, 0))!);
101-
string[] list = new string[reader.Count];
102-
for (int i = 0; i < reader.Count; i++)
103-
list[i] = reader.GetString(i, false)!;
104-
return list;
105-
}
127+
public required ReadAttribute<string[]> SpinSpeeds { get; init; }
106128

107129
/// <summary>
108-
/// Get the Spin Speed Current attribute
130+
/// Spin Speed Current Attribute
109131
/// </summary>
110-
public async Task<byte?> GetSpinSpeedCurrent(SecureSession session) {
111-
return (byte?)(dynamic?)await GetAttribute(session, 1, true);
112-
}
132+
public required ReadWriteAttribute<byte?> SpinSpeedCurrent { get; init; }
113133

114134
/// <summary>
115-
/// Set the Spin Speed Current attribute
135+
/// Number Of Rinses Attribute
116136
/// </summary>
117-
public async Task SetSpinSpeedCurrent (SecureSession session, byte? value) {
118-
await SetAttribute(session, 1, value, true);
119-
}
137+
public required ReadWriteAttribute<NumberOfRinsesEnum> NumberOfRinses { get; init; }
120138

121139
/// <summary>
122-
/// Get the Number Of Rinses attribute
140+
/// Supported Rinses Attribute
123141
/// </summary>
124-
public async Task<NumberOfRinses> GetNumberOfRinses(SecureSession session) {
125-
return (NumberOfRinses)await GetEnumAttribute(session, 2);
126-
}
127-
128-
/// <summary>
129-
/// Set the Number Of Rinses attribute
130-
/// </summary>
131-
public async Task SetNumberOfRinses (SecureSession session, NumberOfRinses value) {
132-
await SetAttribute(session, 2, value);
133-
}
134-
135-
/// <summary>
136-
/// Get the Supported Rinses attribute
137-
/// </summary>
138-
public async Task<NumberOfRinses[]> GetSupportedRinses(SecureSession session) {
139-
FieldReader reader = new FieldReader((IList<object>)(await GetAttribute(session, 3))!);
140-
NumberOfRinses[] list = new NumberOfRinses[reader.Count];
141-
for (int i = 0; i < reader.Count; i++)
142-
list[i] = (NumberOfRinses)reader.GetUShort(i)!.Value;
143-
return list;
144-
}
142+
public required ReadAttribute<NumberOfRinsesEnum[]> SupportedRinses { get; init; }
145143
#endregion Attributes
146144

147145
/// <inheritdoc />

0 commit comments

Comments
 (0)