SoyuzCapsule/Soyuz/ViewModels/PrinterObjectsQuery.swift

80 lines
1.6 KiB
Swift
Raw Permalink Normal View History

2023-02-07 20:04:01 +00:00
//
// PrinterObjectsQuery.swift
// KlipperMon
//
// Created by maddiefuzz on 2/7/23.
//
import Foundation
// Root struct to decode for REST response
2023-02-07 20:04:01 +00:00
struct PrinterObjectsQuery: Decodable {
let result: ResultsData
}
struct ResultsData: Decodable {
let eventtime: Double
let status: StatusData
}
// Individual update replies for JSON-RPC
struct jsonRpcUpdate: Decodable {
let method: String?
let params: jsonRpcParams
}
struct jsonRpcParams: Decodable {
let status: StatusData?
let timestamp: Double?
init(from decoder: Decoder) throws {
var container = try decoder.unkeyedContainer()
self.status = try container.decode(StatusData.self)
self.timestamp = try container.decode(Double.self)
}
}
// Root structs to decode for JSON-RPC response
struct jsonRpcResponse: Decodable {
let result: jsonRpcResult
}
struct jsonRpcResult: Decodable {
let eventtime: Double
let status: StatusData
}
// Shared data sub-structs
2023-02-07 20:04:01 +00:00
struct StatusData: Decodable {
let virtual_sdcard: VirtualSDCardData?
let extruder: ExtruderData?
let print_stats: PrintStatsData?
let heater_bed: HeaterBedData?
}
struct VirtualSDCardData: Decodable {
let file_path: String?
let progress: Double?
let is_active: Bool?
2023-02-07 20:04:01 +00:00
}
struct ExtruderData: Decodable {
let temperature: Double?
let target: Double?
let power: Double?
}
struct PrintStatsData: Decodable {
let filename: String?
let print_duration: Double?
let filament_used: Double?
let state: String?
}
struct HeaterBedData: Decodable {
let temperature: Double?
let target: Double?
let power: Double?
2023-02-07 20:04:01 +00:00
}