Comments (1)
An alternative I see is to handle my own shared state somewhere else and use an on_read callback to update the Homekit state when its actually attempting to be read.
This is something you can do, but, as you pointed out, not really practical for things like sensors where you want event notifications on value changes.
I was expecting that set_value would be "sending out" status update messages to the system so they could be triggering notifications, automations, etc.
It does! (Or at least should do. I hope I didn't break it since I last tested.)
The other idea I had but haven't followed through with yet is trying to use the pointer::Acessory returned from add_accessory to try and get to the characteristic to set values on it. Is that what I'm supposed to be doing?
Yes. That's what I'd do. You're totally right about the lack of documentation for that. Will try to document it properly.
Just added a (lightly tested) example for a motion sensor that gets triggered every two seconds after one minute after program start. The interesting part is this one:
let sensor_ptr = server.add_accessory(sensor).await.unwrap();
let handle = server.run_handle();
let value_set_interval = async move {
let mut interval = tokio::time::interval(std::time::Duration::from_secs(2));
tokio::time::delay_for(std::time::Duration::from_secs(60)).await;
loop {
interval.tick().await;
let mut motion_sensor_accessory = sensor_ptr.lock().await;
let motion_sensor_service = motion_sensor_accessory.get_mut_service(HapType::MotionSensor).unwrap();
let motion_detected_characteristic = motion_sensor_service
.get_mut_characteristic(HapType::MotionDetected)
.unwrap();
motion_detected_characteristic
.set_value(Value::Bool(true))
.await
.unwrap();
tokio::time::delay_for(std::time::Duration::from_secs(1)).await;
motion_detected_characteristic
.set_value(Value::Bool(false))
.await
.unwrap();
}
};
std::env::set_var("RUST_LOG", "hap=debug");
env_logger::init();
futures::join!(handle, value_set_interval);
cargo run --example setting_values_after_server_start --release
Apparently the --release
build is needed for the pairing process to be fast enough for the iOS controller not to lose patience. Still a lot of stuff left to look into here.
Thanks a lot for caring! Feel free to reach out for further questions anytime. And contributions to help finishing this crate are always welcome, should you find it useful.
from hap-rs.
Related Issues (20)
- Update examples to properly reflect target states
- Implement accessories for missing categories
- `FileStorage::list_pairings` is erroring on > 0 stored pairings
- Codegen for macOS 12
- Upgrade to Rust 2021
- Re-check whether deferring the `ControllerPaired` event emission is a good idea
- Creating custom characteristics, services & accessories HOT 4
- make API easier to use with concurrent programs HOT 1
- Battery's `charging_state` and `battery_level` characteristics are defined as optional even though they're required. HOT 3
- Status of this crate HOT 4
- FnMut instead of Fn for on_update_async HOT 1
- IOS Home App does not see accessories any longer HOT 1
- Raspbian speed HOT 2
- Multiple instances with same service HOT 2
- Value Type check for Characteristics HOT 2
- IOS Home App not showing accessory details HOT 2
- Pairing and Performance HOT 1
- Split up, or feature-gate HAP types vs other concepts (servers, storage, transport) HOT 1
- Issues Pairing
- How to pair with Apple Home app? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hap-rs.