OCaml library for controlling Meross smart plugs via local HTTP API
0
fork

Configure Feed

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

codec: let open Json.Codec in cleanup across 15 small lib files

5-7 usages each. atp/blob_ref, freebox/{calls,firewall,http,parental,
switch}, meross/{consumption,electricity,timers}, oci/spec/{manifest_list,
media_type}, sbom, slack/{channel,reaction,user}. Several `name` and
`id` accessors annotated with `(t : T)` so the codec body's
`~enc:(fun u -> Some (id u))` form picks the local record over
mem_map. freebox call sites that wrap codecs into HTTP requests keep
`Json.Codec.list` / `Json.Codec.null` qualified.

+11 -14
+5 -5
lib/consumption.ml
··· 12 12 (** {1 Codec} *) 13 13 14 14 let entry_codec = 15 - Json.Codec.Object.map ~kind:"consumption_entry" (fun date value -> 15 + let open Json.Codec in 16 + Object.map ~kind:"consumption_entry" (fun date value -> 16 17 { date; value = value /. 1000.0 }) (* Convert mWh to Wh *) 17 - |> Json.Codec.Object.mem "date" Json.Codec.string ~enc:(fun e -> e.date) 18 - |> Json.Codec.Object.mem "value" Json.Codec.number ~enc:(fun e -> 19 - e.value *. 1000.0) 20 - |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 18 + |> Object.mem "date" string ~enc:(fun e -> e.date) 19 + |> Object.mem "value" number ~enc:(fun e -> e.value *. 1000.0) 20 + |> Object.skip_unknown |> Object.finish 21 21 22 22 let codec = Json.Codec.list entry_codec 23 23
+6 -8
lib/electricity.ml
··· 13 13 (** {1 Codec} *) 14 14 15 15 let codec = 16 - Json.Codec.Object.map ~kind:"electricity" (fun power voltage current -> 16 + let open Json.Codec in 17 + Object.map ~kind:"electricity" (fun power voltage current -> 17 18 (* Meross reports in milliwatts/decivolts/milliamps *) 18 19 { 19 20 power = power /. 1000.0; 20 21 voltage = voltage /. 10.0; 21 22 current = current /. 1000.0; 22 23 }) 23 - |> Json.Codec.Object.mem "power" Json.Codec.number ~enc:(fun e -> 24 - e.power *. 1000.0) 25 - |> Json.Codec.Object.mem "voltage" Json.Codec.number ~enc:(fun e -> 26 - e.voltage *. 10.0) 27 - |> Json.Codec.Object.mem "current" Json.Codec.number ~enc:(fun e -> 28 - e.current *. 1000.0) 29 - |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 24 + |> Object.mem "power" number ~enc:(fun e -> e.power *. 1000.0) 25 + |> Object.mem "voltage" number ~enc:(fun e -> e.voltage *. 10.0) 26 + |> Object.mem "current" number ~enc:(fun e -> e.current *. 1000.0) 27 + |> Object.skip_unknown |> Object.finish 30 28 31 29 (** {1 Operations} *) 32 30
-1
lib/timers.ml
··· 67 67 (** Get all timers *) 68 68 let get ~http ~sw ip = 69 69 let json = 70 - let open Json.Codec in 71 70 P.request_empty ~method_:"GET" ~namespace:"Appliance.Control.TimerX" 72 71 in 73 72 let* resp = P.http_post ~http ~sw ip json in