@@ -41,40 +41,47 @@ def pics_TC_TIMESYNC_2_1(self) -> list[str]:
41
41
42
42
@async_test_body
43
43
async def test_TC_TIMESYNC_2_1 (self ):
44
+ endpoint = 0
44
45
45
- endpoint = self .user_params .get ("endpoint" , 0 )
46
+ features = await self .read_single_attribute (dev_ctrl = self .default_controller , node_id = self .dut_node_id ,
47
+ endpoint = endpoint , attribute = Clusters .TimeSynchronization .Attributes .FeatureMap )
48
+
49
+ self .supports_time_zone = bool (features & Clusters .TimeSynchronization .Bitmaps .Feature .kTimeZone )
50
+ self .supports_ntpc = bool (features & Clusters .TimeSynchronization .Bitmaps .Feature .kNTPClient )
51
+ self .supports_ntps = bool (features & Clusters .TimeSynchronization .Bitmaps .Feature .kNTPServer )
52
+ self .supports_trusted_time_source = bool (features & Clusters .TimeSynchronization .Bitmaps .Feature .kTimeSyncClient )
53
+
54
+ time_cluster = Clusters .TimeSynchronization
55
+ timesync_attr_list = time_cluster .Attributes .AttributeList
56
+ attribute_list = await self .read_single_attribute_check_success (endpoint = endpoint , cluster = time_cluster , attribute = timesync_attr_list )
57
+ timesource_attr_id = time_cluster .Attributes .TimeSource .attribute_id
46
58
47
59
self .print_step (1 , "Commissioning, already done" )
48
60
attributes = Clusters .TimeSynchronization .Attributes
49
61
50
62
self .print_step (2 , "Read Granularity attribute" )
51
- if self .check_pics ("TIMESYNC.S.A0001" ):
52
- granularity_dut = await self .read_ts_attribute_expect_success (endpoint = endpoint , attribute = attributes .Granularity )
53
- asserts .assert_less (granularity_dut , Clusters .TimeSynchronization .Enums .GranularityEnum .kUnknownEnumValue ,
54
- "Granularity is not in valid range" )
55
- else :
56
- asserts .assert_true (False , "Granularity is a mandatory attribute and must be present in the PICS file" )
63
+ granularity_dut = await self .read_ts_attribute_expect_success (endpoint = endpoint , attribute = attributes .Granularity )
64
+ asserts .assert_less (granularity_dut , Clusters .TimeSynchronization .Enums .GranularityEnum .kUnknownEnumValue ,
65
+ "Granularity is not in valid range" )
57
66
58
67
self .print_step (3 , "Read TimeSource" )
59
- if self . check_pics ( "TIMESYNC.S.A0002" ) :
68
+ if timesource_attr_id in attribute_list :
60
69
time_source = await self .read_ts_attribute_expect_success (endpoint = endpoint , attribute = attributes .TimeSource )
61
70
asserts .assert_less (time_source , Clusters .TimeSynchronization .Enums .TimeSourceEnum .kUnknownEnumValue ,
62
71
"TimeSource is not in valid range" )
63
72
64
73
self .print_step (4 , "Read TrustedTimeSource" )
65
- if self .check_pics ( "TIMESYNC.S.A0003" ) :
74
+ if self .supports_trusted_time_source :
66
75
trusted_time_source = await self .read_ts_attribute_expect_success (endpoint = endpoint ,
67
76
attribute = attributes .TrustedTimeSource )
68
77
if trusted_time_source is not NullValue :
69
78
asserts .assert_less_equal (trusted_time_source .fabricIndex , 0xFE ,
70
79
"FabricIndex for the TrustedTimeSource is out of range" )
71
80
asserts .assert_greater_equal (trusted_time_source .fabricIndex , 1 ,
72
81
"FabricIndex for the TrustedTimeSource is out of range" )
73
- elif self .check_pics ("TIMESYNC.S.F03" ):
74
- asserts .assert_true (False , "TrustedTimeSource is mandatory if the TSC feature (TIMESYNC.S.F03) is supported" )
75
82
76
83
self .print_step (5 , "Read DefaultNTP" )
77
- if self .check_pics ( "TIMESYNC.S.A0004" ) :
84
+ if self .supports_ntpc :
78
85
default_ntp = await self .read_ts_attribute_expect_success (endpoint = endpoint , attribute = attributes .DefaultNTP )
79
86
if default_ntp is not NullValue :
80
87
asserts .assert_less_equal (len (default_ntp ), 128 , "DefaultNTP length must be less than 128" )
@@ -87,11 +94,9 @@ async def test_TC_TIMESYNC_2_1(self):
87
94
is_ip_addr = False
88
95
pass
89
96
asserts .assert_true (is_web_addr or is_ip_addr , "Returned DefaultNTP value is not a IP address or web address" )
90
- elif self .check_pics ("TIMESYNC.S.F01" ):
91
- asserts .assert_true (False , "DefaultNTP is mandatory if the NTPC (TIMESYNC.S.F01) feature is supported" )
92
97
93
98
self .print_step (6 , "Read TimeZone" )
94
- if self .check_pics ( "TIMESYNC.S.A0005" ) :
99
+ if self .supports_time_zone :
95
100
tz_dut = await self .read_ts_attribute_expect_success (endpoint = endpoint , attribute = attributes .TimeZone )
96
101
asserts .assert_greater_equal (len (tz_dut ), 1 , "TimeZone must have at least one entry in the list" )
97
102
asserts .assert_less_equal (len (tz_dut ), 2 , "TimeZone may have a maximum of two entries in the list" )
@@ -104,11 +109,9 @@ async def test_TC_TIMESYNC_2_1(self):
104
109
asserts .assert_equal (tz_dut [0 ].validAt , 0 , "TimeZone list first entry must have a 0 ValidAt time" )
105
110
if len (tz_dut ) > 1 :
106
111
asserts .assert_not_equal (tz_dut [1 ].validAt , 0 , "TimeZone list second entry must have a non-zero ValidAt time" )
107
- elif self .check_pics ("TIMESYNC.S.F00" ):
108
- asserts .assert_true (False , "TimeZone is mandatory if the TZ (TIMESYNC.S.F00) feature is supported" )
109
112
110
113
self .print_step (7 , "Read DSTOffset" )
111
- if self .check_pics ( "TIMESYNC.S.A0006" ) :
114
+ if self .supports_time_zone :
112
115
dst_dut = await self .read_ts_attribute_expect_success (endpoint = endpoint , attribute = attributes .DSTOffset )
113
116
last_valid_until = - 1
114
117
last_valid_starting = - 1
@@ -121,28 +124,23 @@ async def test_TC_TIMESYNC_2_1(self):
121
124
last_valid_until = dst .validUntil
122
125
if dst .validUntil is NullValue or dst .validUntil is None :
123
126
asserts .assert_equal (dst , dst_dut [- 1 ], "DSTOffset list must have Null ValidUntil at the end" )
124
- elif self .check_pics ("TIMESYNC.S.F00" ):
125
- asserts .assert_true (False , "DSTOffset is mandatory if the TZ (TIMESYNC.S.F00) feature is supported" )
126
127
127
128
self .print_step (8 , "Read UTCTime" )
128
- if self .check_pics ("TIMESYNC.S.A0000" ):
129
- utc_dut = await self .read_ts_attribute_expect_success (endpoint = endpoint , attribute = attributes .UTCTime )
130
- if utc_dut is NullValue :
131
- asserts .assert_equal (granularity_dut , Clusters .TimeSynchronization .Enums .GranularityEnum .kNoTimeGranularity )
132
- else :
133
- asserts .assert_not_equal (granularity_dut , Clusters .TimeSynchronization .Enums .GranularityEnum .kNoTimeGranularity )
134
- if granularity_dut is Clusters .TimeSynchronization .Enums .GranularityEnum .kMinutesGranularity :
135
- toleranace = timedelta (minutes = 10 )
136
- else :
137
- toleranace = timedelta (minutes = 1 )
138
- delta_us = abs (utc_dut - utc_time_in_matter_epoch ())
139
- delta = timedelta (microseconds = delta_us )
140
- asserts .assert_less_equal (delta , toleranace , "UTC time is not within tolerance of TH" )
129
+ utc_dut = await self .read_ts_attribute_expect_success (endpoint = endpoint , attribute = attributes .UTCTime )
130
+ if utc_dut is NullValue :
131
+ asserts .assert_equal (granularity_dut , Clusters .TimeSynchronization .Enums .GranularityEnum .kNoTimeGranularity )
141
132
else :
142
- asserts .assert_true (False , "UTCTime is a mandatory attribute and must be present in the PICS file" )
133
+ asserts .assert_not_equal (granularity_dut , Clusters .TimeSynchronization .Enums .GranularityEnum .kNoTimeGranularity )
134
+ if granularity_dut is Clusters .TimeSynchronization .Enums .GranularityEnum .kMinutesGranularity :
135
+ toleranace = timedelta (minutes = 10 )
136
+ else :
137
+ toleranace = timedelta (minutes = 1 )
138
+ delta_us = abs (utc_dut - utc_time_in_matter_epoch ())
139
+ delta = timedelta (microseconds = delta_us )
140
+ asserts .assert_less_equal (delta , toleranace , "UTC time is not within tolerance of TH" )
143
141
144
142
self .print_step (9 , "Read LocalTime" )
145
- if self .check_pics ( "TIMESYNC.S.A0007" ) :
143
+ if self .supports_time_zone :
146
144
utc_dut = await self .read_ts_attribute_expect_success (endpoint = endpoint , attribute = attributes .UTCTime )
147
145
local_dut = await self .read_ts_attribute_expect_success (endpoint = endpoint , attribute = attributes .LocalTime )
148
146
if utc_dut is NullValue :
@@ -155,45 +153,33 @@ async def test_TC_TIMESYNC_2_1(self):
155
153
delta = timedelta (microseconds = delta_us )
156
154
toleranace = timedelta (minutes = 1 )
157
155
asserts .assert_less_equal (delta , toleranace , "Local time caluclation is not within tolerance of calculated value" )
158
- elif self .check_pics ("TIMESYNC.S.F00" ):
159
- asserts .assert_true (False , "LocalTime is mandatory if the TZ (TIMESYNC.S.F00) feature is supported" )
160
156
161
157
self .print_step (10 , "Read TimeZoneDatabase" )
162
- if self .check_pics ( "TIMESYNC.S.A0008" ) :
158
+ if self .supports_time_zone :
163
159
tz_db_dut = await self .read_ts_attribute_expect_success (endpoint = endpoint , attribute = attributes .TimeZoneDatabase )
164
160
asserts .assert_less (tz_db_dut , Clusters .TimeSynchronization .Enums .TimeZoneDatabaseEnum .kUnknownEnumValue ,
165
161
"TimeZoneDatabase is not in valid range" )
166
- elif self .check_pics ("TIMESYNC.S.F00" ):
167
- asserts .assert_true (False , "TimeZoneDatabase is mandatory if the TZ (TIMESYNC.S.F00) feature is supported" )
168
162
169
163
self .print_step (11 , "Read NTPServerAvailable" )
170
- if self .check_pics ( "TIMESYNC.S.A0009" ) :
164
+ if self .supports_ntps :
171
165
# bool typechecking happens in the test read functions, so all we need to do here is do the read
172
166
await self .read_ts_attribute_expect_success (endpoint = endpoint , attribute = attributes .NTPServerAvailable )
173
- elif self .check_pics ("TIMESYNC.S.F02" ):
174
- asserts .assert_true (False , "NTPServerAvailable is mandatory if the NTPS (TIMESYNC.S.F02) feature is supported" )
175
167
176
168
self .print_step (12 , "Read TimeZoneListMaxSize" )
177
- if self .check_pics ( "TIMESYNC.S.A000a" ) :
169
+ if self .supports_time_zone :
178
170
size = await self .read_ts_attribute_expect_success (endpoint = endpoint , attribute = attributes .TimeZoneListMaxSize )
179
171
asserts .assert_greater_equal (size , 1 , "TimeZoneListMaxSize must be at least 1" )
180
172
asserts .assert_less_equal (size , 2 , "TimeZoneListMaxSize must be max 2" )
181
- elif self .check_pics ("TIMESYNC.S.F00" ):
182
- asserts .assert_true (False , "TimeZoneListMaxSize is mandatory if the TZ (TIMESYNC.S.F00) feature is supported" )
183
173
184
174
self .print_step (13 , "Read DSTOffsetListMaxSize" )
185
- if self .check_pics ( "TIMESYNC.S.A000b" ) :
175
+ if self .supports_time_zone :
186
176
size = await self .read_ts_attribute_expect_success (endpoint = endpoint , attribute = attributes .DSTOffsetListMaxSize )
187
177
asserts .assert_greater_equal (size , 1 , "DSTOffsetListMaxSize must be at least 1" )
188
- elif self .check_pics ("TIMESYNC.S.F00" ):
189
- asserts .assert_true (False , "DSTOffsetListMaxSize is mandatory if the TZ (TIMESYNC.S.F00) feature is supported" )
190
178
191
179
self .print_step (14 , "Read SupportsDNSResolve" )
192
- if self . check_pics ( "TIMESYNC.S.A0004" ):
193
- # bool typechecking happens in the test read functions, so all we need to do here is do the read
180
+ # bool typechecking happens in the test read functions, so all we need to do here is do the read
181
+ if self . supports_ntpc :
194
182
await self .read_ts_attribute_expect_success (endpoint = endpoint , attribute = attributes .SupportsDNSResolve )
195
- elif self .check_pics ("TIMESYNC.S.F01" ):
196
- asserts .assert_true (False , "SupportsDNSResolve is mandatory if the NTPC (TIMESYNC.S.F01) feature is supported" )
197
183
198
184
199
185
if __name__ == "__main__" :
0 commit comments