Skip to main content

hap_model/
lib.rs

1//! HomeKit accessory attribute database — Milestone 6 of `hap-rust`.
2//!
3//! `hap-model` is transport-agnostic. It parses the `/accessories` JSON into
4//! a typed [`Accessory`] → [`Service`] → [`Characteristic`] tree and builds /
5//! parses the `/characteristics` request and response bodies. It never touches
6//! the network: the controller (`hap-controller`, M7) executes the requests
7//! this crate produces over a secure session.
8//!
9//! # Example
10//!
11//! ```
12//! use hap_model::parse_accessories;
13//!
14//! let body = br#"{"accessories":[{"aid":1,"services":[
15//!     {"iid":1,"type":"3E","characteristics":[
16//!         {"iid":2,"type":"23","format":"string","perms":["pr"],"value":"Lamp"}
17//!     ]}
18//! ]}]}"#;
19//! let accessories = parse_accessories(body).unwrap();
20//! assert_eq!(accessories[0].aid, 1);
21//! ```
22//!
23//! The doc-test uses `unwrap()`; real library code must propagate the
24//! [`Result`] instead.
25
26#![forbid(unsafe_code)]
27
28pub mod database;
29pub mod error;
30pub mod format;
31pub mod perms;
32pub mod tree;
33pub mod unit;
34pub mod uuid;
35
36mod accessories;
37mod characteristics;
38mod generated;
39
40pub use accessories::parse_accessories;
41pub use characteristics::{
42    build_prepare_request, build_read_request, build_subscribe_request, build_timed_write_request,
43    build_write_request, build_write_request_with_response, parse_read_response, CharRead,
44};
45pub use database::{AccessoryDatabase, Request, RequestExecutor};
46pub use error::{ModelError, Result};
47pub use format::{CharFormat, CharValue};
48pub use generated::{CharacteristicType, ServiceType};
49pub use perms::Perms;
50pub use tree::{Accessory, Characteristic, Service};
51pub use unit::Unit;
52pub use uuid::Uuid;