1 module Cache = Khatus_cache
2 module Msg = Khatus_msg
3 module Time = Khatus_time
12 let init ~node ~modul =
16 ; cache = Cache.create ()
19 (* TODO: Should probably wrap state update in result. *)
20 let update ({node; modul = _; time; cache} as t) ~msg =
21 Msg.handle_data msg ~otherwise:t ~f:(fun ~node:src_node ~modul ~key ~value ->
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 *)
29 Cache.update cache ~node:src_node ~modul ~key ~value ~time;