Skip to content

Commit

Permalink
Merge pull request #15 from chrivers/chrivers/missing-brightness-control
Browse files Browse the repository at this point in the history
Implement missing brightness feature detection
  • Loading branch information
chrivers authored Aug 24, 2024
2 parents 298c107 + af5ab7b commit 2a2873b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/hue/api/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,17 @@ impl From<Dimming> for f64 {
value.brightness
}
}

impl Dimming {
#[must_use]
pub const fn extract_from_expose(expose: &Expose) -> Option<Self> {
let Expose::Numeric(_) = expose else {
return None;
};

Some(Self {
brightness: 0.0,
min_dim_level: None,
})
}
}
10 changes: 8 additions & 2 deletions src/z2m/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use crate::config::{AppConfig, Z2mServer};
use crate::hue;
use crate::hue::api::{
Button, ButtonData, ButtonMetadata, ButtonReport, ColorTemperature, ColorTemperatureUpdate,
ColorUpdate, Device, DeviceArchetype, DeviceProductData, DimmingUpdate, GroupedLight, Light,
LightColor, LightUpdate, Metadata, RType, Resource, ResourceLink, Room, RoomArchetype,
ColorUpdate, Device, DeviceArchetype, DeviceProductData, Dimming, DimmingUpdate, GroupedLight,
Light, LightColor, LightUpdate, Metadata, RType, Resource, ResourceLink, Room, RoomArchetype,
RoomMetadata, Scene, SceneAction, SceneActionElement, SceneMetadata, SceneStatus,
ZigbeeConnectivity, ZigbeeConnectivityStatus,
};
Expand Down Expand Up @@ -97,10 +97,16 @@ impl Client {
let mut res = self.state.lock().await;
let mut light = Light::new(link_device, metadata);

light.dimming = expose
.feature("brightness")
.and_then(Dimming::extract_from_expose);
log::trace!("Detected dimming: {:?}", &light.dimming);

light.color_temperature = expose
.feature("color_temp")
.and_then(ColorTemperature::extract_from_expose);
log::trace!("Detected color temperature: {:?}", &light.color_temperature);

light.color = expose
.feature("color_xy")
.and_then(LightColor::extract_from_expose);
Expand Down

0 comments on commit 2a2873b

Please sign in to comment.