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,227 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "erb"
|
|
5
|
+
|
|
6
|
+
module Octoprint
|
|
7
|
+
# Slicers and slicing profiles of the OctoPrint server.
|
|
8
|
+
#
|
|
9
|
+
# Slicers are provided by plugins (for example the CuraEngine Legacy plugin, with the
|
|
10
|
+
# slicer key +curalegacy+). Each slicer has its own set of slicing profiles, and the content
|
|
11
|
+
# of a profile's {Slicing::Profile#data data} depends on the slicer.
|
|
12
|
+
#
|
|
13
|
+
# Listing requires the +SLICE+ permission. Adding, updating and deleting profiles
|
|
14
|
+
# requires the +SETTINGS+ permission.
|
|
15
|
+
#
|
|
16
|
+
# To slice a file, see {Files.slice}.
|
|
17
|
+
#
|
|
18
|
+
# @example List all slicers and their profiles
|
|
19
|
+
# Octoprint::Slicing.list.each_value do |slicer|
|
|
20
|
+
# puts "#{slicer.display_name} (configured: #{slicer.configured?})"
|
|
21
|
+
# slicer.profiles.each_value { |profile| puts " - #{profile.display_name}" }
|
|
22
|
+
# end
|
|
23
|
+
#
|
|
24
|
+
# @example List the profiles of a slicer
|
|
25
|
+
# profiles = Octoprint::Slicing.profiles(slicer: "curalegacy")
|
|
26
|
+
# profiles.keys # => [:high_quality, :normal_quality]
|
|
27
|
+
#
|
|
28
|
+
# @example Retrieve a profile with its data
|
|
29
|
+
# profile = Octoprint::Slicing.get_profile(slicer: "curalegacy", key: "high_quality")
|
|
30
|
+
# profile.data[:layer_height] # => 0.1
|
|
31
|
+
#
|
|
32
|
+
# @example Add, update and delete a profile
|
|
33
|
+
# Octoprint::Slicing.add_profile(
|
|
34
|
+
# slicer: "curalegacy",
|
|
35
|
+
# key: "draft",
|
|
36
|
+
# display_name: "Draft",
|
|
37
|
+
# description: "Fast and ugly",
|
|
38
|
+
# data: { layer_height: 0.3 }
|
|
39
|
+
# )
|
|
40
|
+
# Octoprint::Slicing.update_profile(slicer: "curalegacy", key: "draft", default: true)
|
|
41
|
+
# Octoprint::Slicing.delete_profile(slicer: "curalegacy", key: "draft")
|
|
42
|
+
#
|
|
43
|
+
# @see https://docs.octoprint.org/en/1.11.2/api/slicing.html OctoPrint Slicing API Documentation
|
|
44
|
+
class Slicing < BaseResource
|
|
45
|
+
resource_path("/api/slicing")
|
|
46
|
+
|
|
47
|
+
class << self
|
|
48
|
+
# Lists all slicers and their slicing profiles.
|
|
49
|
+
#
|
|
50
|
+
# @example
|
|
51
|
+
# slicers = Octoprint::Slicing.list
|
|
52
|
+
# slicers[:curalegacy].display_name # => "CuraEngine Legacy"
|
|
53
|
+
#
|
|
54
|
+
# @example Only list configured slicers
|
|
55
|
+
# Octoprint::Slicing.list(configured: true)
|
|
56
|
+
#
|
|
57
|
+
# @param configured [Boolean] Only include the slicers that are configured
|
|
58
|
+
# @return [Hash{Symbol => Slicing::Slicer}] The slicers, by {Slicing::Slicer#key key}.
|
|
59
|
+
# Empty when no slicer is installed
|
|
60
|
+
# @raise [Octoprint::Exceptions::AuthenticationError] if the user lacks the +SLICE+ permission
|
|
61
|
+
#: (?configured: bool) -> Hash[Symbol, Slicer]
|
|
62
|
+
def list(configured: false)
|
|
63
|
+
response = fetch_resource(deserialize: false, options: configured_option(configured))
|
|
64
|
+
response.values.to_h do |slicer_data|
|
|
65
|
+
slicer = Slicer.deserialize(slicer_data)
|
|
66
|
+
[slicer.key.to_sym, slicer]
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Lists the slicing profiles of a slicer.
|
|
71
|
+
#
|
|
72
|
+
# The profiles don't include their data. Use {.get_profile} to retrieve it.
|
|
73
|
+
#
|
|
74
|
+
# @example
|
|
75
|
+
# profiles = Octoprint::Slicing.profiles(slicer: "curalegacy")
|
|
76
|
+
# profiles[:high_quality].display_name # => "High Quality"
|
|
77
|
+
#
|
|
78
|
+
# @param slicer [String] The slicer's key
|
|
79
|
+
# @param configured [Boolean] Only list the profiles if the slicer is configured
|
|
80
|
+
# @return [Hash{Symbol => Slicing::Profile}] The profiles, by {Slicing::Profile#key key}
|
|
81
|
+
# @raise [Octoprint::Exceptions::NotFoundError] if the slicer doesn't exist, or if +configured+ is true
|
|
82
|
+
# and the slicer isn't configured
|
|
83
|
+
# @raise [Octoprint::Exceptions::AuthenticationError] if the user lacks the +SLICE+ permission
|
|
84
|
+
#: (slicer: String, ?configured: bool) -> Hash[Symbol, Profile]
|
|
85
|
+
def profiles(slicer:, configured: false)
|
|
86
|
+
response = fetch_resource(profiles_path(slicer), deserialize: false, options: configured_option(configured))
|
|
87
|
+
deserialize_profiles(response)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Retrieves a slicing profile, including its data.
|
|
91
|
+
#
|
|
92
|
+
# @example
|
|
93
|
+
# profile = Octoprint::Slicing.get_profile(slicer: "curalegacy", key: "high_quality")
|
|
94
|
+
# profile.data # => { layer_height: 0.1, ... }
|
|
95
|
+
#
|
|
96
|
+
# @param slicer [String] The slicer's key
|
|
97
|
+
# @param key [String] The profile's key
|
|
98
|
+
# @return [Slicing::Profile] The profile
|
|
99
|
+
# @raise [Octoprint::Exceptions::NotFoundError] if the slicer or the profile doesn't exist
|
|
100
|
+
# @raise [Octoprint::Exceptions::AuthenticationError] if the user lacks the +SLICE+ permission
|
|
101
|
+
#: (slicer: String, key: String) -> Profile
|
|
102
|
+
def get_profile(slicer:, key:)
|
|
103
|
+
Profile.deserialize(fetch_resource(profile_subpath(slicer, key), deserialize: false))
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Adds a slicing profile, or replaces it if a profile with this key already exists.
|
|
107
|
+
#
|
|
108
|
+
# The first profile added to a slicer becomes its default profile.
|
|
109
|
+
#
|
|
110
|
+
# @example
|
|
111
|
+
# profile = Octoprint::Slicing.add_profile(
|
|
112
|
+
# slicer: "curalegacy",
|
|
113
|
+
# key: "draft",
|
|
114
|
+
# display_name: "Draft",
|
|
115
|
+
# description: "Fast and ugly",
|
|
116
|
+
# data: { layer_height: 0.3 }
|
|
117
|
+
# )
|
|
118
|
+
# profile.resource # => "http://octopi.local/api/slicing/curalegacy/profiles/draft"
|
|
119
|
+
#
|
|
120
|
+
# @param slicer [String] The slicer's key
|
|
121
|
+
# @param key [String] The new profile's key
|
|
122
|
+
# @param data [Hash] The slicer-specific profile settings
|
|
123
|
+
# @param display_name [String, nil] The profile's human-readable name
|
|
124
|
+
# @param description [String, nil] The profile's description
|
|
125
|
+
# @return [Slicing::Profile] The added profile, without its data
|
|
126
|
+
# @raise [Octoprint::Exceptions::NotFoundError] if the slicer doesn't exist
|
|
127
|
+
# @raise [Octoprint::Exceptions::AuthenticationError] if the user lacks the +SETTINGS+ permission
|
|
128
|
+
#: (
|
|
129
|
+
#| slicer: String,
|
|
130
|
+
#| key: String,
|
|
131
|
+
#| ?data: Hash[(Symbol | String), untyped],
|
|
132
|
+
#| ?display_name: String?,
|
|
133
|
+
#| ?description: String?
|
|
134
|
+
#| ) -> Profile
|
|
135
|
+
def add_profile(slicer:, key:, data: {}, display_name: nil, description: nil)
|
|
136
|
+
params = { displayName: display_name, description: description, data: data }.compact
|
|
137
|
+
Profile.deserialize(put(path: profile_path(slicer, key), params: params))
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# Updates a slicing profile. Only the given attributes are changed.
|
|
141
|
+
#
|
|
142
|
+
# @example Rename a profile
|
|
143
|
+
# Octoprint::Slicing.update_profile(slicer: "curalegacy", key: "draft", display_name: "Quick draft")
|
|
144
|
+
#
|
|
145
|
+
# @example Make a profile the slicer's default
|
|
146
|
+
# Octoprint::Slicing.update_profile(slicer: "curalegacy", key: "draft", default: true)
|
|
147
|
+
#
|
|
148
|
+
# @param slicer [String] The slicer's key
|
|
149
|
+
# @param key [String] The profile's key
|
|
150
|
+
# @param data [Hash, nil] Profile settings to change. Settings left out keep their value
|
|
151
|
+
# @param display_name [String, nil] The new human-readable name
|
|
152
|
+
# @param description [String, nil] The new description
|
|
153
|
+
# @param default [Boolean, nil] true to make this profile the slicer's default
|
|
154
|
+
# @return [Slicing::Profile] The updated profile, without its data
|
|
155
|
+
# @raise [Octoprint::Exceptions::NotFoundError] if the slicer or the profile doesn't exist
|
|
156
|
+
# @raise [Octoprint::Exceptions::AuthenticationError] if the user lacks the +SETTINGS+ permission
|
|
157
|
+
#: (
|
|
158
|
+
#| slicer: String,
|
|
159
|
+
#| key: String,
|
|
160
|
+
#| ?data: Hash[(Symbol | String), untyped]?,
|
|
161
|
+
#| ?display_name: String?,
|
|
162
|
+
#| ?description: String?,
|
|
163
|
+
#| ?default: bool?
|
|
164
|
+
#| ) -> Profile
|
|
165
|
+
def update_profile(slicer:, key:, data: nil, display_name: nil, description: nil, default: nil)
|
|
166
|
+
params = { displayName: display_name, description: description, default: default, data: data }.compact
|
|
167
|
+
Profile.deserialize(patch(path: profile_path(slicer, key), params: params))
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# Deletes a slicing profile.
|
|
171
|
+
#
|
|
172
|
+
# The server reports a success even when the profile doesn't exist.
|
|
173
|
+
#
|
|
174
|
+
# @example
|
|
175
|
+
# Octoprint::Slicing.delete_profile(slicer: "curalegacy", key: "draft") # => true
|
|
176
|
+
#
|
|
177
|
+
# @param slicer [String] The slicer's key
|
|
178
|
+
# @param key [String] The profile's key
|
|
179
|
+
# @return [true] when the request succeeded
|
|
180
|
+
# @raise [Octoprint::Exceptions::NotFoundError] if the slicer doesn't exist
|
|
181
|
+
# @raise [Octoprint::Exceptions::AuthenticationError] if the user lacks the +SETTINGS+ permission
|
|
182
|
+
#: (slicer: String, key: String) -> TrueClass
|
|
183
|
+
def delete_profile(slicer:, key:)
|
|
184
|
+
delete(path: profile_path(slicer, key))
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
# Builds the profiles from the hash of profile key => profile data returned by the API.
|
|
188
|
+
#
|
|
189
|
+
# The profiles are keyed by their {Slicing::Profile#key key}, as a Symbol. The client underscores
|
|
190
|
+
# the hash keys of every response, so a profile named +high-quality+ is keyed +:"high-quality"+,
|
|
191
|
+
# not +:high_quality+.
|
|
192
|
+
#
|
|
193
|
+
# @api private
|
|
194
|
+
# @param profiles_data [Hash, nil] The profiles data, by key
|
|
195
|
+
# @return [Hash{Symbol => Slicing::Profile}] The profiles, by key. Empty when +profiles_data+ is nil
|
|
196
|
+
#: (Hash[Symbol, untyped]? profiles_data) -> Hash[Symbol, Profile]
|
|
197
|
+
def deserialize_profiles(profiles_data)
|
|
198
|
+
(profiles_data || {}).values.to_h do |profile_data|
|
|
199
|
+
profile = Profile.deserialize(profile_data)
|
|
200
|
+
[profile.key.to_sym, profile]
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
private
|
|
205
|
+
|
|
206
|
+
#: (String slicer) -> String
|
|
207
|
+
def profiles_path(slicer)
|
|
208
|
+
"#{ERB::Util.url_encode(slicer)}/profiles"
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
#: (String slicer, String key) -> String
|
|
212
|
+
def profile_subpath(slicer, key)
|
|
213
|
+
"#{profiles_path(slicer)}/#{ERB::Util.url_encode(key)}"
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
#: (String slicer, String key) -> String
|
|
217
|
+
def profile_path(slicer, key)
|
|
218
|
+
"#{@path}/#{profile_subpath(slicer, key)}"
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
#: (bool configured) -> Hash[Symbol, bool]
|
|
222
|
+
def configured_option(configured)
|
|
223
|
+
configured ? { configured: true } : {}
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class SystemCommands
|
|
6
|
+
# Represents a single system command available on the OctoPrint server.
|
|
7
|
+
# System commands can be used to perform actions like shutdown, restart, etc.
|
|
8
|
+
#
|
|
9
|
+
# @see https://docs.octoprint.org/en/master/api/system.html#data-model
|
|
10
|
+
class Command
|
|
11
|
+
include Deserializable
|
|
12
|
+
include AutoInitializable
|
|
13
|
+
|
|
14
|
+
# @!attribute [r] action
|
|
15
|
+
# @return [String] The unique identifier/action name for this command
|
|
16
|
+
auto_attr :action, type: String, nilable: false
|
|
17
|
+
|
|
18
|
+
# @!attribute [r] name
|
|
19
|
+
# @return [String] The human-readable name of the command
|
|
20
|
+
auto_attr :name, type: String, nilable: false
|
|
21
|
+
|
|
22
|
+
# @!attribute [r] confirm
|
|
23
|
+
# @return [String, nil] Optional confirmation message to show before executing
|
|
24
|
+
auto_attr :confirm, type: String
|
|
25
|
+
|
|
26
|
+
# @!attribute [r] source
|
|
27
|
+
# @return [String] The source of the command (e.g., "core" or "custom")
|
|
28
|
+
auto_attr :source, type: String, nilable: false
|
|
29
|
+
|
|
30
|
+
# @!attribute [r] resource
|
|
31
|
+
# @return [String] The URL endpoint for executing this command
|
|
32
|
+
auto_attr :resource, type: String, nilable: false
|
|
33
|
+
|
|
34
|
+
# @!attribute [r] extra
|
|
35
|
+
# @return [Hash] Any additional fields returned by the API that are not explicitly defined
|
|
36
|
+
auto_attr :extra, type: Hash
|
|
37
|
+
|
|
38
|
+
auto_initialize!
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
# The SystemCommands API allows retrieval and execution of system commands on the OctoPrint server.
|
|
6
|
+
# System commands can be used to shutdown or restart the OctoPrint server or the system it's running on.
|
|
7
|
+
#
|
|
8
|
+
# @see https://docs.octoprint.org/en/master/api/system.html OctoPrint System API Documentation
|
|
9
|
+
class SystemCommands < BaseResource
|
|
10
|
+
include Deserializable
|
|
11
|
+
include AutoInitializable
|
|
12
|
+
|
|
13
|
+
resource_path("/api/system/commands")
|
|
14
|
+
|
|
15
|
+
# @!attribute [r] core
|
|
16
|
+
# @return [Array<Command>] List of core (predefined) system commands
|
|
17
|
+
auto_attr :core, type: Command, array: true, nilable: false
|
|
18
|
+
|
|
19
|
+
# @!attribute [r] custom
|
|
20
|
+
# @return [Array<Command>] List of custom (user-defined) system commands
|
|
21
|
+
auto_attr :custom, type: Command, array: true, nilable: false
|
|
22
|
+
|
|
23
|
+
# @!attribute [r] extra
|
|
24
|
+
# @return [Hash] Any additional fields returned by the API that are not explicitly defined
|
|
25
|
+
auto_attr :extra, type: Hash
|
|
26
|
+
|
|
27
|
+
auto_initialize!
|
|
28
|
+
|
|
29
|
+
deserialize_config do
|
|
30
|
+
array :core, Command
|
|
31
|
+
array :custom, Command
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Retrieves all registered system commands from the OctoPrint server.
|
|
35
|
+
#
|
|
36
|
+
# This method fetches both core and custom system commands. Core commands are
|
|
37
|
+
# predefined by OctoPrint (like shutdown, restart), while custom commands are
|
|
38
|
+
# user-defined.
|
|
39
|
+
#
|
|
40
|
+
# @example Get all system commands
|
|
41
|
+
# commands = Octoprint::SystemCommands.list
|
|
42
|
+
#
|
|
43
|
+
# # Access core commands
|
|
44
|
+
# commands.core.each do |cmd|
|
|
45
|
+
# puts "Core: #{cmd.name} - #{cmd.action}"
|
|
46
|
+
# end
|
|
47
|
+
#
|
|
48
|
+
# # Access custom commands
|
|
49
|
+
# commands.custom.each do |cmd|
|
|
50
|
+
# puts "Custom: #{cmd.name} - #{cmd.action}"
|
|
51
|
+
# end
|
|
52
|
+
#
|
|
53
|
+
# @return [SystemCommands] A SystemCommands object containing arrays of core and custom commands
|
|
54
|
+
# @raise [Octoprint::Exceptions::Error] if the request fails
|
|
55
|
+
#: -> SystemCommands
|
|
56
|
+
def self.list
|
|
57
|
+
fetch_resource
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Retrieves all registered system commands for a specific source from the OctoPrint server.
|
|
61
|
+
#
|
|
62
|
+
# This method fetches system commands from a specific source (e.g., "core" or "custom").
|
|
63
|
+
# The source determines which set of commands to retrieve.
|
|
64
|
+
#
|
|
65
|
+
# @example Get core system commands
|
|
66
|
+
# commands = Octoprint::SystemCommands.list_by_source("core")
|
|
67
|
+
# commands.each do |cmd|
|
|
68
|
+
# puts "#{cmd.name} - #{cmd.action}"
|
|
69
|
+
# end
|
|
70
|
+
#
|
|
71
|
+
# @example Get custom system commands
|
|
72
|
+
# commands = Octoprint::SystemCommands.list_by_source("custom")
|
|
73
|
+
# commands.each do |cmd|
|
|
74
|
+
# puts "#{cmd.name} - #{cmd.action}"
|
|
75
|
+
# end
|
|
76
|
+
#
|
|
77
|
+
# @param source [String] The source to retrieve commands for (e.g., "core", "custom")
|
|
78
|
+
# @return [Array<Command>] Array of Command objects for the specified source
|
|
79
|
+
# @raise [Octoprint::Exceptions::Error] if the request fails
|
|
80
|
+
#: (String source) -> Array[Command]
|
|
81
|
+
def self.list_by_source(source)
|
|
82
|
+
response = fetch_resource(source, deserialize: false)
|
|
83
|
+
response.map { |command_data| Command.deserialize(command_data) }
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Executes a registered system command on the OctoPrint server.
|
|
87
|
+
#
|
|
88
|
+
# This method sends a POST request to execute a specific system command.
|
|
89
|
+
# The command must be pre-registered on the server and available in the specified source.
|
|
90
|
+
#
|
|
91
|
+
# @example Execute core restart command
|
|
92
|
+
# Octoprint::SystemCommands.execute("core", "restart")
|
|
93
|
+
#
|
|
94
|
+
# @example Execute core reboot command
|
|
95
|
+
# Octoprint::SystemCommands.execute("core", "reboot")
|
|
96
|
+
#
|
|
97
|
+
# @example Execute custom command
|
|
98
|
+
# Octoprint::SystemCommands.execute("custom", "my_custom_command")
|
|
99
|
+
#
|
|
100
|
+
# @param source [String] The source of the command (e.g., "core", "custom")
|
|
101
|
+
# @param action [String] The action/identifier of the command to execute
|
|
102
|
+
# @return [Boolean] true if the command was executed successfully
|
|
103
|
+
# @raise [Octoprint::Exceptions::Error] if the request fails or command is not found
|
|
104
|
+
#: (String source, String action) -> bool
|
|
105
|
+
def self.execute(source, action) # rubocop:disable Naming/PredicateMethod
|
|
106
|
+
post(path: "/api/system/commands/#{source}/#{action}")
|
|
107
|
+
true
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Timelapse
|
|
6
|
+
# The timelapse configuration used for the next print.
|
|
7
|
+
#
|
|
8
|
+
# Which attributes are set depends on {#type}: +off+ has none, +zchange+ has
|
|
9
|
+
# {#retraction_z_hop} and {#min_delay}, and +timed+ has {#interval}.
|
|
10
|
+
#
|
|
11
|
+
# @example
|
|
12
|
+
# config = Octoprint::Timelapse.get.config
|
|
13
|
+
# config.type # => "timed"
|
|
14
|
+
# config.interval # => 10
|
|
15
|
+
# config.fps # => 25
|
|
16
|
+
#
|
|
17
|
+
# @see https://docs.octoprint.org/en/1.11.2/api/timelapse.html#timelapse-configuration
|
|
18
|
+
class Config
|
|
19
|
+
include AutoInitializable
|
|
20
|
+
include Deserializable
|
|
21
|
+
|
|
22
|
+
# @!attribute [r] type
|
|
23
|
+
# @return [String] +off+, +zchange+ or +timed+
|
|
24
|
+
auto_attr :type, type: String
|
|
25
|
+
|
|
26
|
+
# @!attribute [r] post_roll
|
|
27
|
+
# @return [Integer, nil] Post roll in seconds
|
|
28
|
+
auto_attr :post_roll, type: Integer
|
|
29
|
+
|
|
30
|
+
# @!attribute [r] fps
|
|
31
|
+
# @return [Integer, nil] Frames per second of the rendered video
|
|
32
|
+
auto_attr :fps, type: Integer
|
|
33
|
+
|
|
34
|
+
# @!attribute [r] render_after_print
|
|
35
|
+
# @return [String, nil] When to render after the print: +always+, +success+, +failure+ or +never+
|
|
36
|
+
auto_attr :render_after_print, type: String
|
|
37
|
+
|
|
38
|
+
# @!attribute [r] interval
|
|
39
|
+
# @return [Integer, nil] Seconds between snapshots (+timed+ only)
|
|
40
|
+
auto_attr :interval, type: Integer
|
|
41
|
+
|
|
42
|
+
# @!attribute [r] retraction_z_hop
|
|
43
|
+
# @return [Numeric, nil] Retraction Z hop ignored when detecting Z changes (+zchange+ only)
|
|
44
|
+
auto_attr :retraction_z_hop, type: Numeric
|
|
45
|
+
|
|
46
|
+
# @!attribute [r] min_delay
|
|
47
|
+
# @return [Numeric, nil] Minimum seconds between snapshots (+zchange+ only)
|
|
48
|
+
auto_attr :min_delay, type: Numeric
|
|
49
|
+
|
|
50
|
+
# @!attribute [r] extra
|
|
51
|
+
# @return [Hash, nil] Any additional fields returned by the API
|
|
52
|
+
auto_attr :extra, type: Hash
|
|
53
|
+
|
|
54
|
+
auto_initialize!
|
|
55
|
+
|
|
56
|
+
# Whether timelapses are turned off for the next print
|
|
57
|
+
#
|
|
58
|
+
# @example
|
|
59
|
+
# Octoprint::Timelapse.get.config.off? # => true
|
|
60
|
+
#
|
|
61
|
+
# @return [Boolean]
|
|
62
|
+
#: -> bool
|
|
63
|
+
def off?
|
|
64
|
+
type == "off"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Timelapse
|
|
6
|
+
# Attributes shared by rendered and unrendered timelapses ({Timelapse::Rendered} and
|
|
7
|
+
# {Timelapse::Unrendered}).
|
|
8
|
+
#
|
|
9
|
+
# Including this module declares the following attributes on the including class:
|
|
10
|
+
#
|
|
11
|
+
# - +name+ [String] The name of the timelapse file or job
|
|
12
|
+
# - +size+ [String] The formatted size, e.g. "2.0MB"
|
|
13
|
+
# - +bytes+ [Integer] The size in bytes
|
|
14
|
+
# - +date+ [String] The formatted date, e.g. "2026-11-15 00:52"
|
|
15
|
+
# - +extra+ [Hash, nil] Any additional fields returned by the API
|
|
16
|
+
#
|
|
17
|
+
# The including class declares its own attributes, then calls +auto_initialize!+. It should also
|
|
18
|
+
# include AutoInitializable and Deserializable itself, so Sorbet sees +auto_attr+ on it.
|
|
19
|
+
#
|
|
20
|
+
# @example
|
|
21
|
+
# class Rendered
|
|
22
|
+
# include AutoInitializable
|
|
23
|
+
# include Deserializable
|
|
24
|
+
# include FileAttributes
|
|
25
|
+
#
|
|
26
|
+
# auto_attr :url, type: String
|
|
27
|
+
#
|
|
28
|
+
# auto_initialize!
|
|
29
|
+
# end
|
|
30
|
+
module FileAttributes
|
|
31
|
+
# Declares the shared timelapse attributes on the including class.
|
|
32
|
+
#
|
|
33
|
+
# @param base [Class] The including class
|
|
34
|
+
# @return [void]
|
|
35
|
+
#: (Module base) -> void
|
|
36
|
+
def self.included(base)
|
|
37
|
+
super
|
|
38
|
+
|
|
39
|
+
klass = base #: as untyped
|
|
40
|
+
klass.include AutoInitializable
|
|
41
|
+
klass.include Deserializable
|
|
42
|
+
klass.auto_attr :name, type: String
|
|
43
|
+
klass.auto_attr :size, type: String
|
|
44
|
+
klass.auto_attr :bytes, type: Integer
|
|
45
|
+
klass.auto_attr :date, type: String
|
|
46
|
+
klass.auto_attr :extra, type: Hash
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Timelapse
|
|
6
|
+
# A rendered timelapse file.
|
|
7
|
+
#
|
|
8
|
+
# Has the shared {FileAttributes} (+name+, +size+, +bytes+, +date+, +extra+), plus the
|
|
9
|
+
# download paths and the modification timestamp.
|
|
10
|
+
#
|
|
11
|
+
# @example
|
|
12
|
+
# file = Octoprint::Timelapse.get.files.first
|
|
13
|
+
# file.name # => "benchy_20261115.mp4"
|
|
14
|
+
# file.size # => "2.0MB"
|
|
15
|
+
# file.bytes # => 2097152
|
|
16
|
+
# file.url # => "/downloads/timelapse/benchy_20261115.mp4"
|
|
17
|
+
# file.thumbnail # => "/downloads/timelapse/benchy_20261115.mp4.thumb.jpg"
|
|
18
|
+
#
|
|
19
|
+
# @see https://docs.octoprint.org/en/1.11.2/api/timelapse.html#rendered-timelapse
|
|
20
|
+
class Rendered
|
|
21
|
+
include AutoInitializable
|
|
22
|
+
include Deserializable
|
|
23
|
+
include FileAttributes
|
|
24
|
+
|
|
25
|
+
# @!attribute [r] timestamp
|
|
26
|
+
# @return [Float, nil] The modification date as a Unix timestamp
|
|
27
|
+
auto_attr :timestamp, type: Float
|
|
28
|
+
|
|
29
|
+
# @!attribute [r] url
|
|
30
|
+
# @return [String] The path to download the file
|
|
31
|
+
auto_attr :url, type: String
|
|
32
|
+
|
|
33
|
+
# @!attribute [r] thumbnail
|
|
34
|
+
# @return [String, nil] The path to download the thumbnail, if there is one
|
|
35
|
+
auto_attr :thumbnail, type: String
|
|
36
|
+
|
|
37
|
+
auto_initialize!
|
|
38
|
+
|
|
39
|
+
# The modification date as a Time
|
|
40
|
+
#
|
|
41
|
+
# @example
|
|
42
|
+
# Octoprint::Timelapse.get.files.first.modification_time # => 2026-11-15 00:52:35 -0500
|
|
43
|
+
#
|
|
44
|
+
# @return [Time, nil]
|
|
45
|
+
#: -> Time?
|
|
46
|
+
def modification_time
|
|
47
|
+
Time.at(timestamp) if timestamp
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Timelapse
|
|
6
|
+
# An unrendered timelapse job: the snapshots of a print, not yet rendered to a video.
|
|
7
|
+
#
|
|
8
|
+
# Has the shared {FileAttributes} (+name+, +size+, +bytes+, +date+, +extra+), plus the
|
|
9
|
+
# snapshot count and processing state. +size+, +bytes+ and +date+ cover all the snapshots.
|
|
10
|
+
#
|
|
11
|
+
# @example
|
|
12
|
+
# job = Octoprint::Timelapse.get(unrendered: true).unrendered.first
|
|
13
|
+
# job.name # => "cube_20261115"
|
|
14
|
+
# job.count # => 342
|
|
15
|
+
# job.size # => "12.3MB"
|
|
16
|
+
# job.processing # => false
|
|
17
|
+
#
|
|
18
|
+
# @see https://docs.octoprint.org/en/1.11.2/api/timelapse.html#unrendered-timelapse
|
|
19
|
+
class Unrendered
|
|
20
|
+
include AutoInitializable
|
|
21
|
+
include Deserializable
|
|
22
|
+
include FileAttributes
|
|
23
|
+
|
|
24
|
+
# @!attribute [r] count
|
|
25
|
+
# @return [Integer, nil] The number of snapshots
|
|
26
|
+
auto_attr :count, type: Integer
|
|
27
|
+
|
|
28
|
+
# @!attribute [r] recording
|
|
29
|
+
# @return [Boolean] Whether the job is still recording
|
|
30
|
+
auto_attr :recording, type: Types::Boolean
|
|
31
|
+
|
|
32
|
+
# @!attribute [r] rendering
|
|
33
|
+
# @return [Boolean] Whether the job is being rendered
|
|
34
|
+
auto_attr :rendering, type: Types::Boolean
|
|
35
|
+
|
|
36
|
+
# @!attribute [r] processing
|
|
37
|
+
# @return [Boolean] Whether the job is recording or rendering
|
|
38
|
+
auto_attr :processing, type: Types::Boolean
|
|
39
|
+
|
|
40
|
+
auto_initialize!
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|