power_manager_integration_test_lib/client_connectors/
power_profile_client.rs1use crate::TestEnv;
6use futures::channel::mpsc;
7use futures::StreamExt;
8use log::*;
9use {fidl_fuchsia_power_profile as fprofile, fuchsia_async as fasync};
10
11pub struct PowerProfileClient {
13 _watcher_task: fasync::Task<()>,
14 profile_receiver: mpsc::Receiver<fprofile::Profile>,
15}
16
17impl PowerProfileClient {
18 pub async fn new(test_env: &TestEnv) -> Self {
19 let (mut profile_sender, profile_receiver) = mpsc::channel(1);
20 let proxy = test_env.connect_to_protocol::<fprofile::WatcherMarker>();
21
22 let _watcher_task = fasync::Task::local(async move {
23 while let Ok(profile) = proxy.watch().await {
24 info!("Received power profile: {:?}", profile);
25 profile_sender.try_send(profile).expect("Failed to notify power profile change");
26 }
27 });
28
29 Self { _watcher_task, profile_receiver }
30 }
31
32 pub async fn get_power_profile(&mut self) -> fprofile::Profile {
35 self.profile_receiver.next().await.expect("Failed to wait for power profile")
36 }
37}