@@ -33,9 +33,16 @@ pub enum Type {
33
33
/// has reached 0 or that a device is ready.
34
34
Unit ,
35
35
36
- /// A boolean. Used for instance for on-off switches, presence
37
- /// detectors, etc.
38
- Bool ,
36
+ ///
37
+ /// # Boolean values
38
+ ///
39
+
40
+ /// A boolean on/off state. Used for various two-states switches.
41
+ OnOff ,
42
+
43
+ /// A boolean open/closed state. Used for instance for doors,
44
+ /// windows, etc.
45
+ OpenClosed ,
39
46
40
47
///
41
48
/// # Time
@@ -56,6 +63,8 @@ pub enum Type {
56
63
Color ,
57
64
Json ,
58
65
Binary ,
66
+
67
+ ExtBool ,
59
68
ExtNumeric ,
60
69
}
61
70
@@ -67,11 +76,68 @@ impl Type {
67
76
use self :: Type :: * ;
68
77
match * self {
69
78
Duration | TimeStamp | Temperature | ExtNumeric | Color => false ,
70
- Unit | Bool | String | Json | Binary => true ,
79
+ Unit | String | Json | Binary | OnOff | OpenClosed | ExtBool => true ,
80
+ }
81
+ }
82
+ }
83
+
84
+ /// An on/off state. Internal representation may be either On or Off.
85
+ #[ derive( Debug , Clone , Eq , PartialEq , Serialize , Deserialize ) ]
86
+ pub enum OnOff {
87
+ On ,
88
+ Off ,
89
+ }
90
+
91
+ impl OnOff {
92
+ fn as_bool ( & self ) -> bool {
93
+ match * self {
94
+ OnOff :: On => true ,
95
+ OnOff :: Off => false ,
96
+ }
97
+ }
98
+ }
99
+
100
+ impl PartialOrd for OnOff {
101
+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
102
+ Some ( self . cmp ( other) )
103
+ }
104
+ }
105
+
106
+ impl Ord for OnOff {
107
+ fn cmp ( & self , other : & Self ) -> Ordering {
108
+ self . as_bool ( ) . cmp ( & other. as_bool ( ) )
109
+ }
110
+ }
111
+
112
+ /// An open/closed state. Internal representation may be either
113
+ /// Open or Closed.
114
+ #[ derive( Debug , Clone , Eq , PartialEq , Serialize , Deserialize ) ]
115
+ pub enum OpenClosed {
116
+ Open ,
117
+ Closed ,
118
+ }
119
+
120
+ impl OpenClosed {
121
+ fn as_bool ( & self ) -> bool {
122
+ match * self {
123
+ OpenClosed :: Open => true ,
124
+ OpenClosed :: Closed => false ,
71
125
}
72
126
}
73
127
}
74
128
129
+ impl PartialOrd for OpenClosed {
130
+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
131
+ Some ( self . cmp ( other) )
132
+ }
133
+ }
134
+
135
+ impl Ord for OpenClosed {
136
+ fn cmp ( & self , other : & Self ) -> Ordering {
137
+ self . as_bool ( ) . cmp ( & other. as_bool ( ) )
138
+ }
139
+ }
140
+
75
141
/// A temperature. Internal representation may be either Fahrenheit or
76
142
/// Celcius. The FoxBox adapters are expected to perform conversions
77
143
/// to the format requested by their devices.
@@ -123,6 +189,40 @@ impl PartialOrd for Json {
123
189
}
124
190
}
125
191
192
+ /// A data structure holding a boolean value of a type that has not
193
+ /// been standardized yet.
194
+ #[ derive( Debug , Clone , Eq , PartialEq , Serialize , Deserialize ) ]
195
+ pub struct ExtBool {
196
+ pub value : bool ,
197
+
198
+ /// The vendor. Used for namespacing purposes, to avoid
199
+ /// confusing two incompatible extensions with similar
200
+ /// names. For instance, "[email protected] ".
201
+ pub vendor : String ,
202
+
203
+ /// Identification of the adapter introducing this value.
204
+ /// Designed to aid with tracing and debugging.
205
+ pub adapter : String ,
206
+
207
+ /// A string describing the nature of the value, designed to
208
+ /// aid with type-checking.
209
+ ///
210
+ /// Examples: `"PresenceDetected"`.
211
+ pub kind : String ,
212
+ }
213
+
214
+ impl PartialOrd for ExtBool {
215
+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
216
+ if self . vendor != other. vendor {
217
+ return None ;
218
+ } else if self . kind != other. kind {
219
+ return None ;
220
+ }
221
+
222
+ self . value . partial_cmp ( & other. value )
223
+ }
224
+ }
225
+
126
226
/// A data structure holding a numeric value of a type that has not
127
227
/// been standardized yet.
128
228
#[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
@@ -162,7 +262,8 @@ impl PartialOrd for ExtNumeric {
162
262
#[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
163
263
pub enum Value {
164
264
Unit ,
165
- Bool ( bool ) ,
265
+ OnOff ( OnOff ) ,
266
+ OpenClosed ( OpenClosed ) ,
166
267
Duration ( ValDuration ) ,
167
268
TimeStamp ( TimeStamp ) ,
168
269
Temperature ( Temperature ) ,
@@ -171,18 +272,22 @@ pub enum Value {
171
272
172
273
// FIXME: Add more as we identify needs
173
274
275
+ /// A boolean value representing a unit that has not been
276
+ /// standardized yet into the API.
277
+ ExtBool ( ExtBool ) ,
278
+
174
279
/// A numeric value representing a unit that has not been
175
280
/// standardized yet into the API.
176
281
ExtNumeric ( ExtNumeric ) ,
177
282
178
283
/// A Json value. We put it behind an `Arc` to make sure that
179
- /// cloning remains unexpensive .
284
+ /// cloning remains inexpensive .
180
285
Json ( Arc < Json > ) ,
181
286
182
287
/// Binary data.
183
288
Binary {
184
289
/// The actual data. We put it behind an `Arc` to make sure
185
- /// that cloning remains unexpensive .
290
+ /// that cloning remains inexpensive .
186
291
data : Arc < Vec < u8 > > ,
187
292
mimetype : String
188
293
}
@@ -192,14 +297,16 @@ impl Value {
192
297
pub fn get_type ( & self ) -> Type {
193
298
match * self {
194
299
Value :: Unit => Type :: Unit ,
195
- Value :: Bool ( _) => Type :: Bool ,
300
+ Value :: OnOff => Type :: OnOff ,
301
+ Value :: OpenClosed => Type :: OpenClosed ,
196
302
Value :: String ( _) => Type :: String ,
197
303
Value :: Duration ( _) => Type :: Duration ,
198
304
Value :: TimeStamp ( _) => Type :: TimeStamp ,
199
305
Value :: Temperature ( _) => Type :: Temperature ,
200
306
Value :: Color ( _) => Type :: Color ,
201
307
Value :: Json ( _) => Type :: Json ,
202
308
Value :: Binary { ..} => Type :: Binary ,
309
+ Value :: ExtBool ( _) => Type :: ExtBool ,
203
310
Value :: ExtNumeric ( _) => Type :: ExtNumeric ,
204
311
}
205
312
}
@@ -230,8 +337,11 @@ impl PartialOrd for Value {
230
337
( & Unit , & Unit ) => Some ( Equal ) ,
231
338
( & Unit , _) => None ,
232
339
233
- ( & Bool ( a) , & Bool ( b) ) => a. partial_cmp ( & b) ,
234
- ( & Bool ( _) , _) => None ,
340
+ ( & OnOff ( ref a) , & OnOff ( ref b) ) => a. partial_cmp ( b) ,
341
+ ( & OnOff ( _) , _) => None ,
342
+
343
+ ( & OpenClosed ( ref a) , & OpenClosed ( ref b) ) => a. partial_cmp ( b) ,
344
+ ( & OpenClosed ( _) , _) => None ,
235
345
236
346
( & Duration ( ref a) , & Duration ( ref b) ) => a. partial_cmp ( b) ,
237
347
( & Duration ( _) , _) => None ,
@@ -245,6 +355,9 @@ impl PartialOrd for Value {
245
355
( & Color ( ref a) , & Color ( ref b) ) => a. partial_cmp ( b) ,
246
356
( & Color ( _) , _) => None ,
247
357
358
+ ( & ExtBool ( ref a) , & ExtBool ( ref b) ) => a. partial_cmp ( b) ,
359
+ ( & ExtBool ( _) , _) => None ,
360
+
248
361
( & ExtNumeric ( ref a) , & ExtNumeric ( ref b) ) => a. partial_cmp ( b) ,
249
362
( & ExtNumeric ( _) , _) => None ,
250
363
0 commit comments