Skip to main content

Crate hap_model

Crate hap_model 

Source
Expand description

HomeKit accessory attribute database — Milestone 6 of hap-rust.

hap-model is transport-agnostic. It parses the /accessories JSON into a typed AccessoryServiceCharacteristic tree and builds / parses the /characteristics request and response bodies. It never touches the network: the controller (hap-controller, M7) executes the requests this crate produces over a secure session.

§Example

use hap_model::parse_accessories;

let body = br#"{"accessories":[{"aid":1,"services":[
    {"iid":1,"type":"3E","characteristics":[
        {"iid":2,"type":"23","format":"string","perms":["pr"],"value":"Lamp"}
    ]}
]}]}"#;
let accessories = parse_accessories(body).unwrap();
assert_eq!(accessories[0].aid, 1);

The doc-test uses unwrap(); real library code must propagate the Result instead.

Re-exports§

pub use database::AccessoryDatabase;
pub use database::Request;
pub use database::RequestExecutor;
pub use error::ModelError;
pub use error::Result;
pub use format::CharFormat;
pub use format::CharValue;
pub use perms::Perms;
pub use status::HapStatus;
pub use tree::Accessory;
pub use tree::Characteristic;
pub use tree::Service;
pub use unit::Unit;
pub use uuid::Uuid;

Modules§

database
A thin typed-access layer over a caller-supplied request executor.
error
Error type for hap-model.
format
Characteristic value formats and decoded values.
perms
Characteristic permissions.
status
HAP per-characteristic status codes.
tree
The typed accessory attribute tree: AccessoryServiceCharacteristic.
unit
HAP characteristic units (the spec unit field).
uuid
HAP type UUIDs.

Structs§

CharRead
One decoded entry from a GET /characteristics response.

Enums§

CharacteristicType
HAP-defined CharacteristicType (generated). Unknown carries any non-HAP UUID.
ServiceType
HAP-defined ServiceType (generated). Unknown carries any non-HAP UUID.

Functions§

build_prepare_request
Build the JSON body for PUT /prepare: a timed-write reservation.
build_read_request
Build the path+query for GET /characteristics?id=....
build_subscribe_request
Build the JSON body for PUT /characteristics subscribing (enable=true) or unsubscribing (enable=false) to events for each (aid,iid).
build_timed_write_request
Build a PUT /characteristics body for a timed write: every entry carries the pid from a preceding build_prepare_request.
build_write_request
Build the JSON body for PUT /characteristics writing each (aid,iid) its CharValue.
build_write_request_with_response
Build a PUT /characteristics body requesting the post-write value back (the HAP r flag).
parse_accessories
Parse the body of a GET /accessories response into the typed tree.
parse_read_response
Parse a GET /characteristics response body into ((aid,iid), CharValue) pairs for the successful entries.