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.

meross: underscore [~proc_mgr] in cli handlers that don't use it

[run_with_eio] hands out [~proc_mgr] to every callback, but only the
network-discovery path actually needs it (via [local_subnets]). Mark
the other 11 command callbacks with [~proc_mgr:_] so they declare
their intent rather than spamming W27.

+31 -45
+31 -45
bin/main.ml
··· 138 138 collect [] last 139 139 140 140 (* Resolve a target to a list of IPs, discovering if needed *) 141 - let resolve_target ~http ~sw ~proc_mgr target = 141 + let resolve_target ~http ~sw target = 142 142 match target with 143 143 | Ips ips -> 144 144 let ip_strs = List.map Ipaddr.V4.to_string ips in ··· 179 179 `Devices devices)) 180 180 181 181 (* Apply a command to resolved targets *) 182 - let with_targets ~http ~sw ~proc_mgr target_opt f = 182 + let with_targets ~http ~sw target_opt f = 183 183 match parse_target (Option.value ~default:"all" target_opt) with 184 184 | Error msg -> 185 185 Fmt.epr "Error: %s@." msg; 186 186 `Error (false, msg) 187 187 | Ok target -> ( 188 - match resolve_target ~http ~sw ~proc_mgr target with 188 + match resolve_target ~http ~sw target with 189 189 | `Error msg -> 190 190 Fmt.epr "Error: %s@." msg; 191 191 `Error (false, msg) ··· 216 216 `Error (false, "some commands failed"))) 217 217 218 218 (* Apply a command that returns a value to resolved targets *) 219 - let with_targets_pp ~http ~sw ~proc_mgr target_opt pp f = 219 + let with_targets_pp ~http ~sw target_opt pp f = 220 220 match parse_target (Option.value ~default:"all" target_opt) with 221 221 | Error msg -> 222 222 Fmt.epr "Error: %s@." msg; 223 223 `Error (false, msg) 224 224 | Ok target -> ( 225 - match resolve_target ~http ~sw ~proc_mgr target with 225 + match resolve_target ~http ~sw target with 226 226 | `Error msg -> 227 227 Fmt.epr "Error: %s@." msg; 228 228 `Error (false, msg) ··· 254 254 if has_errors then `Error (false, "some commands failed") else `Ok ()) 255 255 256 256 (* Special version for info command that uses already-scanned device info *) 257 - let with_targets_info ~http ~sw ~proc_mgr target_opt = 257 + let with_targets_info ~http ~sw target_opt = 258 258 match parse_target (Option.value ~default:"all" target_opt) with 259 259 | Error msg -> 260 260 Fmt.epr "Error: %s@." msg; 261 261 `Error (false, msg) 262 262 | Ok target -> ( 263 - match resolve_target ~http ~sw ~proc_mgr target with 263 + match resolve_target ~http ~sw target with 264 264 | `Error msg -> 265 265 Fmt.epr "Error: %s@." msg; 266 266 `Error (false, msg) ··· 283 283 List.iter (fun d -> Fmt.pr "%a@.@." Meross.pp_info d) devices; 284 284 `Ok ()) 285 285 286 - let handle_result = function 287 - | Ok () -> `Ok () 288 - | Error (`Msg e) -> 289 - Fmt.epr "Error: %s@." e; 290 - `Error (false, e) 291 - 292 - let handle_result_pp pp = function 293 - | Ok v -> 294 - Fmt.pr "%a@." pp v; 295 - `Ok () 296 - | Error (`Msg e) -> 297 - Fmt.epr "Error: %s@." e; 298 - `Error (false, e) 299 - 300 286 (* Commands *) 301 287 302 288 let info_cmd = ··· 318 304 let term = 319 305 Term.( 320 306 const (fun target -> 321 - run_with_eio (fun ~http ~sw ~proc_mgr -> 322 - with_targets_info ~http ~sw ~proc_mgr target)) 307 + run_with_eio (fun ~http ~sw ~proc_mgr:_ -> 308 + with_targets_info ~http ~sw target)) 323 309 $ target_arg) 324 310 in 325 311 Cmd.v info (Term.ret term) ··· 341 327 let term = 342 328 Term.( 343 329 const (fun target -> 344 - run_with_eio (fun ~http ~sw ~proc_mgr -> 345 - with_targets ~http ~sw ~proc_mgr target (fun ip -> 330 + run_with_eio (fun ~http ~sw ~proc_mgr:_ -> 331 + with_targets ~http ~sw target (fun ip -> 346 332 Meross.turn_on ~http ~sw ip))) 347 333 $ target_arg) 348 334 in ··· 364 350 let term = 365 351 Term.( 366 352 const (fun target -> 367 - run_with_eio (fun ~http ~sw ~proc_mgr -> 368 - with_targets ~http ~sw ~proc_mgr target (fun ip -> 353 + run_with_eio (fun ~http ~sw ~proc_mgr:_ -> 354 + with_targets ~http ~sw target (fun ip -> 369 355 Meross.turn_off ~http ~sw ip))) 370 356 $ target_arg) 371 357 in ··· 386 372 let term = 387 373 Term.( 388 374 const (fun target -> 389 - run_with_eio (fun ~http ~sw ~proc_mgr -> 390 - with_targets ~http ~sw ~proc_mgr target (fun ip -> 375 + run_with_eio (fun ~http ~sw ~proc_mgr:_ -> 376 + with_targets ~http ~sw target (fun ip -> 391 377 Meross.toggle ~http ~sw ip))) 392 378 $ target_arg) 393 379 in ··· 408 394 let term = 409 395 Term.( 410 396 const (fun target -> 411 - run_with_eio (fun ~http ~sw ~proc_mgr -> 412 - with_targets ~http ~sw ~proc_mgr target (fun ip -> 397 + run_with_eio (fun ~http ~sw ~proc_mgr:_ -> 398 + with_targets ~http ~sw target (fun ip -> 413 399 Meross.reboot ~http ~sw ip))) 414 400 $ target_arg) 415 401 in ··· 432 418 let term = 433 419 Term.( 434 420 const (fun target -> 435 - run_with_eio (fun ~http ~sw ~proc_mgr -> 436 - with_targets_pp ~http ~sw ~proc_mgr target Meross.pp_electricity 437 - (fun ip -> Meross.electricity ~http ~sw ip))) 421 + run_with_eio (fun ~http ~sw ~proc_mgr:_ -> 422 + with_targets_pp ~http ~sw target Meross.pp_electricity (fun ip -> 423 + Meross.electricity ~http ~sw ip))) 438 424 $ target_arg) 439 425 in 440 426 Cmd.v info (Term.ret term) ··· 454 440 let term = 455 441 Term.( 456 442 const (fun target -> 457 - run_with_eio (fun ~http ~sw ~proc_mgr -> 458 - with_targets_pp ~http ~sw ~proc_mgr target Meross.pp_consumption 459 - (fun ip -> Meross.consumption ~http ~sw ip))) 443 + run_with_eio (fun ~http ~sw ~proc_mgr:_ -> 444 + with_targets_pp ~http ~sw target Meross.pp_consumption (fun ip -> 445 + Meross.consumption ~http ~sw ip))) 460 446 $ target_arg) 461 447 in 462 448 Cmd.v info (Term.ret term) ··· 478 464 let term = 479 465 Term.( 480 466 const (fun target -> 481 - run_with_eio (fun ~http ~sw ~proc_mgr -> 482 - with_targets_pp ~http ~sw ~proc_mgr target pp_abilities (fun ip -> 467 + run_with_eio (fun ~http ~sw ~proc_mgr:_ -> 468 + with_targets_pp ~http ~sw target pp_abilities (fun ip -> 483 469 Meross.abilities ~http ~sw ip))) 484 470 $ target_arg) 485 471 in ··· 523 509 Fmt.epr "Error: action must be 'on' or 'off'@."; 524 510 `Error (true, "invalid action") 525 511 | Some enabled -> 526 - run_with_eio (fun ~http ~sw ~proc_mgr -> 527 - with_targets ~http ~sw ~proc_mgr target (fun ip -> 512 + run_with_eio (fun ~http ~sw ~proc_mgr:_ -> 513 + with_targets ~http ~sw target (fun ip -> 528 514 Meross.set_dnd_mode ~http ~sw ip ~enabled))) 529 515 $ action_arg $ dnd_target_arg) 530 516 in ··· 641 627 const (fun action target -> 642 628 match String.lowercase_ascii action with 643 629 | "unbind" -> 644 - run_with_eio (fun ~http ~sw ~proc_mgr -> 645 - with_targets ~http ~sw ~proc_mgr target (fun ip -> 630 + run_with_eio (fun ~http ~sw ~proc_mgr:_ -> 631 + with_targets ~http ~sw target (fun ip -> 646 632 Meross.unbind_matter ~http ~sw ip)) 647 633 | "commission" -> 648 - run_with_eio (fun ~http ~sw ~proc_mgr -> 649 - with_targets ~http ~sw ~proc_mgr target (fun ip -> 634 + run_with_eio (fun ~http ~sw ~proc_mgr:_ -> 635 + with_targets ~http ~sw target (fun ip -> 650 636 Meross.trigger_commissioning ~http ~sw ip)) 651 637 | _ -> 652 638 Fmt.epr "Error: action must be 'unbind' or 'commission'@.";