bacnet-objects 0.12.0

BACnet object model: traits, database, and standard object types
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
use super::{ColorObject, ColorTemperatureObject};
use std::borrow::Cow;

use bacnet_types::enums::PropertyIdentifier as P;

use crate::property_metadata::{
    PropertyConformance::{Optional, RequiredRead},
    PropertyMetadata,
    PropertyWriteCapability::{Always, ReadOnly},
};

// Canonical effective rows for the Color pair (dispatch-first):
// - Color (type 63) and Color Temperature (type 64) come from Addendum
//   135-2020ca, which the 2020 PDF doesn't contain. The rows below haven't
//   been reconciled with the addendum's property tables (no issue), so no
//   conformance code is claimed from them. The codes mirror the
//   Accumulator/Elevator heritage pattern instead: served rows the dispatch
//   treats as core state carry the R-like RequiredRead code, secondary tuning
//   rows carry the O-like Optional code, and writability mirrors the write
//   arms exactly (Elevator precedent: a served row with a routed arm is
//   RequiredRead/Always, never an invented RequiredWrite without a table
//   basis).
// Order preserves each legacy projection; PROPERTY_LIST is appended so the
// projection helper omits it while required_properties keeps it. Only
// implemented rows are described: table rows the objects do not serve stay
// absent until dispatch exists.
// Object_Identifier, Object_Name, and Object_Type carry RequiredRead/ReadOnly
// (no network write route). Object_Name explicitly documents the denial: a
// rename falls through to WRITE_ACCESS_DENIED (neither object has a
// write_object_name arm). Description carries Optional with the routed
// CharacterString arm, so Optional/Always. Out_Of_Service carries
// RequiredRead with the routed Boolean arm, so RequiredRead/Always.
// Color Present_Value has no write arm (non-commandable, no priority array),
// so RequiredRead/ReadOnly. Color Color_Command (BACnetColorCommand arm, see
// command.rs) and Default_Fade_Time (Unsigned arm rejecting values above
// 86_400_000) are served rows with routed arms, so RequiredRead/Always.
// Color Temperature Present_Value carries the routed Unsigned arm
// (u64_to_u32 plus the min/max clamp, with no Out_Of_Service gate), so
// RequiredRead/Always; Color_Command likewise RequiredRead/Always.
// Default_Fade_Time on Color Temperature has no write arm — the asymmetry
// versus Color is preserved, not reconciled — so Optional/ReadOnly alongside
// the other secondary rows (Default_Color, Default_Color_Temperature,
// Default_Ramp_Rate, Default_Step_Increment, Reliability).
// Tracking_Value, Transition, In_Progress, Event_State, Status_Flags, and
// Min/Max_Pres_Value are heritage-R-like served rows with no write route, so
// RequiredRead/ReadOnly. Min/Max_Pres_Value read unknown while None, but the
// constructor sets both and no clearing API exists, so they are always
// readable in practice and stay static borrowed rows.
// Writability is Always, never WhenOutOfService: dispatch routes every write
// arm unconditionally (Color Temperature Present_Value included) and the
// suites pin in-service writes, so the metadata mirrors dispatch. Presence is
// None throughout: the implementation models no commandable,
// intrinsic-reporting, or paired-text gating on this family.
// The pair is not createable at runtime (the network factory builds only the
// eight analog/binary/multi-state input/output/value types, so the
// is_createable=false default holds) and remains deleteable (delete denies
// only Device and NetworkPort, so the is_deleteable=true default holds);
// neither needs an override. Array gating keeps the default: Property_List
// admits an index (BACnetARRAY) while every other served row rejects one. COV
// keeps its overrides: supports_cov=true on both objects, and the COV gating
// path (read_property plus supports_cov_property to supports_cov) never
// consults metadata.
const COLOR_BASE: &[PropertyMetadata] = &[
    PropertyMetadata::new(P::OBJECT_IDENTIFIER, RequiredRead, None, ReadOnly),
    PropertyMetadata::new(P::OBJECT_NAME, RequiredRead, None, ReadOnly),
    PropertyMetadata::new(P::DESCRIPTION, Optional, None, Always),
    PropertyMetadata::new(P::OBJECT_TYPE, RequiredRead, None, ReadOnly),
    PropertyMetadata::new(P::PRESENT_VALUE, RequiredRead, None, ReadOnly),
    PropertyMetadata::new(P::TRACKING_VALUE, RequiredRead, None, ReadOnly),
    PropertyMetadata::new(P::COLOR_COMMAND, RequiredRead, None, Always),
    PropertyMetadata::new(P::IN_PROGRESS, RequiredRead, None, ReadOnly),
    PropertyMetadata::new(P::DEFAULT_COLOR, Optional, None, ReadOnly),
    PropertyMetadata::new(P::DEFAULT_FADE_TIME, RequiredRead, None, Always),
    PropertyMetadata::new(P::TRANSITION, RequiredRead, None, ReadOnly),
    PropertyMetadata::new(P::STATUS_FLAGS, RequiredRead, None, ReadOnly),
    PropertyMetadata::new(P::EVENT_STATE, RequiredRead, None, ReadOnly),
    PropertyMetadata::new(P::OUT_OF_SERVICE, RequiredRead, None, Always),
    PropertyMetadata::new(P::RELIABILITY, Optional, None, ReadOnly),
    PropertyMetadata::new(P::PROPERTY_LIST, RequiredRead, None, ReadOnly),
];

const COLOR_TEMPERATURE_BASE: &[PropertyMetadata] = &[
    PropertyMetadata::new(P::OBJECT_IDENTIFIER, RequiredRead, None, ReadOnly),
    PropertyMetadata::new(P::OBJECT_NAME, RequiredRead, None, ReadOnly),
    PropertyMetadata::new(P::DESCRIPTION, Optional, None, Always),
    PropertyMetadata::new(P::OBJECT_TYPE, RequiredRead, None, ReadOnly),
    PropertyMetadata::new(P::PRESENT_VALUE, RequiredRead, None, Always),
    PropertyMetadata::new(P::TRACKING_VALUE, RequiredRead, None, ReadOnly),
    PropertyMetadata::new(P::COLOR_COMMAND, RequiredRead, None, Always),
    PropertyMetadata::new(P::IN_PROGRESS, RequiredRead, None, ReadOnly),
    PropertyMetadata::new(P::DEFAULT_COLOR_TEMPERATURE, Optional, None, ReadOnly),
    PropertyMetadata::new(P::DEFAULT_FADE_TIME, Optional, None, ReadOnly),
    PropertyMetadata::new(P::DEFAULT_RAMP_RATE, Optional, None, ReadOnly),
    PropertyMetadata::new(P::DEFAULT_STEP_INCREMENT, Optional, None, ReadOnly),
    PropertyMetadata::new(P::TRANSITION, RequiredRead, None, ReadOnly),
    PropertyMetadata::new(P::MIN_PRES_VALUE, RequiredRead, None, ReadOnly),
    PropertyMetadata::new(P::MAX_PRES_VALUE, RequiredRead, None, ReadOnly),
    PropertyMetadata::new(P::STATUS_FLAGS, RequiredRead, None, ReadOnly),
    PropertyMetadata::new(P::EVENT_STATE, RequiredRead, None, ReadOnly),
    PropertyMetadata::new(P::OUT_OF_SERVICE, RequiredRead, None, Always),
    PropertyMetadata::new(P::RELIABILITY, Optional, None, ReadOnly),
    PropertyMetadata::new(P::PROPERTY_LIST, RequiredRead, None, ReadOnly),
];

pub(super) fn for_color_object(_object: &ColorObject) -> Cow<'_, [PropertyMetadata]> {
    Cow::Borrowed(COLOR_BASE)
}

pub(super) fn for_color_temperature_object(
    _object: &ColorTemperatureObject,
) -> Cow<'_, [PropertyMetadata]> {
    Cow::Borrowed(COLOR_TEMPERATURE_BASE)
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::property_metadata::PropertyWriteCapability;
    use crate::traits::BACnetObject;
    use bacnet_types::enums::{ErrorClass, ErrorCode};
    use bacnet_types::error::Error;
    use bacnet_types::primitives::PropertyValue;
    use std::collections::HashSet;

    fn assert_error(error: Error, expected: ErrorCode) {
        assert!(
            matches!(error, Error::Protocol { class, code }
                if class == ErrorClass::PROPERTY.to_raw() as u32
                    && code == expected.to_raw() as u32),
            "expected {expected:?}, got {error:?}"
        );
    }

    fn assert_exact_sets(object: &dyn BACnetObject, all: &[P], required: &[P]) {
        let metadata = object.property_metadata();
        assert!(matches!(metadata, Cow::Borrowed(_)));
        assert_eq!(metadata.len(), all.len() + 1);
        assert_eq!(object.property_list().as_ref(), all);
        assert_eq!(object.required_properties().as_ref(), required);
        assert_eq!(
            metadata
                .iter()
                .map(|row| row.property_identifier)
                .collect::<HashSet<_>>()
                .len(),
            metadata.len()
        );
        assert!(!object.is_createable());
        assert!(object.is_deleteable());
        assert!(object.supports_cov());
        for row in metadata.iter() {
            assert_eq!(row.presence_condition, None);
            let expected = if required.contains(&row.property_identifier) {
                RequiredRead
            } else {
                Optional
            };
            assert_eq!(row.conformance, expected, "{:?}", row.property_identifier);
            object.read_property(row.property_identifier, None).unwrap();
        }
    }

    fn assert_indexed_property_list(object: &dyn BACnetObject, all: &[P]) {
        let wire: Vec<_> = all
            .iter()
            .filter(|&&p| !matches!(p, P::OBJECT_IDENTIFIER | P::OBJECT_NAME | P::OBJECT_TYPE))
            .map(|p| PropertyValue::Enumerated(p.to_raw()))
            .collect();
        assert!(object.is_array_property(P::PROPERTY_LIST));
        assert_eq!(
            object.read_property(P::PROPERTY_LIST, None).unwrap(),
            PropertyValue::List(wire.clone())
        );
        assert_eq!(
            object.read_property(P::PROPERTY_LIST, Some(0)).unwrap(),
            PropertyValue::Unsigned(wire.len() as u64)
        );
        for (index, value) in wire.iter().enumerate() {
            assert_eq!(
                object
                    .read_property(P::PROPERTY_LIST, Some(index as u32 + 1))
                    .unwrap(),
                *value
            );
        }
        for index in [wire.len() as u32 + 1, u32::MAX] {
            assert_error(
                object
                    .read_property(P::PROPERTY_LIST, Some(index))
                    .unwrap_err(),
                ErrorCode::INVALID_ARRAY_INDEX,
            );
        }
    }

    #[test]
    fn property_metadata_color_exact_sets_readable_rows_and_indexed_list() {
        let object = ColorObject::new(1, "CLR-1").unwrap();
        let all = [
            P::OBJECT_IDENTIFIER,
            P::OBJECT_NAME,
            P::DESCRIPTION,
            P::OBJECT_TYPE,
            P::PRESENT_VALUE,
            P::TRACKING_VALUE,
            P::COLOR_COMMAND,
            P::IN_PROGRESS,
            P::DEFAULT_COLOR,
            P::DEFAULT_FADE_TIME,
            P::TRANSITION,
            P::STATUS_FLAGS,
            P::EVENT_STATE,
            P::OUT_OF_SERVICE,
            P::RELIABILITY,
        ];
        let required = [
            P::OBJECT_IDENTIFIER,
            P::OBJECT_NAME,
            P::OBJECT_TYPE,
            P::PRESENT_VALUE,
            P::TRACKING_VALUE,
            P::COLOR_COMMAND,
            P::IN_PROGRESS,
            P::DEFAULT_FADE_TIME,
            P::TRANSITION,
            P::STATUS_FLAGS,
            P::EVENT_STATE,
            P::OUT_OF_SERVICE,
            P::PROPERTY_LIST,
        ];
        assert_exact_sets(&object, &all, &required);
        assert_indexed_property_list(&object, &all);
        // BACnetxyColor reads back as a two-REAL list at the D65 default.
        assert_eq!(
            object.read_property(P::PRESENT_VALUE, None).unwrap(),
            PropertyValue::List(vec![
                PropertyValue::Real(0.3127),
                PropertyValue::Real(0.3290),
            ])
        );
        assert_eq!(
            object.read_property(P::TRACKING_VALUE, None).unwrap(),
            PropertyValue::List(vec![
                PropertyValue::Real(0.3127),
                PropertyValue::Real(0.3290),
            ])
        );
        assert_eq!(
            object.read_property(P::DEFAULT_COLOR, None).unwrap(),
            PropertyValue::List(vec![
                PropertyValue::Real(0.3127),
                PropertyValue::Real(0.3290),
            ])
        );
        // Color_Command reads operation NONE until written.
        assert_eq!(
            object.read_property(P::COLOR_COMMAND, None).unwrap(),
            PropertyValue::ApplicationData(vec![0x09, 0x00])
        );
        // The xy lists are BACnetLIST-style productions, so an index is
        // rejected; Present_Value is scalar and likewise rejects one.
        assert!(!object.is_array_property(P::PRESENT_VALUE));
        assert!(!object.is_array_property(P::TRACKING_VALUE));
        assert!(!object.is_array_property(P::COLOR_COMMAND));
    }

    #[test]
    fn property_metadata_color_temperature_exact_sets_readable_rows_and_indexed_list() {
        let object = ColorTemperatureObject::new(1, "CT-1").unwrap();
        let all = [
            P::OBJECT_IDENTIFIER,
            P::OBJECT_NAME,
            P::DESCRIPTION,
            P::OBJECT_TYPE,
            P::PRESENT_VALUE,
            P::TRACKING_VALUE,
            P::COLOR_COMMAND,
            P::IN_PROGRESS,
            P::DEFAULT_COLOR_TEMPERATURE,
            P::DEFAULT_FADE_TIME,
            P::DEFAULT_RAMP_RATE,
            P::DEFAULT_STEP_INCREMENT,
            P::TRANSITION,
            P::MIN_PRES_VALUE,
            P::MAX_PRES_VALUE,
            P::STATUS_FLAGS,
            P::EVENT_STATE,
            P::OUT_OF_SERVICE,
            P::RELIABILITY,
        ];
        let required = [
            P::OBJECT_IDENTIFIER,
            P::OBJECT_NAME,
            P::OBJECT_TYPE,
            P::PRESENT_VALUE,
            P::TRACKING_VALUE,
            P::COLOR_COMMAND,
            P::IN_PROGRESS,
            P::TRANSITION,
            P::MIN_PRES_VALUE,
            P::MAX_PRES_VALUE,
            P::STATUS_FLAGS,
            P::EVENT_STATE,
            P::OUT_OF_SERVICE,
            P::PROPERTY_LIST,
        ];
        assert_exact_sets(&object, &all, &required);
        assert_indexed_property_list(&object, &all);
        assert_eq!(
            object.read_property(P::PRESENT_VALUE, None).unwrap(),
            PropertyValue::Unsigned(4000)
        );
        assert_eq!(
            object.read_property(P::TRACKING_VALUE, None).unwrap(),
            PropertyValue::Unsigned(4000)
        );
        // The constructor bounds are always readable in practice (no
        // clearing API exists to reach the None arm).
        assert_eq!(
            object.read_property(P::MIN_PRES_VALUE, None).unwrap(),
            PropertyValue::Unsigned(1000)
        );
        assert_eq!(
            object.read_property(P::MAX_PRES_VALUE, None).unwrap(),
            PropertyValue::Unsigned(30000)
        );
        assert_eq!(
            object
                .read_property(P::DEFAULT_COLOR_TEMPERATURE, None)
                .unwrap(),
            PropertyValue::Unsigned(4000)
        );
        assert!(!object.is_array_property(P::PRESENT_VALUE));
        assert!(!object.is_array_property(P::COLOR_COMMAND));
    }

    #[test]
    fn property_metadata_color_pair_write_capabilities_match_dispatch() {
        // Constructor paired with the properties it must accept writes for.
        type WriteCase = (fn() -> Box<dyn BACnetObject>, &'static [P]);
        let cases: [WriteCase; 2] = [
            (
                || Box::new(ColorObject::new(1, "CLR-1").unwrap()),
                &[
                    P::DESCRIPTION,
                    P::OUT_OF_SERVICE,
                    P::COLOR_COMMAND,
                    P::DEFAULT_FADE_TIME,
                ],
            ),
            (
                || Box::new(ColorTemperatureObject::new(1, "CT-1").unwrap()),
                &[
                    P::DESCRIPTION,
                    P::OUT_OF_SERVICE,
                    P::PRESENT_VALUE,
                    P::COLOR_COMMAND,
                ],
            ),
        ];
        for (make, writable) in cases {
            for out_of_service in [false, true] {
                let mut object = make();
                object
                    .write_property(
                        P::OUT_OF_SERVICE,
                        None,
                        PropertyValue::Boolean(out_of_service),
                        None,
                    )
                    .unwrap();
                let original = object.property_metadata().into_owned();
                for row in &original {
                    let p = row.property_identifier;
                    let capability = if writable.contains(&p) {
                        PropertyWriteCapability::Always
                    } else {
                        PropertyWriteCapability::ReadOnly
                    };
                    assert_eq!(row.write_capability, capability, "{p:?}");
                    assert_eq!(
                        object.is_writable_property(p),
                        capability.is_writable(),
                        "{p:?}"
                    );
                    // Color_Command reads NONE until written, and NONE can't
                    // be written, so write STOP instead.
                    let value = if p == P::COLOR_COMMAND {
                        PropertyValue::ApplicationData(vec![0x09, 0x06])
                    } else {
                        object.read_property(p, None).unwrap()
                    };
                    let result = object.write_property(p, None, value, None);
                    if capability.is_writable() {
                        result.unwrap();
                    } else {
                        assert_error(result.unwrap_err(), ErrorCode::WRITE_ACCESS_DENIED);
                    }
                }
                // Object_Name has no network write route: a rename falls
                // through to WRITE_ACCESS_DENIED even with a well-formed value.
                assert!(!object.is_writable_property(P::OBJECT_NAME));
                assert_error(
                    object
                        .write_property(
                            P::OBJECT_NAME,
                            None,
                            PropertyValue::CharacterString("renamed".into()),
                            None,
                        )
                        .unwrap_err(),
                    ErrorCode::WRITE_ACCESS_DENIED,
                );
                assert_eq!(object.property_metadata().as_ref(), original);
            }
        }
    }

    #[test]
    fn property_metadata_color_writes_store_with_fade_time_gate() {
        for out_of_service in [false, true] {
            let mut object = ColorObject::new(1, "CLR-1").unwrap();
            object
                .write_property(
                    P::OUT_OF_SERVICE,
                    None,
                    PropertyValue::Boolean(out_of_service),
                    None,
                )
                .unwrap();
            // Color_Command serves the command written: STOP.
            let command = PropertyValue::ApplicationData(vec![0x09, 0x06]);
            object
                .write_property(P::COLOR_COMMAND, None, command.clone(), None)
                .unwrap();
            assert_eq!(
                object.read_property(P::COLOR_COMMAND, None).unwrap(),
                command
            );
            // Default_Fade_Time stores Unsigned verbatim up to 86_400_000.
            object
                .write_property(
                    P::DEFAULT_FADE_TIME,
                    None,
                    PropertyValue::Unsigned(86_400_000),
                    None,
                )
                .unwrap();
            assert_eq!(
                object.read_property(P::DEFAULT_FADE_TIME, None).unwrap(),
                PropertyValue::Unsigned(86_400_000)
            );
            assert_error(
                object
                    .write_property(
                        P::DEFAULT_FADE_TIME,
                        None,
                        PropertyValue::Unsigned(86_400_001),
                        None,
                    )
                    .unwrap_err(),
                ErrorCode::VALUE_OUT_OF_RANGE,
            );
            assert_eq!(
                object.read_property(P::DEFAULT_FADE_TIME, None).unwrap(),
                PropertyValue::Unsigned(86_400_000)
            );
            // Mistyped values are rejected without changing state.
            for (p, value) in [
                (P::COLOR_COMMAND, PropertyValue::Unsigned(1)),
                (P::DEFAULT_FADE_TIME, PropertyValue::Real(1000.0)),
                (P::DESCRIPTION, PropertyValue::Unsigned(1)),
                (P::OUT_OF_SERVICE, PropertyValue::Unsigned(1)),
            ] {
                assert_error(
                    object.write_property(p, None, value, None).unwrap_err(),
                    ErrorCode::INVALID_DATA_TYPE,
                );
            }
            // Present_Value is non-commandable: even its own readback is
            // denied on write, in and out of service.
            assert!(!object.is_writable_property(P::PRESENT_VALUE));
            let present = object.read_property(P::PRESENT_VALUE, None).unwrap();
            assert_error(
                object
                    .write_property(P::PRESENT_VALUE, None, present, None)
                    .unwrap_err(),
                ErrorCode::WRITE_ACCESS_DENIED,
            );
            // Rows with no network write route deny even their readback.
            for p in [
                P::TRACKING_VALUE,
                P::DEFAULT_COLOR,
                P::TRANSITION,
                P::IN_PROGRESS,
                P::STATUS_FLAGS,
                P::EVENT_STATE,
                P::RELIABILITY,
            ] {
                let value = object.read_property(p, None).unwrap();
                assert_error(
                    object.write_property(p, None, value, None).unwrap_err(),
                    ErrorCode::WRITE_ACCESS_DENIED,
                );
                assert!(!object.is_writable_property(p));
            }
        }
    }

    #[test]
    fn property_metadata_color_temperature_writes_clamp_to_min_max() {
        for out_of_service in [false, true] {
            let mut object = ColorTemperatureObject::new(1, "CT-1").unwrap();
            object
                .write_property(
                    P::OUT_OF_SERVICE,
                    None,
                    PropertyValue::Boolean(out_of_service),
                    None,
                )
                .unwrap();
            // Boundary values round-trip in both states: no OOS gate.
            for value in [1000, 30000] {
                object
                    .write_property(P::PRESENT_VALUE, None, PropertyValue::Unsigned(value), None)
                    .unwrap();
                assert_eq!(
                    object.read_property(P::PRESENT_VALUE, None).unwrap(),
                    PropertyValue::Unsigned(value)
                );
                assert_eq!(
                    object.read_property(P::TRACKING_VALUE, None).unwrap(),
                    PropertyValue::Unsigned(value)
                );
            }
            // Outside the configured bounds the write is refused and both
            // readbacks keep the last stored value.
            for value in [999, 30001, u32::MAX as u64] {
                assert_error(
                    object
                        .write_property(
                            P::PRESENT_VALUE,
                            None,
                            PropertyValue::Unsigned(value),
                            None,
                        )
                        .unwrap_err(),
                    ErrorCode::VALUE_OUT_OF_RANGE,
                );
            }
            // Over-wide values that do not fit u32 are refused the same way.
            assert_error(
                object
                    .write_property(
                        P::PRESENT_VALUE,
                        None,
                        PropertyValue::Unsigned(0x1_0000_03E8),
                        None,
                    )
                    .unwrap_err(),
                ErrorCode::VALUE_OUT_OF_RANGE,
            );
            assert_eq!(
                object.read_property(P::PRESENT_VALUE, None).unwrap(),
                PropertyValue::Unsigned(30000)
            );
            // Color_Command serves the command written: STEP_UP_CCT.
            let command = PropertyValue::ApplicationData(vec![0x09, 0x04]);
            object
                .write_property(P::COLOR_COMMAND, None, command.clone(), None)
                .unwrap();
            assert_eq!(
                object.read_property(P::COLOR_COMMAND, None).unwrap(),
                command
            );
            // Mistyped values are rejected without changing state.
            for (p, value) in [
                (P::PRESENT_VALUE, PropertyValue::Real(4000.0)),
                (P::COLOR_COMMAND, PropertyValue::Unsigned(1)),
                (P::DESCRIPTION, PropertyValue::Unsigned(1)),
                (P::OUT_OF_SERVICE, PropertyValue::Unsigned(1)),
            ] {
                assert_error(
                    object.write_property(p, None, value, None).unwrap_err(),
                    ErrorCode::INVALID_DATA_TYPE,
                );
            }
            // Default rows have no network write route: even their readback
            // is denied on write (the Default_Fade_Time asymmetry versus
            // Color is preserved, not reconciled).
            for p in [
                P::DEFAULT_COLOR_TEMPERATURE,
                P::DEFAULT_FADE_TIME,
                P::DEFAULT_RAMP_RATE,
                P::DEFAULT_STEP_INCREMENT,
            ] {
                let value = object.read_property(p, None).unwrap();
                assert_error(
                    object.write_property(p, None, value, None).unwrap_err(),
                    ErrorCode::WRITE_ACCESS_DENIED,
                );
                assert!(!object.is_writable_property(p));
            }
        }
    }

    #[test]
    fn property_metadata_color_pair_unserved_rows_stay_unknown() {
        fn assert_unserved(object: &mut dyn BACnetObject, p: P) {
            assert!(!object.is_writable_property(p));
            assert_error(
                object.read_property(p, None).unwrap_err(),
                ErrorCode::UNKNOWN_PROPERTY,
            );
            assert_error(
                object
                    .write_property(p, None, PropertyValue::Null, None)
                    .unwrap_err(),
                ErrorCode::UNKNOWN_PROPERTY,
            );
        }

        // Neither object serves priority, command-value, or device rows.
        let mut color = ColorObject::new(1, "CLR-1").unwrap();
        assert_unserved(&mut color, P::PRIORITY_ARRAY);
        assert_unserved(&mut color, P::COV_INCREMENT);
        assert_unserved(&mut color, P::DEVICE_TYPE);
        let mut temperature = ColorTemperatureObject::new(1, "CT-1").unwrap();
        assert_unserved(&mut temperature, P::PRIORITY_ARRAY);
        assert_unserved(&mut temperature, P::COV_INCREMENT);
        assert_unserved(&mut temperature, P::DEVICE_TYPE);
    }
}