test client: Update for compatibility with Klippy API changes

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2020-08-15 07:02:03 -04:00
parent 8840434c7c
commit f9f70ce989

View File

@ -45,14 +45,14 @@ var api = {
method: "get_printer_objects_list" method: "get_printer_objects_list"
}, },
object_status: { object_status: {
url: "/printer/objects/status", url: "/printer/objects/query",
method: "get_printer_objects_status" method: "get_printer_objects_query"
}, },
object_subscription: { object_subscription: {
url: "/printer/objects/subscription", url: "/printer/objects/subscribe",
method: { method: {
post: "post_printer_objects_subscription", post: "post_printer_objects_subscribe",
get: "get_printer_objects_subscription" get: "get_printer_objects_subscribe"
}, },
}, },
temperature_store: { temperature_store: {
@ -243,11 +243,11 @@ function get_klippy_info() {
json_rpc.call_method(api.printer_info.method) json_rpc.call_method(api.printer_info.method)
.then((result) => { .then((result) => {
if (result.is_ready) { if (result.state == "ready") {
if (!klippy_ready) { if (!klippy_ready) {
update_term("Klippy Hostname: " + result.hostname + update_term("Klippy Hostname: " + result.hostname +
" | CPU: " + result.cpu + " | CPU: " + result.cpu_info +
" | Build Version: " + result.version); " | Build Version: " + result.software_version);
klippy_ready = true; klippy_ready = true;
// Klippy has transitioned from not ready to ready. // Klippy has transitioned from not ready to ready.
// It is now safe to fetch the file list. // It is now safe to fetch the file list.
@ -257,23 +257,25 @@ function get_klippy_info() {
if ($("#cbxSub").is(":checked")) { if ($("#cbxSub").is(":checked")) {
// If autosubscribe is check, request the subscription now // If autosubscribe is check, request the subscription now
const sub = { const sub = {
gcode: ["gcode_position", "speed", "speed_factor", "extrude_factor"], objects: {
idle_timeout: [], gcode: ["gcode_position", "speed", "speed_factor", "extrude_factor"],
pause_resume: [], idle_timeout: null,
toolhead: [], pause_resume: null,
virtual_sdcard: [], toolhead: null,
heater_bed: [], virtual_sdcard: null,
extruder: ["temperature", "target"], heater_bed: null,
fan: [], extruder: ["temperature", "target"],
print_stats: []}; fan: null,
print_stats: null}
};
add_subscription(sub); add_subscription(sub);
} else { } else {
get_status({idle_timeout: [], pause_resume: []}); get_status({idle_timeout: null, pause_resume: null});
} }
} }
} else { } else {
if (result.error_detected) { if (result.state == "error") {
update_term(result.message); update_term(result.state_message);
} else { } else {
update_term("Waiting for Klippy ready status..."); update_term("Waiting for Klippy ready status...");
} }
@ -341,7 +343,7 @@ function get_status(printer_objects) {
}); });
} }
function get_object_info() { function get_object_list() {
json_rpc.call_method(api.object_list.method) json_rpc.call_method(api.object_list.method)
.then((result) => { .then((result) => {
// result will be a dictionary containing all available printer // result will be a dictionary containing all available printer
@ -357,8 +359,8 @@ function add_subscription(printer_objects) {
json_rpc.call_method_with_kwargs( json_rpc.call_method_with_kwargs(
api.object_subscription.method.post, printer_objects) api.object_subscription.method.post, printer_objects)
.then((result) => { .then((result) => {
// result is simply an "ok" acknowledgement that subscriptions // result is the the state from all fetched data
// have been added for requested objects handle_status_update(result.status)
console.log(result); console.log(result);
}) })
.catch((error) => { .catch((error) => {
@ -1156,15 +1158,17 @@ window.onload = () => {
}); });
} else { } else {
const sub = { const sub = {
gcode: ["gcode_position", "speed", "speed_factor", "extrude_factor"], objects: {
idle_timeout: [], gcode: ["gcode_position", "speed", "speed_factor", "extrude_factor"],
pause_resume: [], idle_timeout: null,
toolhead: [], pause_resume: null,
virtual_sdcard: [], toolhead: null,
heater_bed: [], virtual_sdcard: null,
extruder: ["temperature", "target"], heater_bed: null,
fan: [], extruder: ["temperature", "target"],
print_stats: []}; fan: null,
print_stats: null}
};
add_subscription(sub); add_subscription(sub);
} }
}); });
@ -1207,7 +1211,7 @@ window.onload = () => {
return false; return false;
}); });
} else { } else {
get_object_info(); get_object_list();
} }
}); });