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,221 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "erb"
|
|
5
|
+
require "faraday"
|
|
6
|
+
|
|
7
|
+
module Octoprint
|
|
8
|
+
# Timelapse API: get, delete and render timelapses, and change the timelapse config.
|
|
9
|
+
#
|
|
10
|
+
# {.get}, {.delete_file} and {.update_config} return the timelapses:
|
|
11
|
+
# the current {Config}, the {Rendered} timelapse files and, when requested with
|
|
12
|
+
# +unrendered: true+, the {Unrendered} timelapse jobs.
|
|
13
|
+
#
|
|
14
|
+
# Permissions: +TIMELAPSE_LIST+ ({.get}), +TIMELAPSE_DELETE+ ({.delete_file}),
|
|
15
|
+
# +TIMELAPSE_MANAGE_UNRENDERED+ ({.render}, {.delete_unrendered}) and
|
|
16
|
+
# +TIMELAPSE_ADMIN+ ({.update_config}).
|
|
17
|
+
#
|
|
18
|
+
# @example List rendered timelapses
|
|
19
|
+
# timelapse = Octoprint::Timelapse.get
|
|
20
|
+
# timelapse.config.type # => "off"
|
|
21
|
+
# timelapse.files.each { |file| puts "#{file.name} (#{file.size})" }
|
|
22
|
+
#
|
|
23
|
+
# @example Render every unrendered timelapse that isn't being processed
|
|
24
|
+
# Octoprint::Timelapse.get(unrendered: true).unrendered.each do |job|
|
|
25
|
+
# Octoprint::Timelapse.render(name: job.name) unless job.processing
|
|
26
|
+
# end
|
|
27
|
+
#
|
|
28
|
+
# @example Take a snapshot every 10 seconds of the next print
|
|
29
|
+
# Octoprint::Timelapse.update_config(type: "timed", interval: 10, fps: 30, save: true)
|
|
30
|
+
#
|
|
31
|
+
# @see https://docs.octoprint.org/en/1.11.2/api/timelapse.html
|
|
32
|
+
class Timelapse < BaseResource
|
|
33
|
+
include AutoInitializable
|
|
34
|
+
include Deserializable
|
|
35
|
+
|
|
36
|
+
resource_path("/api/timelapse")
|
|
37
|
+
|
|
38
|
+
# Timelapse types accepted by {.update_config}
|
|
39
|
+
TYPES = %w[off zchange timed].freeze #: Array[String]
|
|
40
|
+
|
|
41
|
+
# @!attribute [r] config
|
|
42
|
+
# @return [Timelapse::Config] The current timelapse configuration
|
|
43
|
+
auto_attr :config, type: Config
|
|
44
|
+
|
|
45
|
+
# @!attribute [r] enabled
|
|
46
|
+
# @return [Boolean] Whether timelapses are enabled in the webcam settings
|
|
47
|
+
auto_attr :enabled, type: Types::Boolean
|
|
48
|
+
|
|
49
|
+
# @!attribute [r] files
|
|
50
|
+
# @return [Array<Timelapse::Rendered>] The rendered timelapse files
|
|
51
|
+
auto_attr :files, type: Rendered, array: true
|
|
52
|
+
|
|
53
|
+
# @!attribute [r] unrendered
|
|
54
|
+
# @return [Array<Timelapse::Unrendered>, nil] The unrendered timelapse jobs, only present when requested
|
|
55
|
+
auto_attr :unrendered, type: Unrendered, array: true
|
|
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 :config, Config
|
|
65
|
+
array :files, Rendered
|
|
66
|
+
array :unrendered, Unrendered
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
class << self
|
|
70
|
+
# Retrieves the timelapses and the current timelapse config.
|
|
71
|
+
#
|
|
72
|
+
# @param unrendered [Boolean] Also include the unrendered timelapses
|
|
73
|
+
# @param force [Boolean] Bypass the server's timelapse cache
|
|
74
|
+
#
|
|
75
|
+
# @example
|
|
76
|
+
# timelapse = Octoprint::Timelapse.get(unrendered: true)
|
|
77
|
+
# timelapse.files.map(&:name) # => ["benchy_20261115.mp4"]
|
|
78
|
+
# timelapse.unrendered.map(&:name) # => ["cube_20261115"]
|
|
79
|
+
#
|
|
80
|
+
# @return [Timelapse] The timelapses and config
|
|
81
|
+
#: (?unrendered: bool, ?force: bool) -> Timelapse
|
|
82
|
+
def get(unrendered: false, force: false)
|
|
83
|
+
fetch_resource(options: query(unrendered: unrendered, force: force))
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Deletes a rendered timelapse file.
|
|
87
|
+
#
|
|
88
|
+
# @param filename [String] The name of the timelapse file
|
|
89
|
+
# @param unrendered [Boolean] Also include the unrendered timelapses in the result
|
|
90
|
+
#
|
|
91
|
+
# @example
|
|
92
|
+
# Octoprint::Timelapse.delete_file(filename: "benchy_20261115.mp4")
|
|
93
|
+
#
|
|
94
|
+
# @return [Timelapse] The updated timelapses and config
|
|
95
|
+
#: (filename: String, ?unrendered: bool) -> Timelapse
|
|
96
|
+
def delete_file(filename:, unrendered: false)
|
|
97
|
+
response = delete(path: with_query("#{@path}/#{escape(filename)}", query(unrendered: unrendered)))
|
|
98
|
+
deserialize(response)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Issues a command for an unrendered timelapse.
|
|
102
|
+
#
|
|
103
|
+
# @param name [String] The name of the unrendered timelapse job
|
|
104
|
+
# @param command [String] The command to issue. OctoPrint only supports +render+
|
|
105
|
+
#
|
|
106
|
+
# @example
|
|
107
|
+
# Octoprint::Timelapse.issue_unrendered_command(name: "cube_20261115", command: "render")
|
|
108
|
+
#
|
|
109
|
+
# @return [Boolean] true on success (204 No Content)
|
|
110
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is printing or paused
|
|
111
|
+
#: (name: String, command: String) -> untyped
|
|
112
|
+
def issue_unrendered_command(name:, command:)
|
|
113
|
+
post(path: "#{@path}/unrendered/#{escape(name)}", params: { command: command })
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Renders an unrendered timelapse. Rendering happens in the background on the server.
|
|
117
|
+
#
|
|
118
|
+
# @param name [String] The name of the unrendered timelapse job
|
|
119
|
+
#
|
|
120
|
+
# @example
|
|
121
|
+
# Octoprint::Timelapse.render(name: "cube_20261115")
|
|
122
|
+
#
|
|
123
|
+
# @return [Boolean] true on success (204 No Content)
|
|
124
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is printing or paused
|
|
125
|
+
#: (name: String) -> untyped
|
|
126
|
+
def render(name:)
|
|
127
|
+
issue_unrendered_command(name: name, command: "render")
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Deletes an unrendered timelapse and its snapshots.
|
|
131
|
+
#
|
|
132
|
+
# @param name [String] The name of the unrendered timelapse job
|
|
133
|
+
#
|
|
134
|
+
# @example
|
|
135
|
+
# Octoprint::Timelapse.delete_unrendered(name: "cube_20261115")
|
|
136
|
+
#
|
|
137
|
+
# @return [Boolean] true on success (204 No Content)
|
|
138
|
+
#: (name: String) -> untyped
|
|
139
|
+
def delete_unrendered(name:)
|
|
140
|
+
delete(path: "#{@path}/unrendered/#{escape(name)}")
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# Changes the timelapse config used for the next print.
|
|
144
|
+
#
|
|
145
|
+
# Options OctoPrint doesn't use for the given +type+ are ignored by the server.
|
|
146
|
+
# Settings left out fall back to OctoPrint's defaults (no post roll, 25 fps,
|
|
147
|
+
# always render after the print).
|
|
148
|
+
#
|
|
149
|
+
# @param type [String] +off+, +zchange+ (snapshot on Z change) or +timed+ (snapshot on an interval)
|
|
150
|
+
# @param post_roll [Integer, nil] Post roll in seconds
|
|
151
|
+
# @param fps [Integer, nil] Frames per second of the rendered video
|
|
152
|
+
# @param interval [Integer, nil] Seconds between snapshots (+timed+ only)
|
|
153
|
+
# @param retraction_z_hop [Numeric, nil] Retraction Z hop to ignore when detecting Z changes (+zchange+ only)
|
|
154
|
+
# @param min_delay [Numeric, nil] Minimum seconds between snapshots (+zchange+ only)
|
|
155
|
+
# @param render_after_print [String, nil] When to render after a print:
|
|
156
|
+
# +always+, +success+, +failure+ or +never+
|
|
157
|
+
# @param save [Boolean] Persist the config across server restarts (requires admin rights)
|
|
158
|
+
# @param unrendered [Boolean] Also include the unrendered timelapses in the result
|
|
159
|
+
#
|
|
160
|
+
# @example Snapshot on every layer change, rendered only for successful prints
|
|
161
|
+
# Octoprint::Timelapse.update_config(type: "zchange", retraction_z_hop: 0.4, render_after_print: "success")
|
|
162
|
+
#
|
|
163
|
+
# @example Turn timelapses off
|
|
164
|
+
# Octoprint::Timelapse.update_config(type: "off")
|
|
165
|
+
#
|
|
166
|
+
# @return [Timelapse] The updated timelapses and config
|
|
167
|
+
# @raise [ArgumentError] if the type isn't one of {TYPES}
|
|
168
|
+
# @raise [Octoprint::Exceptions::BadRequestError] if a setting is invalid
|
|
169
|
+
#: (
|
|
170
|
+
#| type: String,
|
|
171
|
+
#| ?post_roll: Integer?,
|
|
172
|
+
#| ?fps: Integer?,
|
|
173
|
+
#| ?interval: Integer?,
|
|
174
|
+
#| ?retraction_z_hop: Numeric?,
|
|
175
|
+
#| ?min_delay: Numeric?,
|
|
176
|
+
#| ?render_after_print: String?,
|
|
177
|
+
#| ?save: bool,
|
|
178
|
+
#| ?unrendered: bool
|
|
179
|
+
#| ) -> Timelapse
|
|
180
|
+
def update_config(type:, post_roll: nil, fps: nil, interval: nil, retraction_z_hop: nil, min_delay: nil,
|
|
181
|
+
render_after_print: nil, save: false, unrendered: false)
|
|
182
|
+
raise ArgumentError, "type must be one of #{TYPES.join(", ")}" unless TYPES.include?(type)
|
|
183
|
+
|
|
184
|
+
params = {
|
|
185
|
+
type: type,
|
|
186
|
+
postRoll: post_roll,
|
|
187
|
+
fps: fps,
|
|
188
|
+
interval: interval,
|
|
189
|
+
retractionZHop: retraction_z_hop,
|
|
190
|
+
minDelay: min_delay,
|
|
191
|
+
renderAfterPrint: render_after_print
|
|
192
|
+
}.compact
|
|
193
|
+
params[:save] = true if save
|
|
194
|
+
|
|
195
|
+
response = post(path: with_query(@path, query(unrendered: unrendered)), params: params)
|
|
196
|
+
deserialize(response)
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
private
|
|
200
|
+
|
|
201
|
+
#: (**bool flags) -> Hash[Symbol, bool]
|
|
202
|
+
def query(**flags)
|
|
203
|
+
flags.select { |_flag, value| value }
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
#: (String path, Hash[Symbol, untyped] options) -> String
|
|
207
|
+
def with_query(path, options)
|
|
208
|
+
return path if options.empty?
|
|
209
|
+
|
|
210
|
+
"#{path}?#{Faraday::Utils.build_query(options)}"
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# Percent-encodes a name for use as a path segment. Timelapse names keep the
|
|
214
|
+
# characters of the printed file's name, including spaces and "#".
|
|
215
|
+
#: (String name) -> String
|
|
216
|
+
def escape(name)
|
|
217
|
+
ERB::Util.url_encode(name)
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
end
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
# Common type aliases for use with auto_attr.
|
|
6
|
+
#
|
|
7
|
+
# This module provides convenient type aliases for commonly used types
|
|
8
|
+
# in the OctoPrint API. They are runtime values meant for auto_attr and
|
|
9
|
+
# Sorbet assertions; in RBS signature comments, write the type directly.
|
|
10
|
+
#
|
|
11
|
+
# @example Using with auto_attr
|
|
12
|
+
# class User
|
|
13
|
+
# include AutoInitializable
|
|
14
|
+
#
|
|
15
|
+
# auto_attr :name, type: String, nilable: false
|
|
16
|
+
# auto_attr :email, type: Types::NilableString # Alternative syntax
|
|
17
|
+
# auto_attr :tags, type: Types::StringArray
|
|
18
|
+
# auto_attr :metadata, type: Types::Hash
|
|
19
|
+
#
|
|
20
|
+
# auto_initialize!
|
|
21
|
+
# end
|
|
22
|
+
#
|
|
23
|
+
# @example The same types in an RBS signature comment
|
|
24
|
+
# #: (Hash[Symbol, untyped]) -> String?
|
|
25
|
+
# def process_data(data)
|
|
26
|
+
# data[:name]
|
|
27
|
+
# end
|
|
28
|
+
module Types
|
|
29
|
+
# A hash with symbol keys and untyped values (common for API responses)
|
|
30
|
+
# @example { name: "John", age: 30, active: true }
|
|
31
|
+
Hash = T::Hash[Symbol, T.untyped]
|
|
32
|
+
|
|
33
|
+
# An array of strings
|
|
34
|
+
# @example ["tag1", "tag2", "tag3"]
|
|
35
|
+
StringArray = T::Array[String]
|
|
36
|
+
|
|
37
|
+
# A nullable string (can be String or nil)
|
|
38
|
+
# @example "John Doe" or nil
|
|
39
|
+
NilableString = T.nilable(String)
|
|
40
|
+
|
|
41
|
+
# A nullable integer (can be Integer or nil)
|
|
42
|
+
# @example 42 or nil
|
|
43
|
+
NilableInteger = T.nilable(Integer)
|
|
44
|
+
|
|
45
|
+
# A nullable float (can be Float or nil)
|
|
46
|
+
# @example 3.14 or nil
|
|
47
|
+
NilableFloat = T.nilable(Float)
|
|
48
|
+
|
|
49
|
+
# A nullable hash (can be Hash or nil)
|
|
50
|
+
# @example { key: "value" } or nil
|
|
51
|
+
NilableHash = T.nilable(T::Hash[Symbol, T.untyped])
|
|
52
|
+
|
|
53
|
+
# A nullable string array (can be Array<String> or nil)
|
|
54
|
+
# @example ["tag1", "tag2"] or nil
|
|
55
|
+
NilableStringArray = T.nilable(T::Array[String])
|
|
56
|
+
|
|
57
|
+
# A boolean type (true or false)
|
|
58
|
+
# @example true or false
|
|
59
|
+
Boolean = T.any(TrueClass, FalseClass)
|
|
60
|
+
|
|
61
|
+
# A nullable boolean (can be Boolean or nil)
|
|
62
|
+
# @example true, false, or nil
|
|
63
|
+
NilableBoolean = T.nilable(T.any(TrueClass, FalseClass))
|
|
64
|
+
|
|
65
|
+
# API Response Types
|
|
66
|
+
# A typical API response hash
|
|
67
|
+
# @example { data: {...}, status: "success" }
|
|
68
|
+
ApiResponse = T::Hash[Symbol, T.untyped]
|
|
69
|
+
|
|
70
|
+
# File Types
|
|
71
|
+
# A file path string
|
|
72
|
+
# @example "/path/to/file.gcode"
|
|
73
|
+
FilePath = String
|
|
74
|
+
|
|
75
|
+
# File size in bytes
|
|
76
|
+
# @example 1048576
|
|
77
|
+
FileSize = Integer
|
|
78
|
+
|
|
79
|
+
# Time Types
|
|
80
|
+
# Unix timestamp (seconds since epoch)
|
|
81
|
+
# @example 1640995200
|
|
82
|
+
UnixTimestamp = Integer
|
|
83
|
+
|
|
84
|
+
# ISO 8601 formatted date string
|
|
85
|
+
# @example "2023-12-31T12:00:00Z"
|
|
86
|
+
Iso8601String = String
|
|
87
|
+
|
|
88
|
+
# Network Types
|
|
89
|
+
# A hostname or IP address
|
|
90
|
+
# @example "octopi.local" or "192.168.1.100"
|
|
91
|
+
Hostname = String
|
|
92
|
+
|
|
93
|
+
# A port number
|
|
94
|
+
# @example 80, 443, 5000
|
|
95
|
+
Port = Integer
|
|
96
|
+
|
|
97
|
+
# A URL string
|
|
98
|
+
# @example "https://octopi.local/api/version"
|
|
99
|
+
Url = String
|
|
100
|
+
|
|
101
|
+
# Printer Types
|
|
102
|
+
# A printer identifier
|
|
103
|
+
# @example "ender3", "_default"
|
|
104
|
+
PrinterId = String
|
|
105
|
+
|
|
106
|
+
# Number of extruders
|
|
107
|
+
# @example 1, 2, 4
|
|
108
|
+
ExtruderCount = Integer
|
|
109
|
+
|
|
110
|
+
# Bed temperature in Celsius
|
|
111
|
+
# @example 60.0, 80.5
|
|
112
|
+
BedTemperature = Float
|
|
113
|
+
|
|
114
|
+
# Job Types
|
|
115
|
+
# Job state string
|
|
116
|
+
# @example "Printing", "Paused", "Operational"
|
|
117
|
+
JobState = String
|
|
118
|
+
|
|
119
|
+
# Print progress percentage (0.0 to 100.0)
|
|
120
|
+
# @example 45.5, 100.0
|
|
121
|
+
ProgressPercent = Float
|
|
122
|
+
|
|
123
|
+
# Print time in seconds
|
|
124
|
+
# @example 3600, 7200
|
|
125
|
+
PrintTime = Integer
|
|
126
|
+
|
|
127
|
+
# Connection Types
|
|
128
|
+
# Connection state string
|
|
129
|
+
# @example "Connected", "Disconnected", "Connecting"
|
|
130
|
+
ConnectionState = String
|
|
131
|
+
|
|
132
|
+
# Baud rate for serial connections
|
|
133
|
+
# @example 115200, 250000, 500000
|
|
134
|
+
BaudRate = Integer
|
|
135
|
+
|
|
136
|
+
# Serial port name
|
|
137
|
+
# @example "/dev/ttyUSB0", "COM3"
|
|
138
|
+
SerialPort = String
|
|
139
|
+
end
|
|
140
|
+
end
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
# Utility operations for testing paths, URLs, and connectivity.
|
|
6
|
+
#
|
|
7
|
+
# @example Test a path
|
|
8
|
+
# result = Octoprint::Util.test_path(path: "/tmp/test")
|
|
9
|
+
# puts "Exists: #{result.exists}"
|
|
10
|
+
#
|
|
11
|
+
# @see https://docs.octoprint.org/en/1.11.2/api/util.html
|
|
12
|
+
class Util < BaseResource
|
|
13
|
+
include AutoInitializable
|
|
14
|
+
include Deserializable
|
|
15
|
+
|
|
16
|
+
resource_path("/api/util")
|
|
17
|
+
|
|
18
|
+
# @!attribute [r] result
|
|
19
|
+
# @return [String, nil] The result of the utility operation
|
|
20
|
+
auto_attr :result, type: Types::NilableString
|
|
21
|
+
|
|
22
|
+
# @!attribute [r] exists
|
|
23
|
+
# @return [Boolean, nil] Whether the tested resource exists
|
|
24
|
+
auto_attr :exists, type: Types::NilableBoolean
|
|
25
|
+
|
|
26
|
+
# @!attribute [r] status
|
|
27
|
+
# @return [String, nil] Status of the operation
|
|
28
|
+
auto_attr :status, type: Types::NilableString
|
|
29
|
+
|
|
30
|
+
# @!attribute [r] extra
|
|
31
|
+
# @return [Hash] Any additional fields returned by the API
|
|
32
|
+
auto_attr :extra, type: Hash
|
|
33
|
+
|
|
34
|
+
auto_initialize!
|
|
35
|
+
|
|
36
|
+
# Test file system paths
|
|
37
|
+
#
|
|
38
|
+
# @param [String] path Mandatory file system path
|
|
39
|
+
# @param [String] check_type Optional (file/directory)
|
|
40
|
+
# @param [String] check_access Optional permissions check
|
|
41
|
+
# @param [Boolean] allow_create_dir Optional directory creation flag
|
|
42
|
+
# @param [Boolean] check_writable_dir Optional directory writability test
|
|
43
|
+
# @return [Util]
|
|
44
|
+
#: (
|
|
45
|
+
#| path: String,
|
|
46
|
+
#| ?check_type: String?,
|
|
47
|
+
#| ?check_access: String?,
|
|
48
|
+
#| ?allow_create_dir: bool?,
|
|
49
|
+
#| ?check_writable_dir: bool?
|
|
50
|
+
#| ) -> Util
|
|
51
|
+
def self.test_path(path:, check_type: nil, check_access: nil, allow_create_dir: nil, check_writable_dir: nil)
|
|
52
|
+
params = { command: "path", path: path }
|
|
53
|
+
params[:check_type] = check_type if check_type
|
|
54
|
+
params[:check_access] = check_access if check_access
|
|
55
|
+
params[:allow_create_dir] = allow_create_dir unless allow_create_dir.nil?
|
|
56
|
+
params[:check_writable_dir] = check_writable_dir unless check_writable_dir.nil?
|
|
57
|
+
|
|
58
|
+
response = post(path: "#{@path}/test", params: params)
|
|
59
|
+
deserialize(response)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Test URL connectivity
|
|
63
|
+
#
|
|
64
|
+
# @param [String] url Mandatory URL to test
|
|
65
|
+
# @param [String] method Optional HTTP method (default HEAD)
|
|
66
|
+
# @param [Integer] timeout Optional timeout in seconds (default 3)
|
|
67
|
+
# @param [Integer] status Optional expected status code
|
|
68
|
+
# @param [String] auth_user Optional basic auth username
|
|
69
|
+
# @param [String] auth_pass Optional basic auth password
|
|
70
|
+
# @param [String] auth_digest Optional digest auth
|
|
71
|
+
# @param [String] auth_bearer Optional bearer token
|
|
72
|
+
# @param [String] content_type_whitelist Optional content type filter
|
|
73
|
+
# @param [String] content_type_blacklist Optional content type exclusion
|
|
74
|
+
# @return [Util]
|
|
75
|
+
#: (
|
|
76
|
+
#| url: String,
|
|
77
|
+
#| ?method: String?,
|
|
78
|
+
#| ?timeout: Integer?,
|
|
79
|
+
#| ?status: Integer?,
|
|
80
|
+
#| ?auth_user: String?,
|
|
81
|
+
#| ?auth_pass: String?,
|
|
82
|
+
#| ?auth_digest: String?,
|
|
83
|
+
#| ?auth_bearer: String?,
|
|
84
|
+
#| ?content_type_whitelist: String?,
|
|
85
|
+
#| ?content_type_blacklist: String?
|
|
86
|
+
#| ) -> Util
|
|
87
|
+
def self.test_url(url:, method: nil, timeout: nil, status: nil, auth_user: nil, auth_pass: nil,
|
|
88
|
+
auth_digest: nil, auth_bearer: nil, content_type_whitelist: nil, content_type_blacklist: nil)
|
|
89
|
+
# rubocop:enable Metrics/ParameterLists
|
|
90
|
+
options = {
|
|
91
|
+
method: method, timeout: timeout, status: status,
|
|
92
|
+
auth_user: auth_user, auth_pass: auth_pass, auth_digest: auth_digest, auth_bearer: auth_bearer,
|
|
93
|
+
content_type_whitelist: content_type_whitelist, content_type_blacklist: content_type_blacklist
|
|
94
|
+
}.compact
|
|
95
|
+
params = build_url_test_params(url, options)
|
|
96
|
+
response = post(path: "#{@path}/test", params: params)
|
|
97
|
+
deserialize(response)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
private_class_method def self.build_url_test_params(url, options)
|
|
101
|
+
{ command: "url", url: url }.merge(options.compact)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Test server connectivity
|
|
105
|
+
#
|
|
106
|
+
# @param [String] host Mandatory hostname or IP address
|
|
107
|
+
# @param [Integer] port Mandatory port number
|
|
108
|
+
# @param [String] protocol Optional protocol (default TCP)
|
|
109
|
+
# @param [Float] timeout Optional timeout in seconds (default 3.05)
|
|
110
|
+
# @return [Util]
|
|
111
|
+
#: (
|
|
112
|
+
#| host: String,
|
|
113
|
+
#| port: Integer,
|
|
114
|
+
#| ?protocol: String?,
|
|
115
|
+
#| ?timeout: Float?
|
|
116
|
+
#| ) -> Util
|
|
117
|
+
def self.test_server(host:, port:, protocol: nil, timeout: nil)
|
|
118
|
+
params = { command: "server", host: host, port: port }
|
|
119
|
+
params[:protocol] = protocol if protocol
|
|
120
|
+
params[:timeout] = timeout if timeout
|
|
121
|
+
|
|
122
|
+
response = post(path: "#{@path}/test", params: params)
|
|
123
|
+
deserialize(response)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Test DNS hostname resolution
|
|
127
|
+
#
|
|
128
|
+
# @param [String] name Mandatory hostname to resolve
|
|
129
|
+
# @return [Util]
|
|
130
|
+
#: (name: String) -> Util
|
|
131
|
+
def self.test_resolution(name:)
|
|
132
|
+
params = { command: "resolution", name: name }
|
|
133
|
+
|
|
134
|
+
response = post(path: "#{@path}/test", params: params)
|
|
135
|
+
deserialize(response)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Test network address
|
|
139
|
+
#
|
|
140
|
+
# @param [String] address Optional address (defaults to client address)
|
|
141
|
+
# @return [Util]
|
|
142
|
+
#: (?address: String?) -> Util
|
|
143
|
+
def self.test_address(address: nil)
|
|
144
|
+
params = { command: "address" }
|
|
145
|
+
params[:address] = address if address
|
|
146
|
+
|
|
147
|
+
response = post(path: "#{@path}/test", params: params)
|
|
148
|
+
deserialize(response)
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
# The Wizard API allows retrieval of registered wizard dialog data
|
|
6
|
+
# and completion of wizard dialogs.
|
|
7
|
+
#
|
|
8
|
+
# @see https://docs.octoprint.org/en/master/api/wizard.html OctoPrint Wizard API Documentation
|
|
9
|
+
#
|
|
10
|
+
# @example Get wizard data
|
|
11
|
+
# wizards = Octoprint::Wizard.get
|
|
12
|
+
# wizards.each do |name, data|
|
|
13
|
+
# puts "#{name}: required=#{data[:required]}, ignored=#{data[:ignored]}"
|
|
14
|
+
# end
|
|
15
|
+
#
|
|
16
|
+
# @example Complete wizard dialog
|
|
17
|
+
# Octoprint::Wizard.finish(handled: ["corewizard", "softwareupdate"])
|
|
18
|
+
class Wizard < BaseResource
|
|
19
|
+
resource_path("/api/setup/wizard")
|
|
20
|
+
|
|
21
|
+
# Retrieves registered wizard data from the OctoPrint server.
|
|
22
|
+
#
|
|
23
|
+
# Returns a Hash mapping wizard identifiers to wizard data entries.
|
|
24
|
+
# Each entry contains details about whether the wizard is required,
|
|
25
|
+
# ignored, its version, and plugin-specific details.
|
|
26
|
+
#
|
|
27
|
+
# @example Get wizard data
|
|
28
|
+
# wizards = Octoprint::Wizard.get
|
|
29
|
+
# wizards.each do |name, data|
|
|
30
|
+
# puts "#{name}: required=#{data[:required]}"
|
|
31
|
+
# end
|
|
32
|
+
#
|
|
33
|
+
# @return [Hash] Wizard data keyed by wizard identifier
|
|
34
|
+
# @raise [Octoprint::Exceptions::Error] if the request fails
|
|
35
|
+
#: -> Hash[Symbol, untyped]
|
|
36
|
+
def self.get
|
|
37
|
+
fetch_resource(deserialize: false)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Completes a wizard dialog by reporting which wizards were handled.
|
|
41
|
+
#
|
|
42
|
+
# Triggers the on_wizard_finish method across all registered wizard
|
|
43
|
+
# plugins, passing information about which wizards were handled
|
|
44
|
+
# versus skipped.
|
|
45
|
+
#
|
|
46
|
+
# @example Complete specific wizards
|
|
47
|
+
# Octoprint::Wizard.finish(handled: ["corewizard", "softwareupdate"])
|
|
48
|
+
#
|
|
49
|
+
# @param handled [Array<String>] List of wizard identifiers that were processed (not skipped)
|
|
50
|
+
# @return [T::Boolean] true on success (204 No Content)
|
|
51
|
+
# @raise [Octoprint::Exceptions::Error] if the request fails
|
|
52
|
+
#: (handled: Array[String]) -> untyped
|
|
53
|
+
def self.finish(handled:)
|
|
54
|
+
post(params: { handled: handled })
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
data/lib/octoprint.rb
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "active_support/all"
|
|
5
|
+
require "zeitwerk"
|
|
6
|
+
require "sorbet-runtime"
|
|
7
|
+
|
|
8
|
+
loader = Zeitwerk::Loader.for_gem
|
|
9
|
+
loader.ignore("#{__dir__}/tapioca")
|
|
10
|
+
loader.setup
|
|
11
|
+
|
|
12
|
+
# Welcome to the Octoprint Gem!
|
|
13
|
+
#
|
|
14
|
+
# This gem is still under development.
|
|
15
|
+
# @attr [Octoprint::Client] client The configured API client
|
|
16
|
+
module Octoprint
|
|
17
|
+
class << self
|
|
18
|
+
# Configure the API client with the server's address and key
|
|
19
|
+
#
|
|
20
|
+
# @example
|
|
21
|
+
# Octoprint.configure(host: "http://octopi.local", api_key: "key", open_timeout: 2, timeout: 3)
|
|
22
|
+
#
|
|
23
|
+
# @param [String] host Server's host address
|
|
24
|
+
# @param [String] api_key Server's API key
|
|
25
|
+
# @param [Numeric, nil] open_timeout Seconds to wait for the connection to open. nil falls back to `timeout`
|
|
26
|
+
# @param [Numeric, nil] timeout Seconds to wait for a read or a write. nil: adapter default (60s)
|
|
27
|
+
# @return [nil]
|
|
28
|
+
#: (
|
|
29
|
+
#| host: String,
|
|
30
|
+
#| api_key: String,
|
|
31
|
+
#| ?open_timeout: Numeric?,
|
|
32
|
+
#| ?timeout: Numeric?
|
|
33
|
+
#| ) -> void
|
|
34
|
+
def configure(host:, api_key:, open_timeout: Client::DEFAULT_OPEN_TIMEOUT, timeout: Client::DEFAULT_TIMEOUT)
|
|
35
|
+
self.client = Client.new(host: host, api_key: api_key, open_timeout: open_timeout, timeout: timeout)
|
|
36
|
+
|
|
37
|
+
nil
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# The API client used for the requests
|
|
41
|
+
# @return [Client, nil]
|
|
42
|
+
#: -> Client?
|
|
43
|
+
def client
|
|
44
|
+
Thread.current[:client]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Sets the API client used for the requests
|
|
48
|
+
# @param [Client] client
|
|
49
|
+
def client=(client)
|
|
50
|
+
Thread.current[:client] = client
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Alias for backward compatibility
|
|
55
|
+
# @deprecated Use Octoprint::Access::User instead
|
|
56
|
+
User = Access::User
|
|
57
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
|
|
3
|
+
# DO NOT EDIT MANUALLY
|
|
4
|
+
# This is an autogenerated file for types exported from the `octoprint` gem.
|
|
5
|
+
# Please instead update this file by running `bundle exec rake rbi:export`.
|
|
6
|
+
|
|
7
|
+
class Octoprint::Access::Group
|
|
8
|
+
sig { returns(T::Boolean) }
|
|
9
|
+
def changeable; end
|
|
10
|
+
|
|
11
|
+
sig { returns(T::Boolean) }
|
|
12
|
+
def dangerous; end
|
|
13
|
+
|
|
14
|
+
sig { returns(T::Boolean) }
|
|
15
|
+
def default; end
|
|
16
|
+
|
|
17
|
+
sig { returns(T.nilable(::String)) }
|
|
18
|
+
def description; end
|
|
19
|
+
|
|
20
|
+
sig { returns(T.nilable(::Hash)) }
|
|
21
|
+
def extra; end
|
|
22
|
+
|
|
23
|
+
sig { returns(T.nilable(::String)) }
|
|
24
|
+
def key; end
|
|
25
|
+
|
|
26
|
+
sig { returns(T.nilable(::String)) }
|
|
27
|
+
def name; end
|
|
28
|
+
|
|
29
|
+
sig { returns(T.nilable(::Hash)) }
|
|
30
|
+
def needs; end
|
|
31
|
+
|
|
32
|
+
sig { returns(T.nilable(T::Array[::String])) }
|
|
33
|
+
def needs_role; end
|
|
34
|
+
|
|
35
|
+
sig { returns(T.nilable(T::Array[::String])) }
|
|
36
|
+
def permissions; end
|
|
37
|
+
|
|
38
|
+
sig { returns(T::Boolean) }
|
|
39
|
+
def removable; end
|
|
40
|
+
|
|
41
|
+
sig { returns(T.nilable(T::Array[::String])) }
|
|
42
|
+
def subgroups; end
|
|
43
|
+
|
|
44
|
+
sig { returns(T::Boolean) }
|
|
45
|
+
def toggleable; end
|
|
46
|
+
end
|