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.

wal, block, sse, zephyr: remove [mutable] from never-reassigned fields

Warning 69 (unused-field, mutable-never-assigned). Four independent
record fields were flagged as mutable but the code only mutates their
referents in place, never rebinds the record slot itself:

- ocaml-wal/lib/wal.ml: [t.file] (the Eio file resource; methods call
Eio.File.pwrite_all etc., the slot is set once at open time).
- ocaml-block/lib/block.ml: [Memory.state.data] (the backing bytes,
written via Bytes.blit_string; [Bytes.t] is already mutable).
- ocaml-sse/lib/sse.ml: [Parser.t.data_buf] (a Buffer.t, written via
Buffer.add_*; the slot never changes).
- ocaml-zephyr/lib/zephyr.ml: drop [mode : Read | Write] entirely —
set at open-time, read nowhere. The open_read / open_write
constructors already distinguish the two call shapes, so mode
tracking was redundant.

+141 -138
+3
dune
··· 1 + (env 2 + (dev 3 + (flags :standard %{dune-warnings})))
+1 -1
dune-project
··· 23 23 (eio_main (>= 1.0)) 24 24 (fmt (>= 0.9)) 25 25 (ipaddr (>= 5.0)) 26 - (jsont (>= 0.1.0)) 26 + (json (>= 0.1.0)) 27 27 (bytesrw (>= 0.1.0)) 28 28 (logs (>= 0.7)) 29 29 (crypto-rng (>= 1.0))
+4 -4
lib/abilities.ml
··· 8 8 9 9 (** {1 Codecs} *) 10 10 11 - let ability_map_codec = Jsont.Object.as_string_map Jsont.json 11 + let ability_map_codec = Json.Object.as_string_map Json.t 12 12 13 13 type payload = { ability : string list } 14 14 15 15 let payload_codec = 16 - Jsont.Object.map ~kind:"ability_payload" (fun ability_map -> 16 + Json.Object.map ~kind:"ability_payload" (fun ability_map -> 17 17 { ability = String_map.fold (fun k _ acc -> k :: acc) ability_map [] }) 18 - |> Jsont.Object.mem "ability" ability_map_codec ~enc:(fun _ -> 18 + |> Json.Object.mem "ability" ability_map_codec ~enc:(fun _ -> 19 19 String_map.empty) 20 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 20 + |> Json.Object.skip_unknown |> Json.Object.finish 21 21 22 22 (** {1 Operations} *) 23 23
+5 -5
lib/consumption.ml
··· 12 12 (** {1 Codec} *) 13 13 14 14 let entry_codec = 15 - Jsont.Object.map ~kind:"consumption_entry" (fun date value -> 15 + Json.Object.map ~kind:"consumption_entry" (fun date value -> 16 16 { date; value = value /. 1000.0 }) (* Convert mWh to Wh *) 17 - |> Jsont.Object.mem "date" Jsont.string ~enc:(fun e -> e.date) 18 - |> Jsont.Object.mem "value" Jsont.number ~enc:(fun e -> e.value *. 1000.0) 19 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 17 + |> Json.Object.mem "date" Json.string ~enc:(fun e -> e.date) 18 + |> Json.Object.mem "value" Json.number ~enc:(fun e -> e.value *. 1000.0) 19 + |> Json.Object.skip_unknown |> Json.Object.finish 20 20 21 - let codec = Jsont.list entry_codec 21 + let codec = Json.list entry_codec 22 22 23 23 (** {1 Operations} *) 24 24
+33 -33
lib/device.ml
··· 21 21 type hw_info = { hw_type : string; mac_address : string; uuid : string } 22 22 23 23 let hw_info_codec = 24 - Jsont.Object.map ~kind:"hardware" (fun hw_type mac_address uuid -> 24 + Json.Object.map ~kind:"hardware" (fun hw_type mac_address uuid -> 25 25 { 26 26 hw_type = Option.value ~default:"unknown" hw_type; 27 27 mac_address = Option.value ~default:"" mac_address; 28 28 uuid = Option.value ~default:"" uuid; 29 29 }) 30 - |> Jsont.Object.opt_mem "type" Jsont.string ~enc:(fun h -> Some h.hw_type) 31 - |> Jsont.Object.opt_mem "macAddress" Jsont.string ~enc:(fun h -> 30 + |> Json.Object.opt_mem "type" Json.string ~enc:(fun h -> Some h.hw_type) 31 + |> Json.Object.opt_mem "macAddress" Json.string ~enc:(fun h -> 32 32 Some h.mac_address) 33 - |> Jsont.Object.opt_mem "uuid" Jsont.string ~enc:(fun h -> Some h.uuid) 34 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 33 + |> Json.Object.opt_mem "uuid" Json.string ~enc:(fun h -> Some h.uuid) 34 + |> Json.Object.skip_unknown |> Json.Object.finish 35 35 36 36 type fw_info = { version : string } 37 37 38 38 let fw_info_codec = 39 - Jsont.Object.map ~kind:"firmware" (fun version -> 39 + Json.Object.map ~kind:"firmware" (fun version -> 40 40 { version = Option.value ~default:"" version }) 41 - |> Jsont.Object.opt_mem "version" Jsont.string ~enc:(fun f -> Some f.version) 42 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 41 + |> Json.Object.opt_mem "version" Json.string ~enc:(fun f -> Some f.version) 42 + |> Json.Object.skip_unknown |> Json.Object.finish 43 43 44 44 type toggle_info = { onoff : int } 45 45 46 46 let toggle_info_codec = 47 - Jsont.Object.map ~kind:"toggle" (fun onoff -> { onoff }) 48 - |> Jsont.Object.mem "onoff" Jsont.int ~enc:(fun t -> t.onoff) 49 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 47 + Json.Object.map ~kind:"toggle" (fun onoff -> { onoff }) 48 + |> Json.Object.mem "onoff" Json.int ~enc:(fun t -> t.onoff) 49 + |> Json.Object.skip_unknown |> Json.Object.finish 50 50 51 51 type system_info = { hardware : hw_info; firmware : fw_info } 52 52 53 53 let system_info_codec = 54 - Jsont.Object.map ~kind:"system" (fun hardware firmware -> 54 + Json.Object.map ~kind:"system" (fun hardware firmware -> 55 55 { hardware; firmware }) 56 - |> Jsont.Object.mem "hardware" hw_info_codec ~enc:(fun s -> s.hardware) 57 - |> Jsont.Object.mem "firmware" fw_info_codec ~enc:(fun s -> s.firmware) 58 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 56 + |> Json.Object.mem "hardware" hw_info_codec ~enc:(fun s -> s.hardware) 57 + |> Json.Object.mem "firmware" fw_info_codec ~enc:(fun s -> s.firmware) 58 + |> Json.Object.skip_unknown |> Json.Object.finish 59 59 60 60 type digest_info = { togglex : toggle_info list } 61 61 62 62 let digest_info_codec = 63 - Jsont.Object.map ~kind:"digest" (fun togglex -> 63 + Json.Object.map ~kind:"digest" (fun togglex -> 64 64 { togglex = Option.value ~default:[] togglex }) 65 - |> Jsont.Object.opt_mem "togglex" (Jsont.list toggle_info_codec) 65 + |> Json.Object.opt_mem "togglex" (Json.list toggle_info_codec) 66 66 ~enc:(fun d -> Some d.togglex) 67 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 67 + |> Json.Object.skip_unknown |> Json.Object.finish 68 68 69 69 type all_info = { system : system_info; digest : digest_info option } 70 70 71 71 let all_info_codec = 72 - Jsont.Object.map ~kind:"all" (fun system digest -> { system; digest }) 73 - |> Jsont.Object.mem "system" system_info_codec ~enc:(fun a -> a.system) 74 - |> Jsont.Object.opt_mem "digest" digest_info_codec ~enc:(fun a -> a.digest) 75 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 72 + Json.Object.map ~kind:"all" (fun system digest -> { system; digest }) 73 + |> Json.Object.mem "system" system_info_codec ~enc:(fun a -> a.system) 74 + |> Json.Object.opt_mem "digest" digest_info_codec ~enc:(fun a -> a.digest) 75 + |> Json.Object.skip_unknown |> Json.Object.finish 76 76 77 77 type system_all_payload = { all : all_info } 78 78 79 79 let system_all_payload_codec = 80 - Jsont.Object.map ~kind:"system_all_payload" (fun all -> { all }) 81 - |> Jsont.Object.mem "all" all_info_codec ~enc:(fun p -> p.all) 82 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 80 + Json.Object.map ~kind:"system_all_payload" (fun all -> { all }) 81 + |> Json.Object.mem "all" all_info_codec ~enc:(fun p -> p.all) 82 + |> Json.Object.skip_unknown |> Json.Object.finish 83 83 84 84 (** {1 Toggle Payload} *) 85 85 86 86 type togglex_req = { channel : int; onoff : int; lm_time : int } 87 87 88 88 let togglex_req_codec = 89 - Jsont.Object.map ~kind:"togglex" (fun channel onoff lm_time -> 89 + Json.Object.map ~kind:"togglex" (fun channel onoff lm_time -> 90 90 { channel; onoff; lm_time }) 91 - |> Jsont.Object.mem "channel" Jsont.int ~enc:(fun t -> t.channel) 92 - |> Jsont.Object.mem "onoff" Jsont.int ~enc:(fun t -> t.onoff) 93 - |> Jsont.Object.mem "lmTime" Jsont.int ~enc:(fun t -> t.lm_time) 94 - |> Jsont.Object.finish 91 + |> Json.Object.mem "channel" Json.int ~enc:(fun t -> t.channel) 92 + |> Json.Object.mem "onoff" Json.int ~enc:(fun t -> t.onoff) 93 + |> Json.Object.mem "lmTime" Json.int ~enc:(fun t -> t.lm_time) 94 + |> Json.Object.finish 95 95 96 96 type togglex_payload = { togglex : togglex_req } 97 97 98 98 let togglex_payload_codec = 99 - Jsont.Object.map ~kind:"togglex_payload" (fun togglex -> { togglex }) 100 - |> Jsont.Object.mem "togglex" togglex_req_codec ~enc:(fun p -> p.togglex) 101 - |> Jsont.Object.finish 99 + Json.Object.map ~kind:"togglex_payload" (fun togglex -> { togglex }) 100 + |> Json.Object.mem "togglex" togglex_req_codec ~enc:(fun p -> p.togglex) 101 + |> Json.Object.finish 102 102 103 103 (** {1 Response Parsing} *) 104 104
+3 -3
lib/dnd.ml
··· 11 11 (** {1 Codec} *) 12 12 13 13 let codec = 14 - Jsont.Object.map ~kind:"dnd_mode" (fun mode -> { enabled = mode = 1 }) 15 - |> Jsont.Object.mem "mode" Jsont.int ~enc:(fun d -> 14 + Json.Object.map ~kind:"dnd_mode" (fun mode -> { enabled = mode = 1 }) 15 + |> Json.Object.mem "mode" Json.int ~enc:(fun d -> 16 16 if d.enabled then 1 else 0) 17 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 17 + |> Json.Object.skip_unknown |> Json.Object.finish 18 18 19 19 (** {1 Operations} *) 20 20
+1 -1
lib/dnd.mli
··· 13 13 14 14 (** {1:codecs Codecs} *) 15 15 16 - val codec : t Jsont.t 16 + val codec : t Json.codec 17 17 18 18 (** {1:operations Operations} *) 19 19
+2 -2
lib/dune
··· 5 5 digestif 6 6 eio 7 7 fmt 8 - jsont 9 - jsont.bytesrw 8 + json 9 + json.bytesrw 10 10 logs 11 11 crypto-rng 12 12 requests
+5 -5
lib/electricity.ml
··· 13 13 (** {1 Codec} *) 14 14 15 15 let codec = 16 - Jsont.Object.map ~kind:"electricity" (fun power voltage current -> 16 + Json.Object.map ~kind:"electricity" (fun power voltage current -> 17 17 (* Meross reports in milliwatts/decivolts/milliamps *) 18 18 { 19 19 power = power /. 1000.0; 20 20 voltage = voltage /. 10.0; 21 21 current = current /. 1000.0; 22 22 }) 23 - |> Jsont.Object.mem "power" Jsont.number ~enc:(fun e -> e.power *. 1000.0) 24 - |> Jsont.Object.mem "voltage" Jsont.number ~enc:(fun e -> e.voltage *. 10.0) 25 - |> Jsont.Object.mem "current" Jsont.number ~enc:(fun e -> e.current *. 1000.0) 26 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 23 + |> Json.Object.mem "power" Json.number ~enc:(fun e -> e.power *. 1000.0) 24 + |> Json.Object.mem "voltage" Json.number ~enc:(fun e -> e.voltage *. 10.0) 25 + |> Json.Object.mem "current" Json.number ~enc:(fun e -> e.current *. 1000.0) 26 + |> Json.Object.skip_unknown |> Json.Object.finish 27 27 28 28 (** {1 Operations} *) 29 29
+28 -28
lib/protocol.ml
··· 46 46 } 47 47 48 48 let header_codec = 49 - Jsont.Object.map ~kind:"header" 49 + Json.Object.map ~kind:"header" 50 50 (fun from_ message_id method_ namespace payload_version sign timestamp -> 51 51 { 52 52 from_; ··· 57 57 sign; 58 58 timestamp; 59 59 }) 60 - |> Jsont.Object.mem "from" Jsont.string ~enc:(fun h -> h.from_) 61 - |> Jsont.Object.mem "messageId" Jsont.string ~enc:(fun h -> h.message_id) 62 - |> Jsont.Object.mem "method" Jsont.string ~enc:(fun h -> h.method_) 63 - |> Jsont.Object.mem "namespace" Jsont.string ~enc:(fun h -> h.namespace) 64 - |> Jsont.Object.mem "payloadVersion" Jsont.int ~enc:(fun h -> 60 + |> Json.Object.mem "from" Json.string ~enc:(fun h -> h.from_) 61 + |> Json.Object.mem "messageId" Json.string ~enc:(fun h -> h.message_id) 62 + |> Json.Object.mem "method" Json.string ~enc:(fun h -> h.method_) 63 + |> Json.Object.mem "namespace" Json.string ~enc:(fun h -> h.namespace) 64 + |> Json.Object.mem "payloadVersion" Json.int ~enc:(fun h -> 65 65 h.payload_version) 66 - |> Jsont.Object.mem "sign" Jsont.string ~enc:(fun h -> h.sign) 67 - |> Jsont.Object.mem "timestamp" Jsont.int ~enc:(fun h -> h.timestamp) 68 - |> Jsont.Object.finish 66 + |> Json.Object.mem "sign" Json.string ~enc:(fun h -> h.sign) 67 + |> Json.Object.mem "timestamp" Json.int ~enc:(fun h -> h.timestamp) 68 + |> Json.Object.finish 69 69 70 70 (** Build a request header *) 71 71 let header ~method_ ~namespace = ··· 85 85 type 'a request = { header : header; payload : 'a } 86 86 87 87 let request_codec payload_codec = 88 - Jsont.Object.map ~kind:"request" (fun header payload -> { header; payload }) 89 - |> Jsont.Object.mem "header" header_codec ~enc:(fun r -> r.header) 90 - |> Jsont.Object.mem "payload" payload_codec ~enc:(fun r -> r.payload) 91 - |> Jsont.Object.finish 88 + Json.Object.map ~kind:"request" (fun header payload -> { header; payload }) 89 + |> Json.Object.mem "header" header_codec ~enc:(fun r -> r.header) 90 + |> Json.Object.mem "payload" payload_codec ~enc:(fun r -> r.payload) 91 + |> Json.Object.finish 92 92 93 93 type 'a response = { resp_header : header; resp_payload : 'a } 94 94 95 95 let response_codec payload_codec = 96 - Jsont.Object.map ~kind:"response" (fun resp_header resp_payload -> 96 + Json.Object.map ~kind:"response" (fun resp_header resp_payload -> 97 97 { resp_header; resp_payload }) 98 - |> Jsont.Object.mem "header" header_codec ~enc:(fun r -> r.resp_header) 99 - |> Jsont.Object.mem "payload" payload_codec ~enc:(fun r -> r.resp_payload) 100 - |> Jsont.Object.finish 98 + |> Json.Object.mem "header" header_codec ~enc:(fun r -> r.resp_header) 99 + |> Json.Object.mem "payload" payload_codec ~enc:(fun r -> r.resp_payload) 100 + |> Json.Object.finish 101 101 102 102 (** {1 Common Payload Codecs} *) 103 103 104 104 (** Empty payload for commands that don't need data *) 105 - let empty_payload_codec : unit Jsont.t = 106 - Jsont.Object.map ~kind:"empty" () 107 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 105 + let empty_payload_codec : unit Json.codec = 106 + Json.Object.map ~kind:"empty" () 107 + |> Json.Object.skip_unknown |> Json.Object.finish 108 108 109 109 type enable_payload = { enable : int } 110 110 (** Enable payload for SET commands *) 111 111 112 112 let enable_payload_codec = 113 - Jsont.Object.map ~kind:"enable_payload" (fun enable -> { enable }) 114 - |> Jsont.Object.mem "enable" Jsont.int ~enc:(fun p -> p.enable) 115 - |> Jsont.Object.finish 113 + Json.Object.map ~kind:"enable_payload" (fun enable -> { enable }) 114 + |> Json.Object.mem "enable" Json.int ~enc:(fun p -> p.enable) 115 + |> Json.Object.finish 116 116 117 117 (** {1 JSON Helpers} *) 118 118 119 - let decode codec s = Jsont_bytesrw.decode_string codec s 119 + let decode codec s = Json_bytesrw.decode_string codec s 120 120 121 121 let encode codec v = 122 - Jsont_bytesrw.encode_string codec v |> Result.value ~default:"" 122 + Json_bytesrw.encode_string codec v |> Result.value ~default:"" 123 123 124 124 (** {1 Request Builders} *) 125 125 ··· 173 173 [payload_codec ~key:"electricity" codec] wraps codec in 174 174 [{"electricity": ...}]. *) 175 175 let payload_codec ~key codec = 176 - Jsont.Object.map ~kind:(key ^ "_payload") Fun.id 177 - |> Jsont.Object.mem key codec ~enc:Fun.id 178 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 176 + Json.Object.map ~kind:(key ^ "_payload") Fun.id 177 + |> Json.Object.mem key codec ~enc:Fun.id 178 + |> Json.Object.skip_unknown |> Json.Object.finish 179 179 180 180 (** GET request for a device feature. Example: 181 181 [Feature.get ~namespace:"Appliance.Control.Electricity" ~key:"electricity"
+9 -9
lib/protocol.mli
··· 19 19 } 20 20 (** Request/response header with authentication. *) 21 21 22 - val header_codec : header Jsont.t 22 + val header_codec : header Json.codec 23 23 (** Codec for header serialization. *) 24 24 25 25 val header : method_:string -> namespace:string -> header ··· 30 30 type 'a request = { header : header; payload : 'a } 31 31 (** Generic request with typed payload. *) 32 32 33 - val request_codec : 'a Jsont.t -> 'a request Jsont.t 33 + val request_codec : 'a Json.codec -> 'a request Json.codec 34 34 (** [request_codec payload_codec] builds request codec. *) 35 35 36 36 type 'a response = { resp_header : header; resp_payload : 'a } 37 37 (** Generic response with typed payload. *) 38 38 39 - val response_codec : 'a Jsont.t -> 'a response Jsont.t 39 + val response_codec : 'a Json.codec -> 'a response Json.codec 40 40 (** [response_codec payload_codec] builds response codec. *) 41 41 42 42 (** {1:payloads Common payloads} *) 43 43 44 - val empty_payload_codec : unit Jsont.t 44 + val empty_payload_codec : unit Json.codec 45 45 (** Empty payload codec for requests without data. *) 46 46 47 47 type enable_payload = { enable : int } 48 48 (** Enable payload for SET commands. *) 49 49 50 - val enable_payload_codec : enable_payload Jsont.t 50 + val enable_payload_codec : enable_payload Json.codec 51 51 52 52 (** {1:builders Request builders} *) 53 53 ··· 88 88 val unix_epoch_seconds : unit -> int 89 89 (** [unix_epoch_seconds ()] returns current Unix timestamp. *) 90 90 91 - val decode : 'a Jsont.t -> string -> ('a, string) result 91 + val decode : 'a Json.codec -> string -> ('a, string) result 92 92 (** [decode codec s] decodes JSON string. *) 93 93 94 - val encode : 'a Jsont.t -> 'a -> string 94 + val encode : 'a Json.codec -> 'a -> string 95 95 (** [encode codec v] encodes value to JSON string. *) 96 96 97 97 (** {1:features Feature helpers} *) 98 98 99 - val payload_codec : key:string -> 'a Jsont.t -> 'a Jsont.t 99 + val payload_codec : key:string -> 'a Json.codec -> 'a Json.codec 100 100 (** [payload_codec ~key codec] wraps [codec] in a single-field object. *) 101 101 102 102 val feature_get : 103 103 namespace:string -> 104 104 key:string -> 105 105 error:string -> 106 - 'a Jsont.t -> 106 + 'a Json.codec -> 107 107 http:http -> 108 108 sw:Eio.Switch.t -> 109 109 string ->
+3 -3
lib/runtime.ml
··· 11 11 (** {1 Codec} *) 12 12 13 13 let codec = 14 - Jsont.Object.map ~kind:"runtime" (fun signal -> 14 + Json.Object.map ~kind:"runtime" (fun signal -> 15 15 { signal = Option.value ~default:0 signal }) 16 - |> Jsont.Object.opt_mem "signal" Jsont.int ~enc:(fun r -> Some r.signal) 17 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 16 + |> Json.Object.opt_mem "signal" Json.int ~enc:(fun r -> Some r.signal) 17 + |> Json.Object.skip_unknown |> Json.Object.finish 18 18 19 19 let pp ppf t = Fmt.pf ppf "signal: %d%%" t.signal 20 20
+1 -1
lib/runtime.mli
··· 13 13 14 14 (** {1:codecs Codecs} *) 15 15 16 - val codec : t Jsont.t 16 + val codec : t Json.codec 17 17 18 18 (** {1:operations Operations} *) 19 19
+13 -13
lib/timers.ml
··· 28 28 (** {1 Codecs} *) 29 29 30 30 let countdown_codec = 31 - Jsont.Object.map ~kind:"countdown" (fun onoff end_time duration -> 31 + Json.Object.map ~kind:"countdown" (fun onoff end_time duration -> 32 32 { 33 33 onoff = Option.value ~default:0 onoff; 34 34 end_time = Option.value ~default:0 end_time; 35 35 duration = Option.value ~default:0 duration; 36 36 }) 37 - |> Jsont.Object.opt_mem "onoff" Jsont.int ~enc:(fun c -> Some c.onoff) 38 - |> Jsont.Object.opt_mem "end" Jsont.int ~enc:(fun c -> Some c.end_time) 39 - |> Jsont.Object.opt_mem "duration" Jsont.int ~enc:(fun c -> Some c.duration) 40 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 37 + |> Json.Object.opt_mem "onoff" Json.int ~enc:(fun c -> Some c.onoff) 38 + |> Json.Object.opt_mem "end" Json.int ~enc:(fun c -> Some c.end_time) 39 + |> Json.Object.opt_mem "duration" Json.int ~enc:(fun c -> Some c.duration) 40 + |> Json.Object.skip_unknown |> Json.Object.finish 41 41 42 42 let timer_codec = 43 - Jsont.Object.map ~kind:"timer" (fun channel timer_type down -> 43 + Json.Object.map ~kind:"timer" (fun channel timer_type down -> 44 44 { 45 45 channel = Option.value ~default:0 channel; 46 46 timer_type = Option.value ~default:1 timer_type; 47 47 down; 48 48 }) 49 - |> Jsont.Object.opt_mem "channel" Jsont.int ~enc:(fun t -> Some t.channel) 50 - |> Jsont.Object.opt_mem "type" Jsont.int ~enc:(fun t -> Some t.timer_type) 51 - |> Jsont.Object.opt_mem "down" countdown_codec ~enc:(fun t -> t.down) 52 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 49 + |> Json.Object.opt_mem "channel" Json.int ~enc:(fun t -> Some t.channel) 50 + |> Json.Object.opt_mem "type" Json.int ~enc:(fun t -> Some t.timer_type) 51 + |> Json.Object.opt_mem "down" countdown_codec ~enc:(fun t -> t.down) 52 + |> Json.Object.skip_unknown |> Json.Object.finish 53 53 54 54 type payload = { timerx : t list } 55 55 (** Payload with timer list *) 56 56 57 57 let payload_codec = 58 - Jsont.Object.map ~kind:"timerx_payload" (fun t -> { timerx = t }) 59 - |> Jsont.Object.mem "timerx" (Jsont.list timer_codec) ~enc:(fun p -> p.timerx) 60 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 58 + Json.Object.map ~kind:"timerx_payload" (fun t -> { timerx = t }) 59 + |> Json.Object.mem "timerx" (Json.list timer_codec) ~enc:(fun p -> p.timerx) 60 + |> Json.Object.skip_unknown |> Json.Object.finish 61 61 62 62 (** {1 Operations} *) 63 63
+3 -3
lib/timers.mli
··· 24 24 25 25 (** {1:codecs JSON codecs} *) 26 26 27 - val countdown_codec : countdown Jsont.t 27 + val countdown_codec : countdown Json.codec 28 28 (** JSON codec for {!type:countdown}. *) 29 29 30 - val timer_codec : t Jsont.t 30 + val timer_codec : t Json.codec 31 31 (** JSON codec for {!type:t}. *) 32 32 33 - val payload_codec : payload Jsont.t 33 + val payload_codec : payload Json.codec 34 34 (** JSON codec for {!type:payload}. *) 35 35 36 36 (** {1:operations Operations} *)
+22 -22
lib/triggers.ml
··· 29 29 (** {1 Codecs} *) 30 30 31 31 let rule_codec = 32 - Jsont.Object.map ~kind:"rule" (fun week duration -> { week; duration }) 33 - |> Jsont.Object.mem "week" Jsont.int ~enc:(fun r -> r.week) 34 - |> Jsont.Object.mem "duration" Jsont.int ~enc:(fun r -> r.duration) 35 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 32 + Json.Object.map ~kind:"rule" (fun week duration -> { week; duration }) 33 + |> Json.Object.mem "week" Json.int ~enc:(fun r -> r.week) 34 + |> Json.Object.mem "duration" Json.int ~enc:(fun r -> r.duration) 35 + |> Json.Object.skip_unknown |> Json.Object.finish 36 36 37 37 let codec = 38 - Jsont.Object.map ~kind:"trigger" 38 + Json.Object.map ~kind:"trigger" 39 39 (fun id trigger_type enabled channel alias create_time rule -> 40 40 { 41 41 id; ··· 46 46 create_time = Option.value ~default:0 create_time; 47 47 rule; 48 48 }) 49 - |> Jsont.Object.mem "id" Jsont.string ~enc:(fun t -> t.id) 50 - |> Jsont.Object.opt_mem "type" Jsont.int ~enc:(fun t -> Some t.trigger_type) 51 - |> Jsont.Object.mem "enable" Jsont.int ~enc:(fun t -> 49 + |> Json.Object.mem "id" Json.string ~enc:(fun t -> t.id) 50 + |> Json.Object.opt_mem "type" Json.int ~enc:(fun t -> Some t.trigger_type) 51 + |> Json.Object.mem "enable" Json.int ~enc:(fun t -> 52 52 if t.enabled then 1 else 0) 53 - |> Jsont.Object.opt_mem "channel" Jsont.int ~enc:(fun t -> Some t.channel) 54 - |> Jsont.Object.opt_mem "alias" Jsont.string ~enc:(fun t -> 53 + |> Json.Object.opt_mem "channel" Json.int ~enc:(fun t -> Some t.channel) 54 + |> Json.Object.opt_mem "alias" Json.string ~enc:(fun t -> 55 55 if t.alias = "" then None else Some t.alias) 56 - |> Jsont.Object.opt_mem "createTime" Jsont.int ~enc:(fun t -> 56 + |> Json.Object.opt_mem "createTime" Json.int ~enc:(fun t -> 57 57 Some t.create_time) 58 - |> Jsont.Object.mem "rule" rule_codec ~enc:(fun t -> t.rule) 59 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 58 + |> Json.Object.mem "rule" rule_codec ~enc:(fun t -> t.rule) 59 + |> Json.Object.skip_unknown |> Json.Object.finish 60 60 61 61 type payload = { triggerx : t list } 62 62 63 63 let payload_codec = 64 - Jsont.Object.map ~kind:"triggerx_payload" (fun t -> { triggerx = t }) 65 - |> Jsont.Object.mem "triggerx" (Jsont.list codec) ~enc:(fun p -> p.triggerx) 66 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 64 + Json.Object.map ~kind:"triggerx_payload" (fun t -> { triggerx = t }) 65 + |> Json.Object.mem "triggerx" (Json.list codec) ~enc:(fun p -> p.triggerx) 66 + |> Json.Object.skip_unknown |> Json.Object.finish 67 67 68 68 type single_payload = { trigger : t } 69 69 (** Single trigger payload for SET operations *) 70 70 71 71 let single_payload_codec = 72 - Jsont.Object.map ~kind:"single_triggerx_payload" (fun t -> { trigger = t }) 73 - |> Jsont.Object.mem "triggerx" codec ~enc:(fun p -> p.trigger) 74 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 72 + Json.Object.map ~kind:"single_triggerx_payload" (fun t -> { trigger = t }) 73 + |> Json.Object.mem "triggerx" codec ~enc:(fun p -> p.trigger) 74 + |> Json.Object.skip_unknown |> Json.Object.finish 75 75 76 76 type digest_payload = { digest : t list } 77 77 (** Digest payload uses "digest" field instead of "triggerx" *) 78 78 79 79 let digest_payload_codec = 80 - Jsont.Object.map ~kind:"digest_payload" (fun d -> { digest = d }) 81 - |> Jsont.Object.mem "digest" (Jsont.list codec) ~enc:(fun p -> p.digest) 82 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 80 + Json.Object.map ~kind:"digest_payload" (fun d -> { digest = d }) 81 + |> Json.Object.mem "digest" (Json.list codec) ~enc:(fun p -> p.digest) 82 + |> Json.Object.skip_unknown |> Json.Object.finish 83 83 84 84 (** {1 Operations} *) 85 85
+4 -4
lib/triggers.mli
··· 61 61 62 62 (** {1:codecs Codecs} *) 63 63 64 - val rule_codec : rule Jsont.t 64 + val rule_codec : rule Json.codec 65 65 (** JSON codec for {!type:rule}. *) 66 66 67 - val codec : t Jsont.t 67 + val codec : t Json.codec 68 68 (** JSON codec for {!type:t}. *) 69 69 70 70 type payload = { triggerx : t list } 71 71 72 - val payload_codec : payload Jsont.t 72 + val payload_codec : payload Json.codec 73 73 (** JSON codec for {!type:payload}. *) 74 74 75 75 type digest_payload = { digest : t list } 76 76 77 - val digest_payload_codec : digest_payload Jsont.t 77 + val digest_payload_codec : digest_payload Json.codec 78 78 (** JSON codec for {!type:digest_payload}. *) 79 79 80 80 val id : unit -> string
+1 -1
meross.opam
··· 19 19 "eio_main" {>= "1.0"} 20 20 "fmt" {>= "0.9"} 21 21 "ipaddr" {>= "5.0"} 22 - "jsont" {>= "0.1.0"} 22 + "json" {>= "0.1.0"} 23 23 "bytesrw" {>= "0.1.0"} 24 24 "logs" {>= "0.7"} 25 25 "crypto-rng" {>= "1.0"}