octoprint 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +336 -0
- data/lib/octoprint/access/group.rb +88 -0
- data/lib/octoprint/access/groups.rb +166 -0
- data/lib/octoprint/access/login_response.rb +63 -0
- data/lib/octoprint/access/permission.rb +71 -0
- data/lib/octoprint/access/permissions.rb +29 -0
- data/lib/octoprint/access/user.rb +95 -0
- data/lib/octoprint/access/users.rb +347 -0
- data/lib/octoprint/auto_initializable.rb +219 -0
- data/lib/octoprint/base_resource.rb +139 -0
- data/lib/octoprint/client.rb +151 -0
- data/lib/octoprint/connection/options.rb +44 -0
- data/lib/octoprint/connection/settings.rb +35 -0
- data/lib/octoprint/connection.rb +74 -0
- data/lib/octoprint/deserializable.rb +483 -0
- data/lib/octoprint/exceptions.rb +30 -0
- data/lib/octoprint/files/file.rb +55 -0
- data/lib/octoprint/files/folder.rb +29 -0
- data/lib/octoprint/files/operation_result.rb +37 -0
- data/lib/octoprint/files/refs.rb +19 -0
- data/lib/octoprint/files.rb +238 -0
- data/lib/octoprint/job/information.rb +42 -0
- data/lib/octoprint/job/progress.rb +46 -0
- data/lib/octoprint/job.rb +140 -0
- data/lib/octoprint/languages/language_pack.rb +31 -0
- data/lib/octoprint/languages.rb +102 -0
- data/lib/octoprint/location.rb +23 -0
- data/lib/octoprint/logs/log_file.rb +59 -0
- data/lib/octoprint/logs/references.rb +28 -0
- data/lib/octoprint/logs.rb +98 -0
- data/lib/octoprint/printer/bed.rb +32 -0
- data/lib/octoprint/printer/chamber.rb +29 -0
- data/lib/octoprint/printer/command.rb +129 -0
- data/lib/octoprint/printer/custom_control/input.rb +45 -0
- data/lib/octoprint/printer/custom_control.rb +119 -0
- data/lib/octoprint/printer/error_information.rb +104 -0
- data/lib/octoprint/printer/heater.rb +113 -0
- data/lib/octoprint/printer/history_query.rb +25 -0
- data/lib/octoprint/printer/printhead.rb +105 -0
- data/lib/octoprint/printer/sd.rb +97 -0
- data/lib/octoprint/printer/state.rb +41 -0
- data/lib/octoprint/printer/state_flags.rb +70 -0
- data/lib/octoprint/printer/temperature_attributes.rb +70 -0
- data/lib/octoprint/printer/temperature_data.rb +53 -0
- data/lib/octoprint/printer/temperature_data_point.rb +73 -0
- data/lib/octoprint/printer/temperature_reading.rb +47 -0
- data/lib/octoprint/printer/temperature_state.rb +67 -0
- data/lib/octoprint/printer/tool.rb +154 -0
- data/lib/octoprint/printer.rb +126 -0
- data/lib/octoprint/printer_profiles/printer_profile.rb +40 -0
- data/lib/octoprint/printer_profiles.rb +158 -0
- data/lib/octoprint/server_information.rb +51 -0
- data/lib/octoprint/server_version.rb +52 -0
- data/lib/octoprint/settings/webcam.rb +135 -0
- data/lib/octoprint/settings.rb +133 -0
- data/lib/octoprint/slicing/profile.rb +65 -0
- data/lib/octoprint/slicing/slicer.rb +83 -0
- data/lib/octoprint/slicing.rb +227 -0
- data/lib/octoprint/system_commands/command.rb +41 -0
- data/lib/octoprint/system_commands.rb +110 -0
- data/lib/octoprint/timelapse/config.rb +68 -0
- data/lib/octoprint/timelapse/file_attributes.rb +50 -0
- data/lib/octoprint/timelapse/rendered.rb +51 -0
- data/lib/octoprint/timelapse/unrendered.rb +43 -0
- data/lib/octoprint/timelapse.rb +221 -0
- data/lib/octoprint/types.rb +140 -0
- data/lib/octoprint/util.rb +151 -0
- data/lib/octoprint/version.rb +7 -0
- data/lib/octoprint/wizard.rb +57 -0
- data/lib/octoprint.rb +57 -0
- data/rbi/octoprint/access/group.rbi +46 -0
- data/rbi/octoprint/access/login_response.rbi +22 -0
- data/rbi/octoprint/access/permission.rbi +34 -0
- data/rbi/octoprint/access/user.rbi +43 -0
- data/rbi/octoprint/connection/options.rbi +28 -0
- data/rbi/octoprint/connection/settings.rbi +19 -0
- data/rbi/octoprint/connection.rbi +13 -0
- data/rbi/octoprint/files/file.rbi +61 -0
- data/rbi/octoprint/files/folder.rbi +22 -0
- data/rbi/octoprint/files/operation_result.rbi +22 -0
- data/rbi/octoprint/files/refs.rbi +16 -0
- data/rbi/octoprint/job/information.rbi +22 -0
- data/rbi/octoprint/job/progress.rbi +25 -0
- data/rbi/octoprint/job.rbi +22 -0
- data/rbi/octoprint/languages/language_pack.rbi +19 -0
- data/rbi/octoprint/languages.rbi +13 -0
- data/rbi/octoprint/logs/log_file.rbi +19 -0
- data/rbi/octoprint/logs/references.rbi +13 -0
- data/rbi/octoprint/logs.rbi +13 -0
- data/rbi/octoprint/printer/bed.rbi +22 -0
- data/rbi/octoprint/printer/chamber.rbi +22 -0
- data/rbi/octoprint/printer/custom_control/input.rbi +22 -0
- data/rbi/octoprint/printer/custom_control.rbi +67 -0
- data/rbi/octoprint/printer/error_information.rbi +25 -0
- data/rbi/octoprint/printer/sd.rbi +13 -0
- data/rbi/octoprint/printer/state.rbi +19 -0
- data/rbi/octoprint/printer/state_flags.rbi +43 -0
- data/rbi/octoprint/printer/temperature_data.rbi +19 -0
- data/rbi/octoprint/printer/temperature_data_point.rbi +22 -0
- data/rbi/octoprint/printer/temperature_reading.rbi +19 -0
- data/rbi/octoprint/printer/temperature_state.rbi +22 -0
- data/rbi/octoprint/printer/tool.rbi +22 -0
- data/rbi/octoprint/printer.rbi +19 -0
- data/rbi/octoprint/printer_profiles/printer_profile.rbi +46 -0
- data/rbi/octoprint/printer_profiles.rbi +13 -0
- data/rbi/octoprint/server_information.rbi +16 -0
- data/rbi/octoprint/server_version.rbi +19 -0
- data/rbi/octoprint/settings/webcam.rbi +34 -0
- data/rbi/octoprint/slicing/profile.rbi +28 -0
- data/rbi/octoprint/slicing/slicer.rbi +31 -0
- data/rbi/octoprint/system_commands/command.rbi +25 -0
- data/rbi/octoprint/system_commands.rbi +16 -0
- data/rbi/octoprint/timelapse/config.rbi +31 -0
- data/rbi/octoprint/timelapse/rendered.rbi +31 -0
- data/rbi/octoprint/timelapse/unrendered.rbi +34 -0
- data/rbi/octoprint/timelapse.rbi +22 -0
- data/rbi/octoprint/util.rbi +19 -0
- data/rbi/octoprint.rbi +1848 -0
- metadata +264 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Printer
|
|
6
|
+
# A historic temperature reading of a single heater.
|
|
7
|
+
#
|
|
8
|
+
# @example
|
|
9
|
+
# reading = Octoprint::Printer::Tool.temperatures(history: true)[0].history.first
|
|
10
|
+
# reading.actual # => 50.221
|
|
11
|
+
# reading.target # => 70.0
|
|
12
|
+
#
|
|
13
|
+
# @see https://docs.octoprint.org/en/master/api/datamodel.html#historic-temperature-data-point
|
|
14
|
+
class TemperatureReading
|
|
15
|
+
include AutoInitializable
|
|
16
|
+
include Deserializable
|
|
17
|
+
|
|
18
|
+
# @!attribute [r] time
|
|
19
|
+
# @return [Integer, nil] Unix timestamp of the reading, when provided by the server
|
|
20
|
+
auto_attr :time, type: Integer
|
|
21
|
+
|
|
22
|
+
# @!attribute [r] actual
|
|
23
|
+
# @return [Float, nil] Temperature at the time of the reading
|
|
24
|
+
auto_attr :actual, type: Float
|
|
25
|
+
|
|
26
|
+
# @!attribute [r] target
|
|
27
|
+
# @return [Float, nil] Target temperature at the time of the reading, nil if none was set
|
|
28
|
+
auto_attr :target, type: Float
|
|
29
|
+
|
|
30
|
+
# @!attribute [r] extra
|
|
31
|
+
# @return [Hash, nil] Any additional fields returned by the API
|
|
32
|
+
auto_attr :extra, type: Hash
|
|
33
|
+
|
|
34
|
+
auto_initialize!
|
|
35
|
+
|
|
36
|
+
# The reading's timestamp as a Time object.
|
|
37
|
+
#
|
|
38
|
+
# @return [Time, nil] The time of the reading, nil when the server didn't provide one
|
|
39
|
+
#: -> Time?
|
|
40
|
+
def recorded_at
|
|
41
|
+
return nil unless time
|
|
42
|
+
|
|
43
|
+
Time.at(time)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Printer
|
|
6
|
+
# Temperature state of the printer's tools, bed and chamber, with an optional history.
|
|
7
|
+
#
|
|
8
|
+
# Returned by {Printer.get} as {Printer#temperature}. Only the heaters present on the printer are populated.
|
|
9
|
+
#
|
|
10
|
+
# @example
|
|
11
|
+
# temperature = Octoprint::Printer.get(history: true, limit: 2).temperature
|
|
12
|
+
# temperature.tools.keys # => [:tool0, :tool1]
|
|
13
|
+
# temperature.tool(0).actual # => 214.8821
|
|
14
|
+
# temperature.history.first.time # => 1395651928
|
|
15
|
+
#
|
|
16
|
+
# @see https://docs.octoprint.org/en/master/api/printer.html#temperature-state
|
|
17
|
+
class TemperatureState
|
|
18
|
+
include AutoInitializable
|
|
19
|
+
include Deserializable
|
|
20
|
+
|
|
21
|
+
# @!attribute [r] tools
|
|
22
|
+
# @return [Hash{Symbol => Printer::TemperatureData}] Temperature data per tool, keyed by +:tool0+...
|
|
23
|
+
# Empty when the response contains no tool data
|
|
24
|
+
auto_attr :tools, type: Hash
|
|
25
|
+
|
|
26
|
+
# @!attribute [r] bed
|
|
27
|
+
# @return [Printer::TemperatureData, nil] Temperature data of the heated bed
|
|
28
|
+
auto_attr :bed, type: TemperatureData
|
|
29
|
+
|
|
30
|
+
# @!attribute [r] chamber
|
|
31
|
+
# @return [Printer::TemperatureData, nil] Temperature data of the heated chamber
|
|
32
|
+
auto_attr :chamber, type: TemperatureData
|
|
33
|
+
|
|
34
|
+
# @!attribute [r] history
|
|
35
|
+
# @return [Array<Printer::TemperatureDataPoint>, nil] Temperature history, only included when requested
|
|
36
|
+
auto_attr :history, type: TemperatureDataPoint, array: true
|
|
37
|
+
|
|
38
|
+
# @!attribute [r] extra
|
|
39
|
+
# @return [Hash, nil] Any additional fields returned by the API
|
|
40
|
+
auto_attr :extra, type: Hash
|
|
41
|
+
|
|
42
|
+
auto_initialize!
|
|
43
|
+
|
|
44
|
+
deserialize_config do
|
|
45
|
+
nested :bed, TemperatureData
|
|
46
|
+
nested :chamber, TemperatureData
|
|
47
|
+
array :history, TemperatureDataPoint
|
|
48
|
+
|
|
49
|
+
transform do |data|
|
|
50
|
+
TemperatureData.extract_tools(data)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Temperature data of the tool with the given index.
|
|
55
|
+
#
|
|
56
|
+
# @example
|
|
57
|
+
# Octoprint::Printer.get.temperature.tool(1).target # => 205.0
|
|
58
|
+
#
|
|
59
|
+
# @param index [Integer] The tool's index, starting at 0
|
|
60
|
+
# @return [Printer::TemperatureData, nil] The tool's temperature data, nil if there is no such tool
|
|
61
|
+
#: (?Integer index) -> TemperatureData?
|
|
62
|
+
def tool(index = 0)
|
|
63
|
+
tools&.[](:"tool#{index}")
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Printer
|
|
6
|
+
# Tool (hotend) temperatures and commands: target and offset temperatures, tool selection,
|
|
7
|
+
# extrusion and flow rate.
|
|
8
|
+
#
|
|
9
|
+
# Commands may only be sent while the printer is operational, and {.select_tool} and {.extrude}
|
|
10
|
+
# only while it is not printing. Requires the +CONTROL+ permission for commands and +STATUS+ for
|
|
11
|
+
# {.temperatures}.
|
|
12
|
+
#
|
|
13
|
+
# @example Read the first hotend's temperature
|
|
14
|
+
# Octoprint::Printer::Tool.temperatures[0].actual # => 214.8821
|
|
15
|
+
#
|
|
16
|
+
# @example Heat up the hotends
|
|
17
|
+
# Octoprint::Printer::Tool.target(tool0: 220, tool1: 205)
|
|
18
|
+
#
|
|
19
|
+
# @example Extrude 5mm of filament
|
|
20
|
+
# Octoprint::Printer::Tool.extrude(5)
|
|
21
|
+
#
|
|
22
|
+
# @see https://docs.octoprint.org/en/master/api/printer.html#issue-a-tool-command
|
|
23
|
+
class Tool < BaseResource
|
|
24
|
+
extend HistoryQuery
|
|
25
|
+
include TemperatureAttributes
|
|
26
|
+
|
|
27
|
+
resource_path("/api/printer/tool")
|
|
28
|
+
|
|
29
|
+
# Retrieves the current temperature of each of the printer's tools.
|
|
30
|
+
#
|
|
31
|
+
# @param history [Boolean] Whether to include the temperature history
|
|
32
|
+
# @param limit [Integer, nil] Only return the last +limit+ history data points (ignored unless +history+ is true)
|
|
33
|
+
#
|
|
34
|
+
# @example Read the first hotend's temperature
|
|
35
|
+
# Octoprint::Printer::Tool.temperatures[0].actual # => 214.8821
|
|
36
|
+
#
|
|
37
|
+
# @example Include each tool's last two history readings
|
|
38
|
+
# tools = Octoprint::Printer::Tool.temperatures(history: true, limit: 2)
|
|
39
|
+
# tools.map(&:target) # => [220.0, nil]
|
|
40
|
+
# tools[0].history.map(&:actual) # => [214.8821, 212.32]
|
|
41
|
+
#
|
|
42
|
+
# @return [Array<Printer::Tool>] The tools' temperatures, indexed by tool number
|
|
43
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational
|
|
44
|
+
#: (?history: bool, ?limit: Integer?) -> Array[Tool]
|
|
45
|
+
def self.temperatures(history: false, limit: nil)
|
|
46
|
+
response = fetch_resource(deserialize: false, options: history_query(history: history, limit: limit))
|
|
47
|
+
|
|
48
|
+
response.keys
|
|
49
|
+
.grep(TemperatureData::TOOL_KEY)
|
|
50
|
+
.sort_by { |key| key.to_s.delete_prefix("tool").to_i }
|
|
51
|
+
.map { |key| from_response(response, key) }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Issues a tool command.
|
|
55
|
+
#
|
|
56
|
+
# @param command [String] The command to issue: +target+, +offset+, +select+, +extrude+ or +flowrate+
|
|
57
|
+
# @param options [Hash] Additional command parameters
|
|
58
|
+
#
|
|
59
|
+
# @example
|
|
60
|
+
# Octoprint::Printer::Tool.issue_command(command: "select", options: { tool: "tool1" })
|
|
61
|
+
#
|
|
62
|
+
# @return [Boolean] true on success (204 No Content)
|
|
63
|
+
# @raise [Octoprint::Exceptions::BadRequestError] if the parameters are invalid
|
|
64
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational
|
|
65
|
+
#: (command: String, ?options: Hash[Symbol, untyped]) -> untyped
|
|
66
|
+
def self.issue_command(command:, options: {})
|
|
67
|
+
post(params: { command: command }.merge(options))
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Sets the target temperature of one or more tools. A target of 0 turns the heater off.
|
|
71
|
+
#
|
|
72
|
+
# @param targets [Hash{Symbol, String => Numeric}] Target temperatures keyed by +tool{n}+,
|
|
73
|
+
# or +tool+ for the currently active tool
|
|
74
|
+
#
|
|
75
|
+
# @example Set the temperatures of two hotends
|
|
76
|
+
# Octoprint::Printer::Tool.target(tool0: 220, tool1: 205)
|
|
77
|
+
#
|
|
78
|
+
# @example Set the temperature of the active hotend
|
|
79
|
+
# Octoprint::Printer::Tool.target(tool: 220)
|
|
80
|
+
#
|
|
81
|
+
# @return [Boolean] true on success (204 No Content)
|
|
82
|
+
# @raise [Octoprint::Exceptions::BadRequestError] if a key or temperature is invalid
|
|
83
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational
|
|
84
|
+
#: (Hash[(Symbol | String), Numeric] targets) -> untyped
|
|
85
|
+
def self.target(targets)
|
|
86
|
+
issue_command(command: "target", options: { targets: targets })
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Sets the temperature offset of one or more tools.
|
|
90
|
+
#
|
|
91
|
+
# @param offsets [Hash{Symbol, String => Numeric}] Temperature offsets keyed by +tool{n}+
|
|
92
|
+
#
|
|
93
|
+
# @example
|
|
94
|
+
# Octoprint::Printer::Tool.offset(tool0: 10, tool1: -5)
|
|
95
|
+
#
|
|
96
|
+
# @return [Boolean] true on success (204 No Content)
|
|
97
|
+
# @raise [Octoprint::Exceptions::BadRequestError] if a key or offset is invalid
|
|
98
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational
|
|
99
|
+
#: (Hash[(Symbol | String), Numeric] offsets) -> untyped
|
|
100
|
+
def self.offset(offsets)
|
|
101
|
+
issue_command(command: "offset", options: { offsets: offsets })
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Selects the printer's current tool. Sends the +select+ command.
|
|
105
|
+
#
|
|
106
|
+
# @param tool [String, Symbol] The tool to select, in the format +tool{n}+
|
|
107
|
+
#
|
|
108
|
+
# @example
|
|
109
|
+
# Octoprint::Printer::Tool.select_tool("tool1")
|
|
110
|
+
#
|
|
111
|
+
# @return [Boolean] true on success (204 No Content)
|
|
112
|
+
# @raise [Octoprint::Exceptions::BadRequestError] if the tool is invalid
|
|
113
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational or is printing
|
|
114
|
+
#: ((String | Symbol) tool) -> untyped
|
|
115
|
+
def self.select_tool(tool)
|
|
116
|
+
issue_command(command: "select", options: { tool: tool.to_s })
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Extrudes filament from the currently selected tool. Use a negative amount to retract.
|
|
120
|
+
#
|
|
121
|
+
# @param amount [Numeric] The amount of filament to extrude, in mm
|
|
122
|
+
# @param speed [Integer, nil] Speed in mm/min. Defaults to the profile's maximum E axis speed.
|
|
123
|
+
#
|
|
124
|
+
# @example Extrude 5mm
|
|
125
|
+
# Octoprint::Printer::Tool.extrude(5)
|
|
126
|
+
#
|
|
127
|
+
# @example Retract 3mm at 300mm/min
|
|
128
|
+
# Octoprint::Printer::Tool.extrude(-3, speed: 300)
|
|
129
|
+
#
|
|
130
|
+
# @return [Boolean] true on success (204 No Content)
|
|
131
|
+
# @raise [Octoprint::Exceptions::BadRequestError] if the amount is invalid
|
|
132
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational or is printing
|
|
133
|
+
#: (Numeric amount, ?speed: Integer?) -> untyped
|
|
134
|
+
def self.extrude(amount, speed: nil)
|
|
135
|
+
issue_command(command: "extrude", options: { amount: amount, speed: speed }.compact)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Changes the flow rate factor applied to extrusion.
|
|
139
|
+
#
|
|
140
|
+
# @param factor [Numeric] Percentage between 75 and 125 as an integer (+75+..+125+) or float (+0.75+..+1.25+)
|
|
141
|
+
#
|
|
142
|
+
# @example
|
|
143
|
+
# Octoprint::Printer::Tool.flowrate(95)
|
|
144
|
+
#
|
|
145
|
+
# @return [Boolean] true on success (204 No Content)
|
|
146
|
+
# @raise [Octoprint::Exceptions::BadRequestError] if the factor is out of range
|
|
147
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational
|
|
148
|
+
#: (Numeric factor) -> untyped
|
|
149
|
+
def self.flowrate(factor)
|
|
150
|
+
issue_command(command: "flowrate", options: { factor: factor })
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
# Full state of the printer: temperatures, SD card state and general printer state.
|
|
6
|
+
#
|
|
7
|
+
# The printer's components are controlled through dedicated resources:
|
|
8
|
+
#
|
|
9
|
+
# - {Printer::Printhead} — jog, home and change the feed rate of the print head
|
|
10
|
+
# - {Printer::Tool} — set temperatures, select tools, extrude and change the flow rate
|
|
11
|
+
# - {Printer::Bed} — set the heated bed's temperature
|
|
12
|
+
# - {Printer::Chamber} — set the heated chamber's temperature
|
|
13
|
+
# - {Printer::Sd} — initialize, refresh and release the printer's SD card
|
|
14
|
+
# - {Printer::Command} — send arbitrary commands and retrieve custom controls
|
|
15
|
+
# - {Printer::ErrorInformation} — retrieve information about the last error (see {.last_error})
|
|
16
|
+
#
|
|
17
|
+
# @example Get the current printer state
|
|
18
|
+
# printer = Octoprint::Printer.get
|
|
19
|
+
# printer.state.text # => "Operational"
|
|
20
|
+
# printer.state.flags.printing # => false
|
|
21
|
+
# printer.temperature.tool(0).actual # => 214.8821
|
|
22
|
+
# printer.temperature.bed.target # => 70.0
|
|
23
|
+
# printer.sd.ready # => true
|
|
24
|
+
#
|
|
25
|
+
# @example Include the temperature history, limited to the last two data points
|
|
26
|
+
# printer = Octoprint::Printer.get(history: true, limit: 2)
|
|
27
|
+
# printer.temperature.history.map(&:time) # => [1395651928, 1395651926]
|
|
28
|
+
#
|
|
29
|
+
# @example Exclude data that isn't needed
|
|
30
|
+
# printer = Octoprint::Printer.get(exclude: %i[temperature sd])
|
|
31
|
+
# printer.temperature # => nil
|
|
32
|
+
#
|
|
33
|
+
# @example Check the last error
|
|
34
|
+
# error = Octoprint::Printer.last_error
|
|
35
|
+
# error.error? # => false
|
|
36
|
+
#
|
|
37
|
+
# @see https://docs.octoprint.org/en/master/api/printer.html OctoPrint Printer API Documentation
|
|
38
|
+
class Printer < BaseResource
|
|
39
|
+
extend HistoryQuery
|
|
40
|
+
include AutoInitializable
|
|
41
|
+
include Deserializable
|
|
42
|
+
|
|
43
|
+
resource_path("/api/printer")
|
|
44
|
+
|
|
45
|
+
# @!attribute [r] temperature
|
|
46
|
+
# @return [Printer::TemperatureState, nil] The printer's temperature state, nil when excluded
|
|
47
|
+
auto_attr :temperature, type: TemperatureState
|
|
48
|
+
|
|
49
|
+
# @!attribute [r] sd
|
|
50
|
+
# @return [Printer::Sd, nil] The printer's SD card state, nil when excluded or unavailable
|
|
51
|
+
auto_attr :sd, type: Sd
|
|
52
|
+
|
|
53
|
+
# @!attribute [r] state
|
|
54
|
+
# @return [Printer::State, nil] The printer's general state, nil when excluded
|
|
55
|
+
auto_attr :state, type: State
|
|
56
|
+
|
|
57
|
+
# @!attribute [r] extra
|
|
58
|
+
# @return [Hash, nil] Any additional fields returned by the API
|
|
59
|
+
auto_attr :extra, type: Hash
|
|
60
|
+
|
|
61
|
+
auto_initialize!
|
|
62
|
+
|
|
63
|
+
deserialize_config do
|
|
64
|
+
nested :temperature, TemperatureState
|
|
65
|
+
nested :sd, Sd
|
|
66
|
+
nested :state, State
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Fields that can be excluded from the full state response.
|
|
70
|
+
EXCLUDABLE_FIELDS = %w[temperature sd state].freeze
|
|
71
|
+
|
|
72
|
+
# Retrieves the current state of the printer.
|
|
73
|
+
#
|
|
74
|
+
# @param history [Boolean] Whether to include the temperature history
|
|
75
|
+
# @param limit [Integer, nil] Only return the last +limit+ history data points (ignored unless +history+ is true)
|
|
76
|
+
# @param exclude [Array<String, Symbol>] Fields to leave out of the response: +temperature+, +sd+ and/or +state+
|
|
77
|
+
#
|
|
78
|
+
# @example Get the printer state
|
|
79
|
+
# printer = Octoprint::Printer.get
|
|
80
|
+
# printer.state.text # => "Operational"
|
|
81
|
+
#
|
|
82
|
+
# @example Get the printer state with the last 10 temperature data points
|
|
83
|
+
# Octoprint::Printer.get(history: true, limit: 10).temperature.history
|
|
84
|
+
#
|
|
85
|
+
# @example Only retrieve the general state
|
|
86
|
+
# Octoprint::Printer.get(exclude: %i[temperature sd]).state.flags.ready # => true
|
|
87
|
+
#
|
|
88
|
+
# @return [Printer] The current printer state
|
|
89
|
+
# @raise [ArgumentError] if +exclude+ contains an unknown field
|
|
90
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational
|
|
91
|
+
#: (
|
|
92
|
+
#| ?history: bool,
|
|
93
|
+
#| ?limit: Integer?,
|
|
94
|
+
#| ?exclude: Array[(String | Symbol)]
|
|
95
|
+
#| ) -> Printer
|
|
96
|
+
def self.get(history: false, limit: nil, exclude: [])
|
|
97
|
+
options = history_query(history: history, limit: limit)
|
|
98
|
+
|
|
99
|
+
if exclude.any?
|
|
100
|
+
excluded = exclude.map(&:to_s)
|
|
101
|
+
invalid = excluded - EXCLUDABLE_FIELDS
|
|
102
|
+
raise ArgumentError, "Invalid exclude field(s): #{invalid.join(", ")}" if invalid.any?
|
|
103
|
+
|
|
104
|
+
options[:exclude] = excluded.join(",")
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
fetch_resource(options: options)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Retrieves information about the last error reported by the printer.
|
|
111
|
+
#
|
|
112
|
+
# Shortcut for {Printer::ErrorInformation.get}.
|
|
113
|
+
#
|
|
114
|
+
# @example
|
|
115
|
+
# error = Octoprint::Printer.last_error
|
|
116
|
+
# error.error? # => true
|
|
117
|
+
# error.reason # => "firmware"
|
|
118
|
+
#
|
|
119
|
+
# @return [Printer::ErrorInformation] The last error information
|
|
120
|
+
# @raise [Octoprint::Exceptions::AuthenticationError] if the user lacks the +STATUS+ permission
|
|
121
|
+
#: -> ErrorInformation
|
|
122
|
+
def self.last_error
|
|
123
|
+
ErrorInformation.get
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class PrinterProfiles
|
|
6
|
+
# Represents a single printer profile configuration
|
|
7
|
+
#
|
|
8
|
+
# A printer profile contains the physical characteristics and capabilities
|
|
9
|
+
# of a 3D printer, including dimensions, extruder configuration, heated bed
|
|
10
|
+
# capabilities, and movement speeds.
|
|
11
|
+
#
|
|
12
|
+
# @example Access printer profile information
|
|
13
|
+
# profile = printer_profiles.profiles["_default"]
|
|
14
|
+
# puts profile.name # => "Default"
|
|
15
|
+
# puts profile.model # => "Generic RepRap Printer"
|
|
16
|
+
# puts profile.volume.width # => 200
|
|
17
|
+
class PrinterProfile
|
|
18
|
+
include Deserializable
|
|
19
|
+
include AutoInitializable
|
|
20
|
+
|
|
21
|
+
auto_attr :id, type: String, nilable: false
|
|
22
|
+
auto_attr :name, type: String, nilable: false
|
|
23
|
+
auto_attr :color, type: String, nilable: false
|
|
24
|
+
auto_attr :model, type: String, nilable: false
|
|
25
|
+
auto_attr :default, type: T::Boolean, nilable: false
|
|
26
|
+
auto_attr :current, type: T::Boolean, nilable: false
|
|
27
|
+
auto_attr :resource, type: String, nilable: false
|
|
28
|
+
auto_attr :volume, type: Hash, nilable: false
|
|
29
|
+
auto_attr :heated_bed, type: T::Boolean, nilable: false
|
|
30
|
+
auto_attr :heated_chamber, type: T::Boolean, nilable: false
|
|
31
|
+
auto_attr :axes, type: Hash, nilable: false
|
|
32
|
+
auto_attr :extruder, type: Hash, nilable: false
|
|
33
|
+
auto_attr :extra, type: Hash
|
|
34
|
+
|
|
35
|
+
auto_initialize!
|
|
36
|
+
|
|
37
|
+
# No configuration needed - camelCase conversion and extras collection are automatic!
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
# Printer profile management for OctoPrint server configuration
|
|
6
|
+
#
|
|
7
|
+
# This class provides methods to manage printer profiles on the OctoPrint server.
|
|
8
|
+
# Printer profiles define the physical characteristics and capabilities of 3D printers
|
|
9
|
+
# including print volume, extruder configuration, heated bed capabilities, and movement speeds.
|
|
10
|
+
#
|
|
11
|
+
# @example List all printer profiles
|
|
12
|
+
# profiles = Octoprint::PrinterProfiles.list
|
|
13
|
+
# profiles.profiles.each do |id, profile|
|
|
14
|
+
# puts "#{profile.name}: #{profile.model} (#{profile.id})"
|
|
15
|
+
# end
|
|
16
|
+
#
|
|
17
|
+
# @example Get a specific printer profile
|
|
18
|
+
# profile = Octoprint::PrinterProfiles.get(identifier: "_default")
|
|
19
|
+
# puts "Volume: #{profile.volume.width}x#{profile.volume.depth}x#{profile.volume.height}mm"
|
|
20
|
+
#
|
|
21
|
+
# @example Create a new printer profile
|
|
22
|
+
# profile_data = {
|
|
23
|
+
# name: "My Custom Printer",
|
|
24
|
+
# model: "Custom Model",
|
|
25
|
+
# volume: { width: 200, depth: 200, height: 180 }
|
|
26
|
+
# }
|
|
27
|
+
# new_profile = Octoprint::PrinterProfiles.create(profile: profile_data)
|
|
28
|
+
#
|
|
29
|
+
# @example Update an existing printer profile
|
|
30
|
+
# updates = { name: "Updated Printer Name" }
|
|
31
|
+
# Octoprint::PrinterProfiles.update(identifier: "custom_printer", profile: updates)
|
|
32
|
+
#
|
|
33
|
+
# @example Delete a printer profile
|
|
34
|
+
# Octoprint::PrinterProfiles.delete(identifier: "old_printer")
|
|
35
|
+
#
|
|
36
|
+
# Octoprint's API doc: https://docs.octoprint.org/en/1.11.2/api/printerprofiles.html
|
|
37
|
+
class PrinterProfiles < BaseResource
|
|
38
|
+
include AutoInitializable
|
|
39
|
+
include Deserializable
|
|
40
|
+
|
|
41
|
+
resource_path("/api/printerprofiles")
|
|
42
|
+
|
|
43
|
+
auto_attr :profiles, type: Hash, nilable: false
|
|
44
|
+
auto_attr :extra, type: Hash
|
|
45
|
+
|
|
46
|
+
auto_initialize!
|
|
47
|
+
|
|
48
|
+
deserialize_config do
|
|
49
|
+
transform do |data|
|
|
50
|
+
# Transform the hash of profile_id => profile_info into proper objects
|
|
51
|
+
if data[:profiles].is_a?(Hash)
|
|
52
|
+
data[:profiles] = data[:profiles].transform_values do |profile_info|
|
|
53
|
+
PrinterProfile.deserialize(profile_info)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Fetches the list of available printer profiles
|
|
60
|
+
#
|
|
61
|
+
# @return [PrinterProfiles]
|
|
62
|
+
#: -> PrinterProfiles
|
|
63
|
+
def self.list
|
|
64
|
+
fetch_resource
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Fetches a specific printer profile
|
|
68
|
+
#
|
|
69
|
+
# @param [String] identifier The identifier of the printer profile to retrieve
|
|
70
|
+
#
|
|
71
|
+
# @return [PrinterProfile]
|
|
72
|
+
#: (
|
|
73
|
+
#| identifier: String
|
|
74
|
+
#| ) -> PrinterProfile
|
|
75
|
+
def self.get(identifier:)
|
|
76
|
+
profile_data = fetch_resource(identifier, deserialize: false)
|
|
77
|
+
PrinterProfile.deserialize(profile_data)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Creates a new printer profile
|
|
81
|
+
#
|
|
82
|
+
# @param [Hash] profile The profile data to create
|
|
83
|
+
# @param [String] based_on Optional. The identifier of the profile to base the new profile on
|
|
84
|
+
#
|
|
85
|
+
# @return [PrinterProfile]
|
|
86
|
+
#: (
|
|
87
|
+
#| profile: Hash[Symbol, untyped],
|
|
88
|
+
#| ?based_on: String?
|
|
89
|
+
#| ) -> PrinterProfile
|
|
90
|
+
def self.create(profile:, based_on: nil)
|
|
91
|
+
params = { profile: profile }
|
|
92
|
+
params[:basedOn] = based_on if based_on
|
|
93
|
+
|
|
94
|
+
result = post(params: params)
|
|
95
|
+
# API returns the profile nested under :profile key
|
|
96
|
+
profile_data = result[:profile] || result
|
|
97
|
+
PrinterProfile.deserialize(profile_data)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Updates an existing printer profile
|
|
101
|
+
#
|
|
102
|
+
# @param [String] identifier The identifier of the printer profile to update
|
|
103
|
+
# @param [Hash] profile The profile data to update
|
|
104
|
+
#
|
|
105
|
+
# @return [PrinterProfile]
|
|
106
|
+
#: (
|
|
107
|
+
#| identifier: String,
|
|
108
|
+
#| profile: Hash[Symbol, untyped]
|
|
109
|
+
#| ) -> PrinterProfile
|
|
110
|
+
def self.update(identifier:, profile:)
|
|
111
|
+
path = [@path, identifier].compact.join("/")
|
|
112
|
+
result = patch(path: path, params: { profile: profile })
|
|
113
|
+
# API returns the profile nested under :profile key
|
|
114
|
+
profile_data = result[:profile] || result
|
|
115
|
+
PrinterProfile.deserialize(profile_data)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Deletes a printer profile
|
|
119
|
+
#
|
|
120
|
+
# @param [String] identifier The identifier of the printer profile to delete
|
|
121
|
+
#
|
|
122
|
+
# @return [T.untyped] 204 No Content on success
|
|
123
|
+
#: (
|
|
124
|
+
#| identifier: String
|
|
125
|
+
#| ) -> untyped
|
|
126
|
+
def self.delete_profile(identifier:)
|
|
127
|
+
path = [@path, identifier].compact.join("/")
|
|
128
|
+
delete(path: path)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
class << self
|
|
132
|
+
private
|
|
133
|
+
|
|
134
|
+
# Sends a PATCH request to the resource's endpoint.
|
|
135
|
+
#
|
|
136
|
+
# @param [String] path the path of the patch request
|
|
137
|
+
# @param [Hash] params parameters to the request
|
|
138
|
+
# @param [Hash] headers headers to the request
|
|
139
|
+
# @param [Hash] options options
|
|
140
|
+
# @return [Object]
|
|
141
|
+
#: (
|
|
142
|
+
#| ?path: String,
|
|
143
|
+
#| ?params: Hash[Symbol, untyped],
|
|
144
|
+
#| ?headers: Hash[Symbol, untyped],
|
|
145
|
+
#| ?options: Hash[Symbol, untyped]
|
|
146
|
+
#| ) -> untyped
|
|
147
|
+
def patch(path: @path, params: {}, headers: {}, options: {})
|
|
148
|
+
client.request(
|
|
149
|
+
path,
|
|
150
|
+
http_method: :patch,
|
|
151
|
+
body: params,
|
|
152
|
+
headers: headers,
|
|
153
|
+
options: options
|
|
154
|
+
)
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
# Information about the OctoPrint server.
|
|
6
|
+
#
|
|
7
|
+
# Octoprint's API doc: https://docs.octoprint.org/en/master/api/server.html
|
|
8
|
+
#
|
|
9
|
+
# @attr [String] version Server's version
|
|
10
|
+
# @attr [String|nil] safemode Server's version
|
|
11
|
+
#
|
|
12
|
+
# @example
|
|
13
|
+
# Octoprint.configure(host: 'https://octopi.local/', api_key: 'j98G2nsJq...')
|
|
14
|
+
#
|
|
15
|
+
# server = Octoprint::ServerInformation.get
|
|
16
|
+
# server.version= #=> "1.7.3"
|
|
17
|
+
# server.safemode #=> "incomplete_startup"
|
|
18
|
+
class ServerInformation < BaseResource
|
|
19
|
+
include AutoInitializable
|
|
20
|
+
include Deserializable
|
|
21
|
+
|
|
22
|
+
resource_path("/api/server")
|
|
23
|
+
|
|
24
|
+
# @!attribute [r] version
|
|
25
|
+
# @return [String] The server's version number
|
|
26
|
+
auto_attr :version, type: String, nilable: false
|
|
27
|
+
|
|
28
|
+
# @!attribute [r] safemode
|
|
29
|
+
# @return [String, nil] The server's safe mode status
|
|
30
|
+
auto_attr :safemode, type: String
|
|
31
|
+
|
|
32
|
+
# @!attribute [r] extra
|
|
33
|
+
# @return [Hash] Any additional fields returned by the API
|
|
34
|
+
auto_attr :extra, type: Hash
|
|
35
|
+
|
|
36
|
+
auto_initialize!
|
|
37
|
+
|
|
38
|
+
# Retrieve information regarding server status.
|
|
39
|
+
#
|
|
40
|
+
# @example Get server information
|
|
41
|
+
# server = Octoprint::ServerInformation.get
|
|
42
|
+
# puts "Version: #{server.version}"
|
|
43
|
+
#
|
|
44
|
+
# @return [ServerInformation] Server information object
|
|
45
|
+
# @raise [Octoprint::Exceptions::Error] if the request fails
|
|
46
|
+
#: -> ServerInformation
|
|
47
|
+
def self.get
|
|
48
|
+
fetch_resource
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|