Skip to content

Commit 394e99c

Browse files
committed
Add default transition for brightness and color
1 parent 8b74d6d commit 394e99c

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/backend/z2m/backend_event.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,26 @@ impl Z2mBackend {
9292
drop(lock);
9393

9494
/* step 1: send generic light update */
95+
let transition = upd
96+
.dynamics
97+
.as_ref()
98+
.and_then(|d| d.duration.map(|duration| f64::from(duration) / 1000.0))
99+
.or_else(|| {
100+
if upd.dimming.is_some()
101+
|| upd.color_temperature.is_some()
102+
|| upd.color_temperature.is_some()
103+
{
104+
Some(0.4)
105+
} else {
106+
None
107+
}
108+
});
95109
let mut payload = DeviceUpdate::default()
96110
.with_state(upd.on.map(|on| on.on))
97111
.with_brightness(upd.dimming.map(|dim| dim.brightness / 100.0 * 254.0))
98112
.with_color_temp(upd.color_temperature.and_then(|ct| ct.mirek))
99113
.with_color_xy(upd.color.map(|col| col.xy))
100-
.with_transition(
101-
upd.dynamics
102-
.as_ref()
103-
.and_then(|d| d.duration.map(|duration| f64::from(duration) / 1000.0)),
104-
);
114+
.with_transition(transition);
105115

106116
// We don't want to send gradient updates twice, but if hue
107117
// effects are not supported for this light, this is the best

0 commit comments

Comments
 (0)