Skip to content

Commit 12d9e37

Browse files
authored
Merge pull request #144 from duvholt/timed-effects
Implement timed effects for Hue lights. This enables the effects "sunrise" and "sunset" using the https api.
2 parents 8e16fba + eb3fca5 commit 12d9e37

File tree

6 files changed

+361
-54
lines changed

6 files changed

+361
-54
lines changed

crates/hue/src/api/light.rs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::BTreeSet;
22
use std::ops::{AddAssign, Sub};
33

44
use serde::{Deserialize, Serialize};
5-
use serde_json::{Value, json};
5+
use serde_json::Value;
66

77
use crate::api::device::DeviceIdentifyUpdate;
88
use 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

507506
impl 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)]
611623
pub 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

647669
impl LightUpdate {

crates/hue/src/api/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ pub use light::{
3838
LightEffectValues, LightEffects, LightEffectsV2, LightEffectsV2Update, LightFunction,
3939
LightGradient, LightGradientMode, LightGradientPoint, LightGradientUpdate, LightMetadata,
4040
LightMode, LightPowerup, LightPowerupColor, LightPowerupDimming, LightPowerupOn,
41-
LightPowerupPreset, LightProductData, LightSignal, LightSignaling, LightTimedEffects,
42-
LightUpdate, MirekSchema, On,
41+
LightPowerupPreset, LightProductData, LightSignal, LightSignaling, LightTimedEffect,
42+
LightTimedEffects, LightTimedEffectsUpdate, LightUpdate, MirekSchema, On,
4343
};
4444
pub use resource::{RType, ResourceLink, ResourceRecord};
4545
pub use room::{Room, RoomArchetype, RoomMetadata, RoomMetadataUpdate, RoomUpdate};

0 commit comments

Comments
 (0)