@@ -267,7 +267,7 @@ struct RawSwitchRule {
267
267
value_type : Option < SwitchPropertyType > ,
268
268
269
269
#[ serde( default , rename = "v2" ) ]
270
- value2 : Option < Variant > ,
270
+ value2 : Variant ,
271
271
272
272
#[ serde( default , rename = "v2t" ) ]
273
273
value2_type : Option < SwitchPropertyType > ,
@@ -284,7 +284,7 @@ struct SwitchRule {
284
284
285
285
value_type : SwitchPropertyType ,
286
286
287
- value2 : Option < RedPropertyValue > ,
287
+ value2 : RedPropertyValue ,
288
288
289
289
value2_type : Option < SwitchPropertyType > ,
290
290
@@ -357,27 +357,29 @@ impl SwitchNode {
357
357
( None , None ) => ( SwitchPropertyType :: Str , RedPropertyValue :: null ( ) ) ,
358
358
} ;
359
359
360
- let ( v2t, v2) = if let Some ( raw_v2 ) = raw_rule. value2 {
360
+ let ( v2t, v2) = if ! raw_rule. value2 . is_null ( ) {
361
361
match raw_rule. value2_type {
362
- Some ( SwitchPropertyType :: Prev ) => ( Some ( SwitchPropertyType :: Prev ) , Some ( RedPropertyValue :: null ( ) ) ) ,
362
+ Some ( SwitchPropertyType :: Prev ) => ( Some ( SwitchPropertyType :: Prev ) , RedPropertyValue :: null ( ) ) ,
363
363
None => {
364
- if raw_v2 . is_number ( ) {
365
- ( Some ( SwitchPropertyType :: Num ) , Some ( RedPropertyValue :: Constant ( raw_v2 ) ) )
364
+ if raw_rule . value2 . is_number ( ) {
365
+ ( Some ( SwitchPropertyType :: Num ) , RedPropertyValue :: Constant ( raw_rule . value2 ) )
366
366
} else {
367
- ( Some ( SwitchPropertyType :: Str ) , Some ( RedPropertyValue :: Constant ( raw_v2 ) ) )
367
+ ( Some ( SwitchPropertyType :: Str ) , RedPropertyValue :: Constant ( raw_rule . value2 ) )
368
368
}
369
369
}
370
370
Some ( raw_v2t) => {
371
371
if raw_v2t. is_constant ( ) {
372
- let evaluated = RedPropertyValue :: evaluate_constant ( & raw_v2, raw_v2t. try_into ( ) ?) ?;
373
- ( Some ( raw_v2t) , Some ( evaluated) )
372
+ (
373
+ Some ( raw_v2t) ,
374
+ RedPropertyValue :: evaluate_constant ( & raw_rule. value2 , raw_v2t. try_into ( ) ?) ?,
375
+ )
374
376
} else {
375
- ( Some ( raw_v2t) , Some ( RedPropertyValue :: Runtime ( raw_v2 . to_string ( ) ?) ) )
377
+ ( Some ( raw_v2t) , RedPropertyValue :: Runtime ( raw_rule . value2 . to_string ( ) ?) )
376
378
}
377
379
}
378
380
}
379
381
} else {
380
- ( raw_rule. value2_type , Some ( RedPropertyValue :: null ( ) ) )
382
+ ( raw_rule. value2_type , RedPropertyValue :: null ( ) )
381
383
} ;
382
384
383
385
let v = match v {
@@ -474,7 +476,7 @@ impl SwitchNode {
474
476
async fn get_v2 ( & self , rule : & SwitchRule , msg : & Msg ) -> crate :: Result < Variant > {
475
477
match ( rule. value2_type , & rule. value2 ) {
476
478
( Some ( SwitchPropertyType :: Prev ) , _) => Ok ( self . prev_value . read ( ) . await . clone ( ) ) ,
477
- ( Some ( vt2) , Some ( v2 ) ) => {
479
+ ( Some ( vt2) , v2 ) => {
478
480
eval:: evaluate_node_property_value (
479
481
v2. clone ( ) ,
480
482
vt2. try_into ( ) . unwrap ( ) ,
@@ -485,7 +487,6 @@ impl SwitchNode {
485
487
. await
486
488
}
487
489
( None , _) => Ok ( Variant :: Null ) ,
488
- _ => Err ( EdgelinkError :: BadArgument ( "rule" ) . into ( ) ) ,
489
490
}
490
491
}
491
492
}
0 commit comments