Improve overview and experiment naming
[khatus.git] / x3 / src / lib / khatus_state.ml
CommitLineData
6f35286a
SK
1module Cache = Khatus_cache
2module Msg = Khatus_msg
3module Time = Khatus_time
4
5type t =
6 { node : string
7 ; modul : string
8 ; time : Time.t
9 ; cache : Cache.t
10 }
11
12let init ~node ~modul =
13 { node
14 ; modul
15 ; time = Time.init
16 ; cache = Cache.create ()
17 }
18
19(* TODO: Should probably wrap state update in result. *)
20let update ({node; modul = _; time; cache} as t) ~msg =
21 Msg.handle_data msg ~otherwise:t ~f:(fun ~node:src_node ~modul ~key ~value ->
22 let time =
23 match (modul, key) with
24 | ("khatus_sensor_datetime", ["epoch"]) when src_node = node ->
25 Time.of_string value (* Raises if value is not a number *)
26 | (_, _) ->
27 time
28 in
29 Cache.update cache ~node:src_node ~modul ~key ~value ~time;
30 {t with time}
31 )
This page took 0.019163 seconds and 4 git commands to generate.