Skip to content

Commit 2cc406c

Browse files
committed
+ Add more supported fields in ApiGroupUpdate2, and mark all as optional
This allows changing entertainment configurations from api v1, which makes iLightShow able to switch targets.
1 parent 1e4a911 commit 2cc406c

2 files changed

Lines changed: 31 additions & 22 deletions

File tree

crates/hue/src/legacy_api.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,14 +491,16 @@ pub struct ApiGroupUpdate {
491491
pub scene: String,
492492
}
493493

494-
#[derive(Debug, Serialize, Deserialize)]
494+
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
495495
pub struct Active {
496496
pub active: bool,
497497
}
498498

499499
#[derive(Debug, Serialize, Deserialize)]
500500
pub struct ApiGroupUpdate2 {
501-
pub stream: Active,
501+
pub lights: Option<Vec<String>>,
502+
pub name: Option<String>,
503+
pub stream: Option<Active>,
502504
}
503505

504506
#[derive(Debug, Serialize, Deserialize)]

src/routes/api.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -390,21 +390,27 @@ async fn put_api_user_resource_id(
390390
ApiResourceType::Groups => {
391391
let upd: ApiGroupUpdate2 = serde_json::from_value(req)?;
392392

393-
let uuid = state.res.lock().await.from_id_v1(id)?;
393+
let mut v1res = V1Reply::for_group(id);
394394

395-
let action = if upd.stream.active {
396-
EntertainmentConfigurationAction::Start
397-
} else {
398-
EntertainmentConfigurationAction::Stop
399-
};
395+
let mut ecupd = EntertainmentConfigurationUpdate::new();
400396

401-
let ecupd = EntertainmentConfigurationUpdate {
402-
configuration_type: None,
403-
metadata: None,
404-
action: Some(action),
405-
stream_proxy: None,
406-
locations: None,
407-
};
397+
let lock = state.res.lock().await;
398+
399+
let uuid = lock.from_id_v1(id)?;
400+
401+
ecupd.action = upd.stream.map(|stream| {
402+
if stream.active {
403+
EntertainmentConfigurationAction::Start
404+
} else {
405+
EntertainmentConfigurationAction::Stop
406+
}
407+
});
408+
409+
if let Some(lights) = &upd.lights {
410+
ecupd.locations = Some(lights_v1_to_ec_locations(lights, &lock)?.into());
411+
}
412+
413+
drop(lock);
408414

409415
let rlink = RType::EntertainmentConfiguration.link_to(uuid);
410416

@@ -415,14 +421,15 @@ async fn put_api_user_resource_id(
415421
)
416422
.await?;
417423

418-
if resp.0.errors.is_empty() {
419-
let v1res = V1Reply::for_group(id)
420-
.add("stream/active", upd.stream.active)?
421-
.json();
422-
Ok(Json(v1res))
423-
} else {
424-
Err(HueApiV1Error::BridgeInternalError)?
424+
if !resp.0.errors.is_empty() {
425+
Err(HueApiV1Error::BridgeInternalError)?;
425426
}
427+
428+
if let Some(stream) = &upd.stream {
429+
v1res = v1res.add("stream/active", stream.active)?;
430+
}
431+
432+
Ok(Json(v1res.json()))
426433
}
427434
ApiResourceType::Config
428435
| ApiResourceType::Lights

0 commit comments

Comments
 (0)