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,28 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "sorbet-runtime"
|
|
5
|
+
|
|
6
|
+
module Octoprint
|
|
7
|
+
class Logs
|
|
8
|
+
# References relevant to this log file
|
|
9
|
+
#
|
|
10
|
+
# Contains URLs for accessing the log file through different endpoints,
|
|
11
|
+
# including direct download and API resource access.
|
|
12
|
+
#
|
|
13
|
+
# @example Accessing log file URLs
|
|
14
|
+
# log_file = Octoprint::Logs.list.files.first
|
|
15
|
+
# refs = log_file.refs
|
|
16
|
+
#
|
|
17
|
+
# puts refs.resource # => "http://octoprint.local/plugin/logging/logs/octoprint.log"
|
|
18
|
+
# puts refs.download # => "http://octoprint.local/downloads/logs/octoprint.log"
|
|
19
|
+
class References
|
|
20
|
+
include AutoInitializable
|
|
21
|
+
|
|
22
|
+
auto_attr :resource, type: String
|
|
23
|
+
auto_attr :download, type: String
|
|
24
|
+
|
|
25
|
+
auto_initialize!
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
# Log file management API
|
|
6
|
+
#
|
|
7
|
+
# This class provides methods to manage log files on the OctoPrint server.
|
|
8
|
+
# The logging functionality allows you to retrieve information about available
|
|
9
|
+
# log files and delete them when needed for maintenance or cleanup purposes.
|
|
10
|
+
#
|
|
11
|
+
# Log files contain important debugging and operational information from the
|
|
12
|
+
# OctoPrint server, including printer communication logs, error messages,
|
|
13
|
+
# and system events.
|
|
14
|
+
#
|
|
15
|
+
# @example List all available log files
|
|
16
|
+
# logs = Octoprint::Logs.list
|
|
17
|
+
# puts "Available log files (#{logs.files.length}):"
|
|
18
|
+
# logs.files.each do |log_file|
|
|
19
|
+
# puts "- #{log_file.name}: #{log_file.size} bytes, modified #{log_file.modification_time}"
|
|
20
|
+
# end
|
|
21
|
+
# puts "Free disk space: #{logs.free} bytes" if logs.free
|
|
22
|
+
#
|
|
23
|
+
# @example Access log file details and references
|
|
24
|
+
# logs = Octoprint::Logs.list
|
|
25
|
+
# log_file = logs.files.first
|
|
26
|
+
# puts "Log file: #{log_file.name}"
|
|
27
|
+
# puts "Size: #{log_file.size} bytes"
|
|
28
|
+
# puts "Last modified: #{log_file.modification_time}"
|
|
29
|
+
# if log_file.refs
|
|
30
|
+
# puts "Download URL: #{log_file.refs.download}"
|
|
31
|
+
# puts "Resource URL: #{log_file.refs.resource}"
|
|
32
|
+
# end
|
|
33
|
+
#
|
|
34
|
+
# @example Delete old log files
|
|
35
|
+
# logs = Octoprint::Logs.list
|
|
36
|
+
# old_logs = logs.files.select { |log| log.name.match?(/\.log\.\d+$/) }
|
|
37
|
+
# old_logs.each do |log_file|
|
|
38
|
+
# success = Octoprint::Logs.delete_file(filename: log_file.name)
|
|
39
|
+
# puts success ? "Deleted #{log_file.name}" : "Failed to delete #{log_file.name}"
|
|
40
|
+
# end
|
|
41
|
+
#
|
|
42
|
+
# @example Check disk space and cleanup if needed
|
|
43
|
+
# logs = Octoprint::Logs.list
|
|
44
|
+
# if logs.free && logs.free < 100_000_000 # Less than 100MB free
|
|
45
|
+
# puts "Low disk space detected (#{logs.free} bytes free)"
|
|
46
|
+
# # Delete archived log files to free space
|
|
47
|
+
# archived_logs = logs.files.select { |log| log.name.include?('.gz') }
|
|
48
|
+
# archived_logs.each do |log_file|
|
|
49
|
+
# Octoprint::Logs.delete_file(filename: log_file.name)
|
|
50
|
+
# puts "Deleted archived log: #{log_file.name}"
|
|
51
|
+
# end
|
|
52
|
+
# end
|
|
53
|
+
#
|
|
54
|
+
# OctoPrint's API doc: https://docs.octoprint.org/en/1.11.2/bundledplugins/logging.html
|
|
55
|
+
class Logs < BaseResource
|
|
56
|
+
include Deserializable
|
|
57
|
+
include AutoInitializable
|
|
58
|
+
|
|
59
|
+
resource_path("/plugin/logging/logs")
|
|
60
|
+
|
|
61
|
+
auto_attr :files, type: LogFile, array: true, nilable: false
|
|
62
|
+
auto_attr :free, type: Integer
|
|
63
|
+
|
|
64
|
+
auto_initialize!
|
|
65
|
+
|
|
66
|
+
# Configure deserialization
|
|
67
|
+
deserialize_config do
|
|
68
|
+
array :files, LogFile
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Retrieves a list of available log files
|
|
72
|
+
#
|
|
73
|
+
# @return [Logs] List of log files with metadata
|
|
74
|
+
#
|
|
75
|
+
# @example
|
|
76
|
+
# logs = Octoprint::Logs.list
|
|
77
|
+
# logs.files.each { |file| puts "#{file.name}: #{file.size} bytes" }
|
|
78
|
+
# puts "Free space: #{logs.free} bytes"
|
|
79
|
+
#: -> Logs
|
|
80
|
+
def self.list
|
|
81
|
+
fetch_resource
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Deletes a specific log file
|
|
85
|
+
#
|
|
86
|
+
# @param [String] filename The name of the log file to delete
|
|
87
|
+
# @return [T::Boolean] True if deletion was successful
|
|
88
|
+
#
|
|
89
|
+
# @example
|
|
90
|
+
# result = Octoprint::Logs.delete_file(filename: "octoprint.log.1")
|
|
91
|
+
# puts "Deleted successfully" if result
|
|
92
|
+
#: (filename: String) -> bool
|
|
93
|
+
def self.delete_file(filename:)
|
|
94
|
+
path = [@path, filename].compact.join("/")
|
|
95
|
+
delete(path: path)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Printer
|
|
6
|
+
# Heated bed temperature and commands.
|
|
7
|
+
#
|
|
8
|
+
# Only available if the selected printer profile has a heated bed, otherwise every request
|
|
9
|
+
# raises {Octoprint::Exceptions::ConflictError}. Requires the +CONTROL+ permission for commands
|
|
10
|
+
# and +STATUS+ for {.temperature}.
|
|
11
|
+
#
|
|
12
|
+
# @example Read the bed temperature
|
|
13
|
+
# bed = Octoprint::Printer::Bed.temperature
|
|
14
|
+
# puts "#{bed.actual}°C / #{bed.target}°C"
|
|
15
|
+
#
|
|
16
|
+
# @example Include the last two history readings
|
|
17
|
+
# Octoprint::Printer::Bed.temperature(history: true, limit: 2).history.map(&:actual) # => [50.221, 49.1123]
|
|
18
|
+
#
|
|
19
|
+
# @example Heat the bed to 75°C
|
|
20
|
+
# Octoprint::Printer::Bed.target(75)
|
|
21
|
+
#
|
|
22
|
+
# @example Set a -5°C offset
|
|
23
|
+
# Octoprint::Printer::Bed.offset(-5)
|
|
24
|
+
#
|
|
25
|
+
# @see https://docs.octoprint.org/en/master/api/printer.html#issue-a-bed-command
|
|
26
|
+
class Bed < BaseResource
|
|
27
|
+
include Heater
|
|
28
|
+
|
|
29
|
+
resource_path("/api/printer/bed")
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Printer
|
|
6
|
+
# Heated chamber temperature and commands.
|
|
7
|
+
#
|
|
8
|
+
# Only available if the selected printer profile has a heated chamber, otherwise every request
|
|
9
|
+
# raises {Octoprint::Exceptions::ConflictError}. Requires the +CONTROL+ permission for commands
|
|
10
|
+
# and +STATUS+ for {.temperature}.
|
|
11
|
+
#
|
|
12
|
+
# @example Read the chamber temperature
|
|
13
|
+
# chamber = Octoprint::Printer::Chamber.temperature
|
|
14
|
+
# puts "#{chamber.actual}°C / #{chamber.target}°C"
|
|
15
|
+
#
|
|
16
|
+
# @example Heat the chamber to 50°C
|
|
17
|
+
# Octoprint::Printer::Chamber.target(50)
|
|
18
|
+
#
|
|
19
|
+
# @example Set a -5°C offset
|
|
20
|
+
# Octoprint::Printer::Chamber.offset(-5)
|
|
21
|
+
#
|
|
22
|
+
# @see https://docs.octoprint.org/en/master/api/printer.html#issue-a-chamber-command
|
|
23
|
+
class Chamber < BaseResource
|
|
24
|
+
include Heater
|
|
25
|
+
|
|
26
|
+
resource_path("/api/printer/chamber")
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Printer
|
|
6
|
+
# Sends arbitrary commands or GCODE scripts to the printer and retrieves custom controls.
|
|
7
|
+
#
|
|
8
|
+
# Use with care: some commands can interfere with or even stop a running print job.
|
|
9
|
+
# Requires the +CONTROL+ permission.
|
|
10
|
+
#
|
|
11
|
+
# @example Send a single command
|
|
12
|
+
# Octoprint::Printer::Command.send_command("M106")
|
|
13
|
+
#
|
|
14
|
+
# @example Send multiple commands
|
|
15
|
+
# Octoprint::Printer::Command.send_commands(["M18", "M106 S0"])
|
|
16
|
+
#
|
|
17
|
+
# @example Run a GCODE script template
|
|
18
|
+
# Octoprint::Printer::Command.run_script("afterPrintCancelled")
|
|
19
|
+
#
|
|
20
|
+
# @example List the custom controls
|
|
21
|
+
# Octoprint::Printer::Command.custom_controls.map(&:name) # => ["Fan", "Reporting"]
|
|
22
|
+
#
|
|
23
|
+
# @see https://docs.octoprint.org/en/master/api/printer.html#send-an-arbitrary-command-to-the-printer
|
|
24
|
+
class Command < BaseResource
|
|
25
|
+
resource_path("/api/printer/command")
|
|
26
|
+
|
|
27
|
+
# Sends an arbitrary command request. Exactly one of +command+, +commands+ or +script+ must be given.
|
|
28
|
+
#
|
|
29
|
+
# @param command [String, nil] A single command to send
|
|
30
|
+
# @param commands [Array<String>, nil] Multiple commands to send, in order
|
|
31
|
+
# @param script [String, nil] The name of a GCODE script template to send
|
|
32
|
+
# @param parameters [Hash, nil] Parameters to replace in the commands or to provide to the script renderer
|
|
33
|
+
# @param context [Hash, nil] Additional template variables for the script renderer (only with +script+)
|
|
34
|
+
#
|
|
35
|
+
# @example
|
|
36
|
+
# Octoprint::Printer::Command.issue(commands: ["G91", "G1 X%(distance)s", "G90"],
|
|
37
|
+
# parameters: { distance: 10 })
|
|
38
|
+
#
|
|
39
|
+
# @return [Boolean] true on success (204 No Content)
|
|
40
|
+
# @raise [ArgumentError] if not exactly one of +command+, +commands+ or +script+ is given,
|
|
41
|
+
# or if +context+ is given without +script+
|
|
42
|
+
#: (
|
|
43
|
+
#| ?command: String?,
|
|
44
|
+
#| ?commands: Array[String]?,
|
|
45
|
+
#| ?script: String?,
|
|
46
|
+
#| ?parameters: Hash[(Symbol | String), untyped]?,
|
|
47
|
+
#| ?context: Hash[(Symbol | String), untyped]?
|
|
48
|
+
#| ) -> untyped
|
|
49
|
+
def self.issue(command: nil, commands: nil, script: nil, parameters: nil, context: nil)
|
|
50
|
+
unless [command, commands, script].compact.size == 1
|
|
51
|
+
raise ArgumentError, "Exactly one of command, commands or script must be provided"
|
|
52
|
+
end
|
|
53
|
+
raise ArgumentError, "context can only be used with script" if context && script.nil?
|
|
54
|
+
|
|
55
|
+
post(params: { command: command, commands: commands, script: script, parameters: parameters,
|
|
56
|
+
context: context }.compact)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Sends a single command to the printer.
|
|
60
|
+
#
|
|
61
|
+
# @param command [String] The command to send
|
|
62
|
+
# @param parameters [Hash, nil] Parameters to replace in the command
|
|
63
|
+
#
|
|
64
|
+
# @example
|
|
65
|
+
# Octoprint::Printer::Command.send_command("M106")
|
|
66
|
+
#
|
|
67
|
+
# @example With parameters
|
|
68
|
+
# Octoprint::Printer::Command.send_command("M106 S%(speed)s", parameters: { speed: 255 })
|
|
69
|
+
#
|
|
70
|
+
# @return [Boolean] true on success (204 No Content)
|
|
71
|
+
#: (String command, ?parameters: Hash[(Symbol | String), untyped]?) -> untyped
|
|
72
|
+
def self.send_command(command, parameters: nil)
|
|
73
|
+
issue(command: command, parameters: parameters)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Sends multiple commands to the printer, in the given order.
|
|
77
|
+
#
|
|
78
|
+
# @param commands [Array<String>] The commands to send
|
|
79
|
+
# @param parameters [Hash, nil] Parameters to replace in the commands
|
|
80
|
+
#
|
|
81
|
+
# @example
|
|
82
|
+
# Octoprint::Printer::Command.send_commands(["M18", "M106 S0"])
|
|
83
|
+
#
|
|
84
|
+
# @return [Boolean] true on success (204 No Content)
|
|
85
|
+
#: (
|
|
86
|
+
#| Array[String] commands,
|
|
87
|
+
#| ?parameters: Hash[(Symbol | String), untyped]?
|
|
88
|
+
#| ) -> untyped
|
|
89
|
+
def self.send_commands(commands, parameters: nil)
|
|
90
|
+
issue(commands: commands, parameters: parameters)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Renders a GCODE script template and sends it to the printer.
|
|
94
|
+
#
|
|
95
|
+
# @param script [String] The name of the GCODE script template
|
|
96
|
+
# @param parameters [Hash, nil] Parameters to provide to the script renderer
|
|
97
|
+
# @param context [Hash, nil] Additional template variables to provide to the script renderer
|
|
98
|
+
#
|
|
99
|
+
# @example
|
|
100
|
+
# Octoprint::Printer::Command.run_script("afterPrintCancelled")
|
|
101
|
+
#
|
|
102
|
+
# @return [Boolean] true on success (204 No Content)
|
|
103
|
+
#: (
|
|
104
|
+
#| String script,
|
|
105
|
+
#| ?parameters: Hash[(Symbol | String), untyped]?,
|
|
106
|
+
#| ?context: Hash[(Symbol | String), untyped]?
|
|
107
|
+
#| ) -> untyped
|
|
108
|
+
def self.run_script(script, parameters: nil, context: nil)
|
|
109
|
+
issue(script: script, parameters: parameters, context: context)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Retrieves the custom controls configured in OctoPrint's +config.yaml+.
|
|
113
|
+
#
|
|
114
|
+
# @example
|
|
115
|
+
# Octoprint::Printer::Command.custom_controls.each do |control|
|
|
116
|
+
# puts control.name
|
|
117
|
+
# control.children&.each { |child| puts " #{child.name}: #{child.command}" }
|
|
118
|
+
# end
|
|
119
|
+
#
|
|
120
|
+
# @return [Array<Printer::CustomControl>] The custom controls
|
|
121
|
+
# @see https://docs.octoprint.org/en/master/features/custom_controls.html Custom controls
|
|
122
|
+
#: -> Array[CustomControl]
|
|
123
|
+
def self.custom_controls
|
|
124
|
+
response = fetch_resource("custom", deserialize: false)
|
|
125
|
+
Array(response[:controls]).map { |control| CustomControl.deserialize(control) }
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Printer
|
|
6
|
+
class CustomControl
|
|
7
|
+
# An input parameter of a custom control.
|
|
8
|
+
#
|
|
9
|
+
# @example
|
|
10
|
+
# input = Octoprint::Printer::Command.custom_controls.first.children.first.input.first
|
|
11
|
+
# input.name # => "Speed (0-255)"
|
|
12
|
+
# input.parameter # => "speed"
|
|
13
|
+
# input.default # => 255
|
|
14
|
+
# input.slider # => { min: 0, max: 255 }
|
|
15
|
+
#
|
|
16
|
+
# @see https://docs.octoprint.org/en/master/features/custom_controls.html
|
|
17
|
+
class Input
|
|
18
|
+
include AutoInitializable
|
|
19
|
+
include Deserializable
|
|
20
|
+
|
|
21
|
+
# @!attribute [r] name
|
|
22
|
+
# @return [String, nil] Name to display for the input field
|
|
23
|
+
auto_attr :name, type: String
|
|
24
|
+
|
|
25
|
+
# @!attribute [r] parameter
|
|
26
|
+
# @return [String, nil] Placeholder name used in the control's command(s)
|
|
27
|
+
auto_attr :parameter, type: String
|
|
28
|
+
|
|
29
|
+
# @!attribute [r] default
|
|
30
|
+
# @return [Object, nil] Default value of the input field
|
|
31
|
+
auto_attr :default, type: T.untyped
|
|
32
|
+
|
|
33
|
+
# @!attribute [r] slider
|
|
34
|
+
# @return [Hash, nil] Slider settings (+min+, +max+, +step+) when rendered as a slider
|
|
35
|
+
auto_attr :slider, type: Hash
|
|
36
|
+
|
|
37
|
+
# @!attribute [r] extra
|
|
38
|
+
# @return [Hash, nil] Any additional fields returned by the API
|
|
39
|
+
auto_attr :extra, type: Hash
|
|
40
|
+
|
|
41
|
+
auto_initialize!
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Printer
|
|
6
|
+
# A custom control as configured in OctoPrint's +config.yaml+.
|
|
7
|
+
#
|
|
8
|
+
# There are two kinds of custom controls: containers, which group other controls in +children+,
|
|
9
|
+
# and controls, which send a +command+, +commands+ or +script+ to the printer and/or display
|
|
10
|
+
# output matched by +regex+ and rendered with +template+.
|
|
11
|
+
#
|
|
12
|
+
# @example
|
|
13
|
+
# fan = Octoprint::Printer::Command.custom_controls.first
|
|
14
|
+
# fan.container? # => true
|
|
15
|
+
# fan.children.first.command # => "M106 S%(speed)s"
|
|
16
|
+
# fan.children.first.input.first # => #<Octoprint::Printer::CustomControl::Input ...>
|
|
17
|
+
#
|
|
18
|
+
# @see https://docs.octoprint.org/en/master/features/custom_controls.html
|
|
19
|
+
class CustomControl
|
|
20
|
+
include AutoInitializable
|
|
21
|
+
include Deserializable
|
|
22
|
+
|
|
23
|
+
# @!attribute [r] name
|
|
24
|
+
# @return [String, nil] The name of the control or container
|
|
25
|
+
auto_attr :name, type: String
|
|
26
|
+
|
|
27
|
+
# @!attribute [r] type
|
|
28
|
+
# @return [String, nil] The control type, if set in the configuration
|
|
29
|
+
auto_attr :type, type: String
|
|
30
|
+
|
|
31
|
+
# @!attribute [r] children
|
|
32
|
+
# @return [Array<Printer::CustomControl>, nil] The controls contained in a container
|
|
33
|
+
auto_attr :children, type: CustomControl, array: true
|
|
34
|
+
|
|
35
|
+
# @!attribute [r] layout
|
|
36
|
+
# @return [String, nil] The container's layout: +vertical+, +horizontal+ or +horizontal_grid+
|
|
37
|
+
auto_attr :layout, type: String
|
|
38
|
+
|
|
39
|
+
# @!attribute [r] collapsed
|
|
40
|
+
# @return [Boolean, nil] Whether the container is collapsed by default
|
|
41
|
+
auto_attr :collapsed, type: Types::Boolean
|
|
42
|
+
|
|
43
|
+
# @!attribute [r] width
|
|
44
|
+
# @return [String, Integer, nil] The control's width in a grid layout
|
|
45
|
+
auto_attr :width, type: T.untyped
|
|
46
|
+
|
|
47
|
+
# @!attribute [r] offset
|
|
48
|
+
# @return [String, Integer, nil] The control's offset in a grid layout
|
|
49
|
+
auto_attr :offset, type: T.untyped
|
|
50
|
+
|
|
51
|
+
# @!attribute [r] command
|
|
52
|
+
# @return [String, nil] A single GCODE command sent by the control
|
|
53
|
+
auto_attr :command, type: String
|
|
54
|
+
|
|
55
|
+
# @!attribute [r] commands
|
|
56
|
+
# @return [Array<String>, nil] GCODE commands sent by the control
|
|
57
|
+
auto_attr :commands, type: String, array: true
|
|
58
|
+
|
|
59
|
+
# @!attribute [r] script
|
|
60
|
+
# @return [String, nil] The name of a GCODE script sent by the control
|
|
61
|
+
auto_attr :script, type: String
|
|
62
|
+
|
|
63
|
+
# @!attribute [r] javascript
|
|
64
|
+
# @return [String, nil] A JavaScript snippet executed when the control is clicked
|
|
65
|
+
auto_attr :javascript, type: String
|
|
66
|
+
|
|
67
|
+
# @!attribute [r] additional_classes
|
|
68
|
+
# @return [String, nil] Additional CSS classes applied to the control's button
|
|
69
|
+
auto_attr :additional_classes, type: String
|
|
70
|
+
|
|
71
|
+
# @!attribute [r] enabled
|
|
72
|
+
# @return [String, nil] A JavaScript snippet determining whether the control is enabled
|
|
73
|
+
auto_attr :enabled, type: String
|
|
74
|
+
|
|
75
|
+
# @!attribute [r] input
|
|
76
|
+
# @return [Array<Printer::CustomControl::Input>, nil] Input parameters of the control
|
|
77
|
+
auto_attr :input, type: Input, array: true
|
|
78
|
+
|
|
79
|
+
# @!attribute [r] regex
|
|
80
|
+
# @return [String, nil] A regular expression matched against lines received from the printer
|
|
81
|
+
auto_attr :regex, type: String
|
|
82
|
+
|
|
83
|
+
# @!attribute [r] template
|
|
84
|
+
# @return [String, nil] A template used to render the +regex+ match
|
|
85
|
+
auto_attr :template, type: String
|
|
86
|
+
|
|
87
|
+
# @!attribute [r] key
|
|
88
|
+
# @return [String, nil] Identifier generated by OctoPrint for controls using +regex+
|
|
89
|
+
auto_attr :key, type: String
|
|
90
|
+
|
|
91
|
+
# @!attribute [r] template_key
|
|
92
|
+
# @return [String, nil] Identifier generated by OctoPrint for the control's +template+
|
|
93
|
+
auto_attr :template_key, type: String
|
|
94
|
+
|
|
95
|
+
# @!attribute [r] confirm
|
|
96
|
+
# @return [String, nil] A confirmation text displayed before sending the control's commands
|
|
97
|
+
auto_attr :confirm, type: String
|
|
98
|
+
|
|
99
|
+
# @!attribute [r] extra
|
|
100
|
+
# @return [Hash, nil] Any additional fields returned by the API
|
|
101
|
+
auto_attr :extra, type: Hash
|
|
102
|
+
|
|
103
|
+
auto_initialize!
|
|
104
|
+
|
|
105
|
+
deserialize_config do
|
|
106
|
+
array :children, CustomControl
|
|
107
|
+
array :input, Input
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Whether this is a container grouping other controls.
|
|
111
|
+
#
|
|
112
|
+
# @return [Boolean] true if the control has children
|
|
113
|
+
#: -> bool
|
|
114
|
+
def container?
|
|
115
|
+
!children.nil?
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Printer
|
|
6
|
+
# Information about the last error reported by the printer.
|
|
7
|
+
#
|
|
8
|
+
# Requires the +STATUS+ permission. The {#logs} are only included when the user
|
|
9
|
+
# also has the +MONITOR_TERMINAL+ permission.
|
|
10
|
+
#
|
|
11
|
+
# When no error has occurred, the server still returns +error+ and +reason+, as
|
|
12
|
+
# empty strings, and leaves out +consequence+, +faq+ and +logs+. Use {#error?} to
|
|
13
|
+
# check whether there is an error.
|
|
14
|
+
#
|
|
15
|
+
# @example Check for an error
|
|
16
|
+
# info = Octoprint::Printer::ErrorInformation.get
|
|
17
|
+
# info.error? # => false
|
|
18
|
+
# info.error # => ""
|
|
19
|
+
#
|
|
20
|
+
# @example Inspect the last firmware error
|
|
21
|
+
# info = Octoprint::Printer.last_error
|
|
22
|
+
# info.error # => "MINTEMP triggered!"
|
|
23
|
+
# info.reason # => "firmware"
|
|
24
|
+
# info.consequence # => "emergency"
|
|
25
|
+
# info.faq_url # => "https://faq.octoprint.org/firmware-mintemp"
|
|
26
|
+
# info.logs # => ["Recv: Error:MINTEMP triggered!", ...]
|
|
27
|
+
#
|
|
28
|
+
# @see https://docs.octoprint.org/en/1.11.8/api/printer.html#retrieve-information-about-the-last-error
|
|
29
|
+
class ErrorInformation < BaseResource
|
|
30
|
+
include AutoInitializable
|
|
31
|
+
include Deserializable
|
|
32
|
+
|
|
33
|
+
resource_path("/api/printer/error")
|
|
34
|
+
|
|
35
|
+
# Base URL of OctoPrint's FAQ, completed with {#faq} to build {#faq_url}.
|
|
36
|
+
FAQ_BASE_URL = "https://faq.octoprint.org/"
|
|
37
|
+
|
|
38
|
+
# @!attribute [r] error
|
|
39
|
+
# @return [String, nil] The error message, empty when there is no error
|
|
40
|
+
auto_attr :error, type: String
|
|
41
|
+
|
|
42
|
+
# @!attribute [r] reason
|
|
43
|
+
# @return [String, nil] The reason for the error, for example +firmware+. Empty when there is no error
|
|
44
|
+
auto_attr :reason, type: String
|
|
45
|
+
|
|
46
|
+
# @!attribute [r] consequence
|
|
47
|
+
# @return [String, nil] What the error triggered: +emergency+, +disconnect+ or +cancel+.
|
|
48
|
+
# nil when nothing was triggered or there is no error
|
|
49
|
+
auto_attr :consequence, type: String
|
|
50
|
+
|
|
51
|
+
# @!attribute [r] faq
|
|
52
|
+
# @return [String, nil] The id of the matching FAQ entry, nil when there is none or no error.
|
|
53
|
+
# See {#faq_url}
|
|
54
|
+
auto_attr :faq, type: String
|
|
55
|
+
|
|
56
|
+
# @!attribute [r] logs
|
|
57
|
+
# @return [Array<String>, nil] Terminal lines related to the error. nil when there is no error
|
|
58
|
+
# or the user lacks the +MONITOR_TERMINAL+ permission
|
|
59
|
+
auto_attr :logs, type: String, array: true
|
|
60
|
+
|
|
61
|
+
# @!attribute [r] extra
|
|
62
|
+
# @return [Hash, nil] Any additional fields returned by the API
|
|
63
|
+
auto_attr :extra, type: Hash
|
|
64
|
+
|
|
65
|
+
auto_initialize!
|
|
66
|
+
|
|
67
|
+
# Retrieves information about the last error reported by the printer.
|
|
68
|
+
#
|
|
69
|
+
# @example
|
|
70
|
+
# Octoprint::Printer::ErrorInformation.get.error # => "MINTEMP triggered!"
|
|
71
|
+
#
|
|
72
|
+
# @return [Printer::ErrorInformation] The last error information
|
|
73
|
+
# @raise [Octoprint::Exceptions::AuthenticationError] if the user lacks the +STATUS+ permission
|
|
74
|
+
#: -> ErrorInformation
|
|
75
|
+
def self.get
|
|
76
|
+
fetch_resource
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Whether the server reported an error.
|
|
80
|
+
#
|
|
81
|
+
# @example
|
|
82
|
+
# Octoprint::Printer.last_error.error? # => false
|
|
83
|
+
#
|
|
84
|
+
# @return [Boolean] false when {#error} is nil or empty
|
|
85
|
+
#: -> bool
|
|
86
|
+
def error?
|
|
87
|
+
!error.to_s.empty?
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# The link to the FAQ entry for this error.
|
|
91
|
+
#
|
|
92
|
+
# @example
|
|
93
|
+
# Octoprint::Printer.last_error.faq_url # => "https://faq.octoprint.org/firmware-mintemp"
|
|
94
|
+
#
|
|
95
|
+
# @return [String, nil] The FAQ URL, nil when there is no FAQ entry
|
|
96
|
+
#: -> String?
|
|
97
|
+
def faq_url
|
|
98
|
+
return if faq.to_s.empty?
|
|
99
|
+
|
|
100
|
+
"#{FAQ_BASE_URL}#{faq}"
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|