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
use crate::{
service::{HapService, Service},
characteristic::{
HapCharacteristic,
identify,
manufacturer,
model,
name,
serial_number,
firmware_revision,
hardware_revision,
accessory_flags,
},
HapType,
};
pub type AccessoryInformation = Service<AccessoryInformationInner>;
impl Default for AccessoryInformation {
fn default() -> AccessoryInformation { new() }
}
#[derive(Default)]
pub struct AccessoryInformationInner {
id: u64,
hap_type: HapType,
hidden: bool,
primary: bool,
pub identify: identify::Identify,
pub manufacturer: manufacturer::Manufacturer,
pub model: model::Model,
pub name: name::Name,
pub serial_number: serial_number::SerialNumber,
pub firmware_revision: firmware_revision::FirmwareRevision,
pub hardware_revision: Option<hardware_revision::HardwareRevision>,
pub accessory_flags: Option<accessory_flags::AccessoryFlags>,
}
impl HapService for AccessoryInformationInner {
fn get_id(&self) -> u64 {
self.id
}
fn set_id(&mut self, id: u64) {
self.id = id;
}
fn get_type(&self) -> HapType {
self.hap_type
}
fn get_hidden(&self) -> bool {
self.hidden
}
fn set_hidden(&mut self, hidden: bool) {
self.hidden = hidden;
}
fn get_primary(&self) -> bool {
self.primary
}
fn set_primary(&mut self, primary: bool) {
self.primary = primary;
}
fn get_characteristics(&self) -> Vec<&HapCharacteristic> {
let mut characteristics: Vec<&HapCharacteristic> = vec![
&self.identify,
&self.manufacturer,
&self.model,
&self.name,
&self.serial_number,
&self.firmware_revision,
];
if let Some(c) = &self.hardware_revision {
characteristics.push(c);
}
if let Some(c) = &self.accessory_flags {
characteristics.push(c);
}
characteristics
}
fn get_mut_characteristics(&mut self) -> Vec<&mut HapCharacteristic> {
let mut characteristics: Vec<&mut HapCharacteristic> = vec![
&mut self.identify,
&mut self.manufacturer,
&mut self.model,
&mut self.name,
&mut self.serial_number,
&mut self.firmware_revision,
];
if let Some(c) = &mut self.hardware_revision {
characteristics.push(c);
}
if let Some(c) = &mut self.accessory_flags {
characteristics.push(c);
}
characteristics
}
}
pub fn new() -> AccessoryInformation {
AccessoryInformation::new(AccessoryInformationInner {
hap_type: HapType::AccessoryInformation,
identify: identify::new(),
manufacturer: manufacturer::new(),
model: model::new(),
name: name::new(),
serial_number: serial_number::new(),
firmware_revision: firmware_revision::new(),
..Default::default()
})
}