@@ -10,10 +10,9 @@ use uuid::Uuid;
1010use bifrost_api:: backend:: BackendRequest ;
1111use hue:: api:: {
1212 BridgeHome , ColorTemperatureUpdate , DimmingDeltaAction , Entertainment ,
13- EntertainmentConfiguration , GroupedLight , GroupedLightUpdate , Light , LightEffect ,
14- LightEffectsV2Update , LightGradientMode , LightUpdate , RType , Resource , ResourceLink , Room ,
15- RoomUpdate , Scene , SceneActive , SceneStatus , SceneStatusEnum , SceneUpdate ,
16- ZigbeeDeviceDiscoveryUpdate ,
13+ EntertainmentConfiguration , GroupedLight , GroupedLightUpdate , Light , LightEffectsV2Update ,
14+ LightGradientMode , LightUpdate , RType , Resource , ResourceLink , Room , RoomUpdate , Scene ,
15+ SceneActive , SceneStatus , SceneStatusEnum , SceneUpdate , ZigbeeDeviceDiscoveryUpdate ,
1716} ;
1817use hue:: error:: HueError ;
1918use hue:: stream:: HueStreamLightsV2 ;
@@ -72,7 +71,7 @@ impl Z2mBackend {
7271 hz = hz. with_effect_type ( fx. into ( ) ) ;
7372 }
7473 if let Some ( speed) = & act. parameters . speed {
75- hz = hz. with_effect_speed ( speed. unit_to_u8_clamped ( ) ) ;
74+ hz = hz. with_effect_speed ( speed. unit_to_u8_clamped_light ( ) ) ;
7675 }
7776 if let Some ( mirek) = & act. parameters . color_temperature . and_then ( |ct| ct. mirek ) {
7877 hz = hz. with_color_mirek ( * mirek) ;
@@ -105,43 +104,18 @@ impl Z2mBackend {
105104 return Ok ( ( ) ) ;
106105 } ;
107106
108- let mut lock = self . state . lock ( ) . await ;
109-
110- // We cannot recover .mode from backend updates, since these only contain
111- // the gradient colors. So we have no choice, but to update the mode
112- // here. Otherwise, the information would be lost.
113- if let Some ( mode) = upd. gradient . as_ref ( ) . and_then ( |gr| gr. mode ) {
114- lock. update :: < Light > ( & link. rid , |light| {
115- if let Some ( gr) = & mut light. gradient {
116- gr. mode = mode;
117- }
118- } ) ?;
119- }
120- // Effect state is currently not retrieved from backend updates either
121- if let Some ( upd) = upd. effects_v2 . as_ref ( ) {
122- lock. update :: < Light > ( & link. rid , |light| {
123- if let Some ( effects_v2) = & mut light. effects_v2 {
124- * effects_v2 += upd;
125- }
126- if let Some ( effects) = & mut light. effects {
127- let light_effect = upd
128- . action
129- . as_ref ( )
130- . and_then ( |a| a. effect )
131- . unwrap_or ( LightEffect :: NoEffect ) ;
132- effects. status = light_effect;
133- }
134- } ) ?;
135- }
136- let hue_effects = lock. get :: < Light > ( link) ?. effects . is_some ( ) ;
137- drop ( lock) ;
107+ let hue_effects = self
108+ . state
109+ . lock ( )
110+ . await
111+ . get :: < Light > ( link) ?
112+ . effects
113+ . is_some ( ) ;
138114
139115 let mut payload: Option < DeviceUpdate > = None ;
140116
141117 // handle "identify" request (light breathing)
142118 if upd. identify . is_some ( ) {
143- // handle "identify" request (light breathing)
144-
145119 payload = Some (
146120 payload
147121 . unwrap_or_default ( )
@@ -209,17 +183,7 @@ impl Z2mBackend {
209183 if !hz. is_empty ( ) {
210184 hz = hz. with_fade_speed ( 0x0001 ) ;
211185
212- let read_payload = DeviceRead :: default ( )
213- . with_state (
214- hz. onoff . is_some ( ) || hz. brightness . is_some ( ) || hz. effect_type . is_some ( ) ,
215- )
216- . with_color (
217- hz. color_mirek . is_some ( )
218- || hz. color_xy . is_some ( )
219- || hz. effect_type . is_some ( ) ,
220- )
221- . with_brightness ( hz. brightness . is_some ( ) || hz. effect_type . is_some ( ) ) ;
222-
186+ let read_payload = DeviceRead :: default ( ) . with_state ( true ) ;
223187 z2mws. send_hue_effects ( topic, hz) . await ?;
224188
225189 // Do an explicit attribute read since Hue specific updates do not automatically update z2m state
0 commit comments