HomeKit Accessory Protocol (HAP) for OCaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

json: rename mem -> member / finish -> seal across the codec + value API

Object combinators: [Object.mem] -> [Object.member], [Object.opt_mem]
-> [Object.opt_member], [Object.case_mem] -> [Object.case_member]. The
sibling submodules [Object.Mem] / [Object.Mems] become
[Object.Member] / [Object.Members]. RFC 8259 §4 calls these
"name/value pairs, referred to as the members", so mirror the spec
name rather than the shortened [mem].

[Object.finish] -> [Object.seal]. "Seal" reads as "close the map, no
more members added", which is what the operation does.

Value constructors/queries: [Value.mem] (function) -> [Value.member];
[Value.mem_find] -> [Value.member_key]; [Value.mem_names] ->
[Value.member_names]; [Value.mem_keys] -> [Value.member_keys].
[type mem = ...] -> [type member = ...]; [type object'] still points
at [member list].

Downstream (~80 files across slack, sbom, stripe, sigstore, requests,
claude, irmin, freebox) updated via perl-pie. dune build clean,
dune test ocaml-json clean.

+36 -35
+2 -2
dune-project
··· 28 28 (re (>= 1.10)) 29 29 (requests (>= 0.1)) 30 30 (json (>= 0.1)) 31 - (bytesrw (>= 0.1)) 32 31 (base64 (>= 3.5)) 33 32 (logs (>= 0.7)) 34 33 (fmt (>= 0.9)) 35 34 (ipaddr (>= 5.0)) 36 35 (domain-name (>= 0.4)) 37 36 (alcotest :with-test) 38 - (crowbar :with-test))) 37 + (alcobar :with-test) 38 + loc))
+2 -2
hap.opam
··· 22 22 "re" {>= "1.10"} 23 23 "requests" {>= "0.1"} 24 24 "json" {>= "0.1"} 25 - "bytesrw" {>= "0.1"} 26 25 "base64" {>= "3.5"} 27 26 "logs" {>= "0.7"} 28 27 "fmt" {>= "0.9"} 29 28 "ipaddr" {>= "5.0"} 30 29 "domain-name" {>= "0.4"} 31 30 "alcotest" {with-test} 32 - "crowbar" {with-test} 31 + "alcobar" {with-test} 32 + "loc" 33 33 "odoc" {with-doc} 34 34 ] 35 35 build: [
+32 -31
lib/hap.ml
··· 556 556 let open Json.Codec in 557 557 Object.map ~kind:"char_write" (fun aid iid value -> 558 558 { cw_aid = aid; cw_iid = iid; cw_value = value }) 559 - |> Object.mem "aid" int ~enc:(fun c -> c.cw_aid) 560 - |> Object.mem "iid" int ~enc:(fun c -> c.cw_iid) 561 - |> Object.mem "value" Value.t ~enc:(fun c -> c.cw_value) 562 - |> Object.finish 559 + |> Object.member "aid" int ~enc:(fun c -> c.cw_aid) 560 + |> Object.member "iid" int ~enc:(fun c -> c.cw_iid) 561 + |> Object.member "value" Value.t ~enc:(fun c -> c.cw_value) 562 + |> Object.seal 563 563 564 564 type char_write_request = { characteristics : char_write list } 565 565 ··· 567 567 let open Json.Codec in 568 568 Object.map ~kind:"char_write_request" (fun characteristics -> 569 569 { characteristics }) 570 - |> Object.mem "characteristics" (list char_write_codec) ~enc:(fun r -> 570 + |> Object.member "characteristics" (list char_write_codec) ~enc:(fun r -> 571 571 r.characteristics) 572 - |> Object.finish 572 + |> Object.seal 573 573 574 574 (* Write a characteristic *) 575 575 let put_characteristic ~net ~sw session ~aid ~iid value = ··· 646 646 controller_ltsk; 647 647 controller_ltpk; 648 648 }) 649 - |> Object.mem "accessory_id" string ~enc:(fun p -> p.accessory_id) 650 - |> Object.mem "accessory_ltpk" string ~enc:(fun p -> p.accessory_ltpk) 651 - |> Object.mem "controller_id" string ~enc:(fun p -> p.controller_id) 652 - |> Object.mem "controller_ltsk" string ~enc:(fun p -> p.controller_ltsk) 653 - |> Object.mem "controller_ltpk" string ~enc:(fun p -> p.controller_ltpk) 654 - |> Object.finish 649 + |> Object.member "accessory_id" string ~enc:(fun p -> p.accessory_id) 650 + |> Object.member "accessory_ltpk" string ~enc:(fun p -> p.accessory_ltpk) 651 + |> Object.member "controller_id" string ~enc:(fun p -> p.controller_id) 652 + |> Object.member "controller_ltsk" string ~enc:(fun p -> p.controller_ltsk) 653 + |> Object.member "controller_ltpk" string ~enc:(fun p -> p.controller_ltpk) 654 + |> Object.seal 655 655 656 656 let of_pairing (p : pairing) : stored = 657 657 { ··· 856 856 let characteristic = 857 857 Object.map ~kind:"hap.characteristic" (fun iid type_ value -> 858 858 { iid; type_; value }) 859 - |> Object.mem "iid" int ~enc:(fun c -> c.iid) 860 - |> Object.mem "type" string ~enc:(fun c -> c.type_) 861 - |> Object.opt_mem "value" Value.t ~enc:(fun c -> c.value) 862 - |> Object.finish 859 + |> Object.member "iid" int ~enc:(fun c -> c.iid) 860 + |> Object.member "type" string ~enc:(fun c -> c.type_) 861 + |> Object.opt_member "value" Value.t ~enc:(fun c -> c.value) 862 + |> Object.seal 863 863 864 864 type service = { 865 865 iid : int; ··· 871 871 let service = 872 872 Object.map ~kind:"hap.service" (fun iid type_ characteristics -> 873 873 { iid; type_; characteristics }) 874 - |> Object.mem "iid" int ~enc:(fun s -> s.iid) 875 - |> Object.mem "type" string ~enc:(fun s -> s.type_) 876 - |> Object.mem "characteristics" (list characteristic) ~enc:(fun s -> 874 + |> Object.member "iid" int ~enc:(fun s -> s.iid) 875 + |> Object.member "type" string ~enc:(fun s -> s.type_) 876 + |> Object.member "characteristics" (list characteristic) ~enc:(fun s -> 877 877 s.characteristics) 878 - |> Object.finish 878 + |> Object.seal 879 879 880 880 type accessory = { aid : int; services : service list } 881 881 (** HAP accessory *) 882 882 883 883 let accessory = 884 884 Object.map ~kind:"hap.accessory" (fun aid services -> { aid; services }) 885 - |> Object.mem "aid" int ~enc:(fun a -> a.aid) 886 - |> Object.mem "services" (list service) ~enc:(fun a -> a.services) 887 - |> Object.finish 885 + |> Object.member "aid" int ~enc:(fun a -> a.aid) 886 + |> Object.member "services" (list service) ~enc:(fun a -> a.services) 887 + |> Object.seal 888 888 889 889 type accessories_response = { accessories : accessory list } 890 890 (** HAP accessories response *) ··· 892 892 let accessories_response = 893 893 Object.map ~kind:"hap.accessories_response" (fun accessories -> 894 894 { accessories }) 895 - |> Object.mem "accessories" (list accessory) ~enc:(fun r -> r.accessories) 896 - |> Object.finish 895 + |> Object.member "accessories" (list accessory) ~enc:(fun r -> 896 + r.accessories) 897 + |> Object.seal 897 898 898 899 type char_value = { aid : int; iid : int; value : Json.t option } 899 900 (** HAP characteristics value *) 900 901 901 902 let char_value = 902 903 Object.map ~kind:"hap.char_value" (fun aid iid value -> { aid; iid; value }) 903 - |> Object.mem "aid" int ~enc:(fun c -> c.aid) 904 - |> Object.mem "iid" int ~enc:(fun c -> c.iid) 905 - |> Object.opt_mem "value" Value.t ~enc:(fun c -> c.value) 906 - |> Object.finish 904 + |> Object.member "aid" int ~enc:(fun c -> c.aid) 905 + |> Object.member "iid" int ~enc:(fun c -> c.iid) 906 + |> Object.opt_member "value" Value.t ~enc:(fun c -> c.value) 907 + |> Object.seal 907 908 908 909 type characteristics_response = { characteristics : char_value list } 909 910 910 911 let characteristics_response = 911 912 Object.map ~kind:"hap.characteristics_response" (fun characteristics -> 912 913 { characteristics }) 913 - |> Object.mem "characteristics" (list char_value) ~enc:(fun r -> 914 + |> Object.member "characteristics" (list char_value) ~enc:(fun r -> 914 915 r.characteristics) 915 - |> Object.finish 916 + |> Object.seal 916 917 end 917 918 918 919 (** {1 High-level control} *)