@@ -2,7 +2,7 @@ use std::collections::BTreeSet;
22use std:: ops:: { AddAssign , Sub } ;
33
44use serde:: { Deserialize , Serialize } ;
5- use serde_json:: { Value , json } ;
5+ use serde_json:: Value ;
66
77use crate :: api:: device:: DeviceIdentifyUpdate ;
88use crate :: api:: { DeviceArchetype , Identify , Metadata , MetadataUpdate , ResourceLink , Stub } ;
@@ -113,9 +113,9 @@ impl Light {
113113 gradient : None ,
114114 identify : Identify { } ,
115115 timed_effects : Some ( LightTimedEffects {
116- status_values : json ! ( [ "no_effect" , "sunrise" , "sunset" ] ) ,
117- status : json ! ( "no_effect" ) ,
118- effect_values : json ! ( [ "no_effect" , "sunrise" , "sunset" ] ) ,
116+ status_values : Vec :: from ( LightTimedEffect :: ALL ) ,
117+ status : LightTimedEffect :: NoEffect ,
118+ effect_values : Vec :: from ( LightTimedEffect :: ALL ) ,
119119 } ) ,
120120 mode : LightMode :: Normal ,
121121 on : On { on : true } ,
@@ -501,7 +501,6 @@ pub enum LightEffect {
501501 Cosmos ,
502502 Sunbeam ,
503503 Enchant ,
504- Sunrise ,
505504}
506505
507506impl LightEffect {
@@ -607,11 +606,32 @@ pub struct LightEffectStatus {
607606 pub parameters : Option < Value > ,
608607}
609608
609+ #[ derive( Debug , Default , Serialize , Deserialize , Clone , Copy , PartialEq , Eq ) ]
610+ #[ serde( rename_all = "snake_case" ) ]
611+ pub enum LightTimedEffect {
612+ #[ default]
613+ NoEffect ,
614+ Sunrise ,
615+ Sunset ,
616+ }
617+
618+ impl LightTimedEffect {
619+ pub const ALL : [ Self ; 3 ] = [ Self :: NoEffect , Self :: Sunrise , Self :: Sunset ] ;
620+ }
621+
610622#[ derive( Debug , Serialize , Deserialize , Clone , PartialEq , Eq ) ]
611623pub struct LightTimedEffects {
612- pub status_values : Value ,
613- pub status : Value ,
614- pub effect_values : Value ,
624+ pub status_values : Vec < LightTimedEffect > ,
625+ pub status : LightTimedEffect ,
626+ pub effect_values : Vec < LightTimedEffect > ,
627+ }
628+
629+ #[ derive( Debug , Serialize , Deserialize , Clone , PartialEq , Eq ) ]
630+ pub struct LightTimedEffectsUpdate {
631+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
632+ pub effect : Option < LightTimedEffect > ,
633+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
634+ pub duration : Option < u32 > ,
615635}
616636
617637#[ derive( Debug , Serialize , Deserialize , Clone , Default ) ]
@@ -642,6 +662,8 @@ pub struct LightUpdate {
642662 pub dynamics : Option < LightDynamicsUpdate > ,
643663 #[ serde( skip_serializing_if = "Option::is_none" ) ]
644664 pub identify : Option < DeviceIdentifyUpdate > ,
665+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
666+ pub timed_effects : Option < LightTimedEffectsUpdate > ,
645667}
646668
647669impl LightUpdate {
0 commit comments