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 16 medium files

10-19 usages each: linkedin/{profile,post}, space-dtn/daemon/config,
gdocs/comments, freebox/{switch,calls,firewall,parental,auth},
slack/team, requests/oauth, oci/spec/{manifest,intoto},
meross/timers, atp/atp/lex, gauth.

Same pattern: per-let `let open Json.Codec in` inside codec bodies,
`Json.Codec.list` qualified at the API call sites that wrap codecs
into HTTP requests. No record-field clashes worth annotating in this
batch.

+17 -19
+17 -19
lib/timers.ml
··· 28 28 (** {1 Codecs} *) 29 29 30 30 let countdown_codec = 31 - Json.Codec.Object.map ~kind:"countdown" (fun onoff end_time duration -> 31 + let open Json.Codec in 32 + Object.map ~kind:"countdown" (fun onoff end_time duration -> 32 33 { 33 34 onoff = Option.value ~default:0 onoff; 34 35 end_time = Option.value ~default:0 end_time; 35 36 duration = Option.value ~default:0 duration; 36 37 }) 37 - |> Json.Codec.Object.opt_mem "onoff" Json.Codec.int ~enc:(fun c -> 38 - Some c.onoff) 39 - |> Json.Codec.Object.opt_mem "end" Json.Codec.int ~enc:(fun c -> 40 - Some c.end_time) 41 - |> Json.Codec.Object.opt_mem "duration" Json.Codec.int ~enc:(fun c -> 42 - Some c.duration) 43 - |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 38 + |> Object.opt_mem "onoff" int ~enc:(fun c -> Some c.onoff) 39 + |> Object.opt_mem "end" int ~enc:(fun c -> Some c.end_time) 40 + |> Object.opt_mem "duration" int ~enc:(fun c -> Some c.duration) 41 + |> Object.skip_unknown |> Object.finish 44 42 45 43 let timer_codec = 46 - Json.Codec.Object.map ~kind:"timer" (fun channel timer_type down -> 44 + let open Json.Codec in 45 + Object.map ~kind:"timer" (fun channel timer_type down -> 47 46 { 48 47 channel = Option.value ~default:0 channel; 49 48 timer_type = Option.value ~default:1 timer_type; 50 49 down; 51 50 }) 52 - |> Json.Codec.Object.opt_mem "channel" Json.Codec.int ~enc:(fun t -> 53 - Some t.channel) 54 - |> Json.Codec.Object.opt_mem "type" Json.Codec.int ~enc:(fun t -> 55 - Some t.timer_type) 56 - |> Json.Codec.Object.opt_mem "down" countdown_codec ~enc:(fun t -> t.down) 57 - |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 51 + |> Object.opt_mem "channel" int ~enc:(fun t -> Some t.channel) 52 + |> Object.opt_mem "type" int ~enc:(fun t -> Some t.timer_type) 53 + |> Object.opt_mem "down" countdown_codec ~enc:(fun t -> t.down) 54 + |> Object.skip_unknown |> Object.finish 58 55 59 56 type payload = { timerx : t list } 60 57 (** Payload with timer list *) 61 58 62 59 let payload_codec = 63 - Json.Codec.Object.map ~kind:"timerx_payload" (fun t -> { timerx = t }) 64 - |> Json.Codec.Object.mem "timerx" (Json.Codec.list timer_codec) ~enc:(fun p -> 65 - p.timerx) 66 - |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 60 + let open Json.Codec in 61 + Object.map ~kind:"timerx_payload" (fun t -> { timerx = t }) 62 + |> Object.mem "timerx" (list timer_codec) ~enc:(fun p -> p.timerx) 63 + |> Object.skip_unknown |> Object.finish 67 64 68 65 (** {1 Operations} *) 69 66 70 67 (** Get all timers *) 71 68 let get ~http ~sw ip = 72 69 let json = 70 + let open Json.Codec in 73 71 P.request_empty ~method_:"GET" ~namespace:"Appliance.Control.TimerX" 74 72 in 75 73 let* resp = P.http_post ~http ~sw ip json in