Skip to content

Commit

Permalink
generate characteristics from system homed
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilken committed Jul 11, 2021
1 parent 7b07769 commit 3476496
Show file tree
Hide file tree
Showing 273 changed files with 13,957 additions and 3,725 deletions.
39 changes: 14 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ Ceiling Fan Accessory
| |-- Serial Characteristic
|
|-- Fan Service
| |-- On Characteristic
| |-- Power State Characteristic
| |-- Rotation Direction Characteristic
| |-- Rotation Speed Characteristic
|
|-- Lightbulb Service
| |-- On Characteristic
| |-- Power State Characteristic
| |-- Brightness Characteristic
| |-- Hue Characteristic
| |-- Saturation Characteristic
Expand Down Expand Up @@ -104,13 +104,13 @@ async fn main() -> Result<()> {
```rust
use hap::characteristic::CharacteristicCallbacks;

lightbulb.lightbulb.on.on_read(Some(|| {
println!("on characteristic read");
lightbulb.lightbulb.power_state.on_read(Some(|| {
println!("power_state characteristic read");
None
}));

lightbulb.lightbulb.on.on_update(Some(|current_val: &bool, new_val: &bool| {
println!("on characteristic updated from {} to {}", current_val, new_val);
lightbulb.lightbulb.power_state.on_update(Some(|current_val: &bool, new_val: &bool| {
println!("power_state characteristic updated from {} to {}", current_val, new_val);
}));
```

Expand All @@ -119,17 +119,17 @@ lightbulb.lightbulb.on.on_update(Some(|current_val: &bool, new_val: &bool| {
```rust
use hap::characteristic::AsyncCharacteristicCallbacks;

lightbulb.lightbulb.on.on_read_async(Some(|| {
lightbulb.lightbulb.power_state.on_read_async(Some(|| {
async {
println!("on characteristic read (async)");
println!("power_state characteristic read (async)");
None
}
.boxed()
}));

lightbulb.lightbulb.on.on_update_async(Some(|current_val: bool, new_val: bool| {
lightbulb.lightbulb.power_state.on_update_async(Some(|current_val: bool, new_val: bool| {
async move {
println!("on characteristic updated from {} to {} (async)", current_val, new_val);
println!("power_state characteristic updated from {} to {} (async)", current_val, new_val);
}
.boxed()
}));
Expand All @@ -143,7 +143,7 @@ use hap::{
serde_json::Value,
};

lightbulb.lightbulb.on.set_value(Value::Bool(true)).await.unwrap();
lightbulb.lightbulb.power_state.set_value(Value::Bool(true)).await.unwrap();
```

### Interacting with accessories added to the server
Expand All @@ -158,7 +158,7 @@ async {

Accessories behind the pointer are represented by the `HapAccessory` trait. The `HapAccessory::get_service` and `HapAccessory::get_mut_service` methods provide access to the services of the accessory, represented by the `HapService` trait. The `HapService::get_characteristic` and `HapService::get_mut_characteristic` methods provide access to the characteristics of the service, represented by the `HapCharacteristic` trait. All services and characteristics are identified by their `HapType`.

Accessing and changing the `on` characteristic of the `lightbulb` service of a `lightbulb` accessory would look like this:
Accessing and changing the `power_state` characteristic of the `lightbulb` service of a `lightbulb` accessory would look like this:

```rust
use hap::{HapType, serde_json::Value};
Expand All @@ -167,9 +167,9 @@ async {
let mut lightbulb_accessory = lightbulb_ptr.lock().await;

let lightbulb_service = lightbulb_accessory.get_mut_service(HapType::Lightbulb).unwrap();
let on_characteristic = lightbulb_service.get_mut_characteristic(HapType::On).unwrap();
let power_state_characteristic = lightbulb_service.get_mut_characteristic(HapType::PowerState).unwrap();

on_characteristic.set_value(Value::Bool(true)).await.unwrap();
power_state_characteristic.set_value(Value::Bool(true)).await.unwrap();
}
```

Expand Down Expand Up @@ -202,17 +202,6 @@ let config = match storage.load_config().await {
};
```

## TODOs

- [x] IP Transport
- [x] Default Accessories
- [x] Lock Accessory
- [x] Television Accessory
- [ ] Camera Streams
- [ ] IP Camera Accessory
- [ ] Video Doorbell Accessory
- [ ] BLE Transport

## Development

Codegen is handled by the `codegen` crate in the workspace. Generated files are checked in. To run the code generation, do:
Expand Down
6 changes: 5 additions & 1 deletion codegen/gen/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
plutil -convert json -o official.json /Volumes/Additional\ Tools/Hardware/HomeKit\ Accessory\ Simulator.app/Contents/Frameworks/HAPAccessoryKit.framework/Versions/A/Resources/default.metadata.plist
### Getting system definitions

cp /System/Library/PrivateFrameworks/HomeKitDaemon.framework/Resources/plain-metadata.config system.json
# remove `LegacyCloud` & `LegacyIDS` entries
plutil -convert json system.json
Loading

0 comments on commit 3476496

Please sign in to comment.