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,113 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Printer
|
|
6
|
+
# Behaviour of the single heater resources ({Printer::Bed} and {Printer::Chamber}): reading the
|
|
7
|
+
# heater's temperature and setting its target and offset.
|
|
8
|
+
#
|
|
9
|
+
# Including this module also includes {Printer::TemperatureAttributes}, so the including class gets the
|
|
10
|
+
# +actual+, +target+, +offset+, +history+ and +extra+ attributes.
|
|
11
|
+
#
|
|
12
|
+
# @example
|
|
13
|
+
# class Bed < BaseResource
|
|
14
|
+
# include Heater
|
|
15
|
+
#
|
|
16
|
+
# resource_path("/api/printer/bed")
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
# Bed.temperature.actual # => 50.221
|
|
20
|
+
# Bed.target(75)
|
|
21
|
+
module Heater
|
|
22
|
+
extend T::Helpers
|
|
23
|
+
|
|
24
|
+
# Class methods added to the including resource.
|
|
25
|
+
module ClassMethods
|
|
26
|
+
extend T::Generic
|
|
27
|
+
include HistoryQuery
|
|
28
|
+
|
|
29
|
+
has_attached_class!(:out)
|
|
30
|
+
|
|
31
|
+
# Retrieves the heater's current temperature.
|
|
32
|
+
#
|
|
33
|
+
# @param history [Boolean] Whether to include the temperature history
|
|
34
|
+
# @param limit [Integer, nil] Only return the last +limit+ history data points (ignored unless +history+
|
|
35
|
+
# is true)
|
|
36
|
+
#
|
|
37
|
+
# @return [Object] The heater, e.g. a {Printer::Bed}, with its temperature
|
|
38
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational or the heater isn't
|
|
39
|
+
# configured
|
|
40
|
+
#: (?history: bool, ?limit: Integer?) -> instance
|
|
41
|
+
def temperature(history: false, limit: nil)
|
|
42
|
+
response = T.unsafe(self).fetch_resource(deserialize: false,
|
|
43
|
+
options: history_query(history: history, limit: limit))
|
|
44
|
+
|
|
45
|
+
T.unsafe(self).from_response(response, heater_key)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Issues a heater command.
|
|
49
|
+
#
|
|
50
|
+
# @param command [String] The command to issue: +target+ or +offset+
|
|
51
|
+
# @param options [Hash] Additional command parameters
|
|
52
|
+
#
|
|
53
|
+
# @return [Boolean] true on success (204 No Content)
|
|
54
|
+
# @raise [Octoprint::Exceptions::BadRequestError] if the parameters are invalid
|
|
55
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational or the heater isn't
|
|
56
|
+
# configured
|
|
57
|
+
#: (command: String, ?options: Hash[Symbol, untyped]) -> untyped
|
|
58
|
+
def issue_command(command:, options: {})
|
|
59
|
+
T.unsafe(self).post(params: { command: command }.merge(options))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Sets the heater's target temperature. A target of 0 turns the heater off.
|
|
63
|
+
#
|
|
64
|
+
# @param temperature [Numeric] The target temperature
|
|
65
|
+
#
|
|
66
|
+
# @return [Boolean] true on success (204 No Content)
|
|
67
|
+
# @raise [Octoprint::Exceptions::BadRequestError] if the temperature is invalid
|
|
68
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational or the heater isn't
|
|
69
|
+
# configured
|
|
70
|
+
#: (Numeric temperature) -> untyped
|
|
71
|
+
def target(temperature)
|
|
72
|
+
issue_command(command: "target", options: { target: temperature })
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Sets the heater's temperature offset.
|
|
76
|
+
#
|
|
77
|
+
# @param offset [Numeric] The temperature offset
|
|
78
|
+
#
|
|
79
|
+
# @return [Boolean] true on success (204 No Content)
|
|
80
|
+
# @raise [Octoprint::Exceptions::BadRequestError] if the offset is invalid
|
|
81
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational or the heater isn't
|
|
82
|
+
# configured
|
|
83
|
+
#: (Numeric offset) -> untyped
|
|
84
|
+
def offset(offset)
|
|
85
|
+
issue_command(command: "offset", options: { offset: offset })
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
private
|
|
89
|
+
|
|
90
|
+
# The heater's key in the API responses, derived from the class name (+:bed+, +:chamber+).
|
|
91
|
+
#
|
|
92
|
+
# @return [Symbol] The heater's key
|
|
93
|
+
#: -> Symbol
|
|
94
|
+
def heater_key
|
|
95
|
+
T.must(T.unsafe(self).name).demodulize.underscore.to_sym
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
mixes_in_class_methods(ClassMethods)
|
|
100
|
+
|
|
101
|
+
# Adds the temperature attributes to the including resource.
|
|
102
|
+
#
|
|
103
|
+
# @param base [Class] The including resource
|
|
104
|
+
# @return [void]
|
|
105
|
+
#: (Module base) -> void
|
|
106
|
+
def self.included(base)
|
|
107
|
+
super
|
|
108
|
+
|
|
109
|
+
T.unsafe(base).include TemperatureAttributes
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Printer
|
|
6
|
+
# Builds the +history+ and +limit+ query parameters shared by the temperature endpoints.
|
|
7
|
+
#
|
|
8
|
+
# @api private
|
|
9
|
+
module HistoryQuery
|
|
10
|
+
private
|
|
11
|
+
|
|
12
|
+
# @param history [Boolean] Whether to include the temperature history
|
|
13
|
+
# @param limit [Integer, nil] Maximum number of history data points, only sent when +history+ is true
|
|
14
|
+
# @return [Hash] The query parameters
|
|
15
|
+
#: (history: bool, limit: Integer?) -> Hash[Symbol, untyped]
|
|
16
|
+
def history_query(history:, limit:)
|
|
17
|
+
return {} unless history
|
|
18
|
+
|
|
19
|
+
options = { history: true }
|
|
20
|
+
options[:limit] = limit if limit
|
|
21
|
+
options
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Printer
|
|
6
|
+
# Print head commands: jogging, homing and changing the feed rate.
|
|
7
|
+
#
|
|
8
|
+
# All commands except {.feedrate} may only be sent while the printer is operational and not printing.
|
|
9
|
+
# Requires the +CONTROL+ permission.
|
|
10
|
+
#
|
|
11
|
+
# @example Jog the print head
|
|
12
|
+
# Octoprint::Printer::Printhead.jog(x: 10, y: -5, z: 0.02)
|
|
13
|
+
#
|
|
14
|
+
# @example Home the X and Y axes
|
|
15
|
+
# Octoprint::Printer::Printhead.home(axes: %w[x y])
|
|
16
|
+
#
|
|
17
|
+
# @example Set the feed rate to 105%
|
|
18
|
+
# Octoprint::Printer::Printhead.feedrate(105)
|
|
19
|
+
#
|
|
20
|
+
# @see https://docs.octoprint.org/en/master/api/printer.html#issue-a-print-head-command
|
|
21
|
+
class Printhead < BaseResource
|
|
22
|
+
resource_path("/api/printer/printhead")
|
|
23
|
+
|
|
24
|
+
# Issues a print head command.
|
|
25
|
+
#
|
|
26
|
+
# @param command [String] The command to issue: +jog+, +home+ or +feedrate+
|
|
27
|
+
# @param options [Hash] Additional command parameters
|
|
28
|
+
#
|
|
29
|
+
# @example
|
|
30
|
+
# Octoprint::Printer::Printhead.issue_command(command: "home", options: { axes: ["z"] })
|
|
31
|
+
#
|
|
32
|
+
# @return [Boolean] true on success (204 No Content)
|
|
33
|
+
# @raise [Octoprint::Exceptions::BadRequestError] if the parameters are invalid
|
|
34
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational or is printing
|
|
35
|
+
#: (command: String, ?options: Hash[Symbol, untyped]) -> untyped
|
|
36
|
+
def self.issue_command(command:, options: {})
|
|
37
|
+
post(params: { command: command }.merge(options))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Jogs the print head by a relative amount, or to an absolute position, on one or more axes.
|
|
41
|
+
#
|
|
42
|
+
# @param x [Numeric, nil] Distance (or coordinate when +absolute+) to travel on the X axis, in mm
|
|
43
|
+
# @param y [Numeric, nil] Distance (or coordinate when +absolute+) to travel on the Y axis, in mm
|
|
44
|
+
# @param z [Numeric, nil] Distance (or coordinate when +absolute+) to travel on the Z axis, in mm
|
|
45
|
+
# @param absolute [Boolean, nil] Move to absolute coordinates instead of relative amounts
|
|
46
|
+
# @param speed [Integer, false, nil] Speed in mm/min. Defaults to the profile's minimum axis speed;
|
|
47
|
+
# +false+ sends no speed at all
|
|
48
|
+
#
|
|
49
|
+
# @example Relative jog
|
|
50
|
+
# Octoprint::Printer::Printhead.jog(x: 10, y: -5, z: 0.02)
|
|
51
|
+
#
|
|
52
|
+
# @example Absolute move at a given speed
|
|
53
|
+
# Octoprint::Printer::Printhead.jog(x: 100, y: 100, absolute: true, speed: 3000)
|
|
54
|
+
#
|
|
55
|
+
# @return [Boolean] true on success (204 No Content)
|
|
56
|
+
# @raise [Octoprint::Exceptions::BadRequestError] if an amount is invalid
|
|
57
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational or is printing
|
|
58
|
+
#: (
|
|
59
|
+
#| ?x: Numeric?,
|
|
60
|
+
#| ?y: Numeric?,
|
|
61
|
+
#| ?z: Numeric?,
|
|
62
|
+
#| ?absolute: bool?,
|
|
63
|
+
#| ?speed: (Integer | FalseClass)?
|
|
64
|
+
#| ) -> untyped
|
|
65
|
+
def self.jog(x: nil, y: nil, z: nil, absolute: nil, speed: nil) # rubocop:disable Naming/MethodParameterName
|
|
66
|
+
issue_command(command: "jog", options: { x: x, y: y, z: z, absolute: absolute, speed: speed }.compact)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Homes the print head on the given axes.
|
|
70
|
+
#
|
|
71
|
+
# @param axes [Array<String, Symbol>] The axes to home, one or more of +x+, +y+ and +z+. Defaults to all three.
|
|
72
|
+
#
|
|
73
|
+
# @example Home all axes
|
|
74
|
+
# Octoprint::Printer::Printhead.home
|
|
75
|
+
#
|
|
76
|
+
# @example Home X and Y only
|
|
77
|
+
# Octoprint::Printer::Printhead.home(axes: %w[x y])
|
|
78
|
+
#
|
|
79
|
+
# @return [Boolean] true on success (204 No Content)
|
|
80
|
+
# @raise [Octoprint::Exceptions::BadRequestError] if an invalid axis is given
|
|
81
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the printer is not operational or is printing
|
|
82
|
+
#: (?axes: Array[(String | Symbol)]) -> untyped
|
|
83
|
+
def self.home(axes: %w[x y z])
|
|
84
|
+
issue_command(command: "home", options: { axes: axes.map(&:to_s) })
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Changes the feed rate factor applied to the movements of the axes.
|
|
88
|
+
#
|
|
89
|
+
# @param factor [Numeric] Percentage between 50 and 200 as an integer (+50+..+200+) or float (+0.5+..+2.0+)
|
|
90
|
+
#
|
|
91
|
+
# @example Using a percentage
|
|
92
|
+
# Octoprint::Printer::Printhead.feedrate(105)
|
|
93
|
+
#
|
|
94
|
+
# @example Using a float
|
|
95
|
+
# Octoprint::Printer::Printhead.feedrate(1.05)
|
|
96
|
+
#
|
|
97
|
+
# @return [Boolean] true on success (204 No Content)
|
|
98
|
+
# @raise [Octoprint::Exceptions::BadRequestError] if the factor is out of range
|
|
99
|
+
#: (Numeric factor) -> untyped
|
|
100
|
+
def self.feedrate(factor)
|
|
101
|
+
issue_command(command: "feedrate", options: { factor: factor })
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Printer
|
|
6
|
+
# The printer's SD card: state and commands.
|
|
7
|
+
#
|
|
8
|
+
# Requires the +CONTROL+ permission for commands and +STATUS+ for {.get}.
|
|
9
|
+
#
|
|
10
|
+
# @example Check whether the SD card is ready
|
|
11
|
+
# Octoprint::Printer::Sd.get.ready # => true
|
|
12
|
+
#
|
|
13
|
+
# @example Initialize, refresh and release the SD card
|
|
14
|
+
# Octoprint::Printer::Sd.init
|
|
15
|
+
# Octoprint::Printer::Sd.refresh
|
|
16
|
+
# Octoprint::Printer::Sd.release
|
|
17
|
+
#
|
|
18
|
+
# @see https://docs.octoprint.org/en/master/api/printer.html#issue-an-sd-command
|
|
19
|
+
class Sd < BaseResource
|
|
20
|
+
include AutoInitializable
|
|
21
|
+
include Deserializable
|
|
22
|
+
|
|
23
|
+
resource_path("/api/printer/sd")
|
|
24
|
+
|
|
25
|
+
# @!attribute [r] ready
|
|
26
|
+
# @return [Boolean] Whether the SD card has been initialized
|
|
27
|
+
auto_attr :ready, type: Types::Boolean
|
|
28
|
+
|
|
29
|
+
# @!attribute [r] extra
|
|
30
|
+
# @return [Hash, nil] Any additional fields returned by the API
|
|
31
|
+
auto_attr :extra, type: Hash
|
|
32
|
+
|
|
33
|
+
auto_initialize!
|
|
34
|
+
|
|
35
|
+
# Retrieves the current state of the printer's SD card.
|
|
36
|
+
#
|
|
37
|
+
# @example
|
|
38
|
+
# Octoprint::Printer::Sd.get.ready # => true
|
|
39
|
+
#
|
|
40
|
+
# @return [Printer::Sd] The SD card state
|
|
41
|
+
# @raise [Octoprint::Exceptions::NotFoundError] if SD support is disabled in OctoPrint's settings
|
|
42
|
+
#: -> Sd
|
|
43
|
+
def self.get
|
|
44
|
+
fetch_resource
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Issues an SD command.
|
|
48
|
+
#
|
|
49
|
+
# @param command [String] The command to issue: +init+, +refresh+ or +release+
|
|
50
|
+
#
|
|
51
|
+
# @example
|
|
52
|
+
# Octoprint::Printer::Sd.issue_command(command: "refresh")
|
|
53
|
+
#
|
|
54
|
+
# @return [Boolean] true on success (204 No Content)
|
|
55
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the card isn't initialized (+refresh+ and +release+)
|
|
56
|
+
#: (command: String) -> untyped
|
|
57
|
+
def self.issue_command(command:)
|
|
58
|
+
post(params: { command: command })
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Initializes the printer's SD card and retrieves its file list.
|
|
62
|
+
#
|
|
63
|
+
# @example
|
|
64
|
+
# Octoprint::Printer::Sd.init
|
|
65
|
+
#
|
|
66
|
+
# @return [Boolean] true on success (204 No Content)
|
|
67
|
+
#: -> untyped
|
|
68
|
+
def self.init
|
|
69
|
+
issue_command(command: "init")
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Refreshes the list of files stored on the printer's SD card.
|
|
73
|
+
#
|
|
74
|
+
# @example
|
|
75
|
+
# Octoprint::Printer::Sd.refresh
|
|
76
|
+
#
|
|
77
|
+
# @return [Boolean] true on success (204 No Content)
|
|
78
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the card hasn't been initialized
|
|
79
|
+
#: -> untyped
|
|
80
|
+
def self.refresh
|
|
81
|
+
issue_command(command: "refresh")
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Releases the SD card from the printer. The reverse operation of {.init}.
|
|
85
|
+
#
|
|
86
|
+
# @example
|
|
87
|
+
# Octoprint::Printer::Sd.release
|
|
88
|
+
#
|
|
89
|
+
# @return [Boolean] true on success (204 No Content)
|
|
90
|
+
# @raise [Octoprint::Exceptions::ConflictError] if the card hasn't been initialized
|
|
91
|
+
#: -> untyped
|
|
92
|
+
def self.release
|
|
93
|
+
issue_command(command: "release")
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Printer
|
|
6
|
+
# The printer's general state.
|
|
7
|
+
#
|
|
8
|
+
# @example
|
|
9
|
+
# state = Octoprint::Printer.get.state
|
|
10
|
+
# state.text # => "Operational"
|
|
11
|
+
# state.flags.ready # => true
|
|
12
|
+
#
|
|
13
|
+
# @see https://docs.octoprint.org/en/master/api/datamodel.html#printer-state
|
|
14
|
+
class State
|
|
15
|
+
include AutoInitializable
|
|
16
|
+
include Deserializable
|
|
17
|
+
|
|
18
|
+
# @!attribute [r] text
|
|
19
|
+
# @return [String] A textual representation of the current state, e.g. "Operational" or "Printing"
|
|
20
|
+
auto_attr :text, type: String
|
|
21
|
+
|
|
22
|
+
# @!attribute [r] flags
|
|
23
|
+
# @return [Printer::StateFlags] Boolean printer state flags
|
|
24
|
+
auto_attr :flags, type: StateFlags
|
|
25
|
+
|
|
26
|
+
# @!attribute [r] error
|
|
27
|
+
# @return [String, nil] The current error message, if any
|
|
28
|
+
auto_attr :error, type: String
|
|
29
|
+
|
|
30
|
+
# @!attribute [r] extra
|
|
31
|
+
# @return [Hash, nil] Any additional fields returned by the API
|
|
32
|
+
auto_attr :extra, type: Hash
|
|
33
|
+
|
|
34
|
+
auto_initialize!
|
|
35
|
+
|
|
36
|
+
deserialize_config do
|
|
37
|
+
nested :flags, StateFlags
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Printer
|
|
6
|
+
# Boolean flags describing the printer's state.
|
|
7
|
+
#
|
|
8
|
+
# @example
|
|
9
|
+
# flags = Octoprint::Printer.get.state.flags
|
|
10
|
+
# flags.operational # => true
|
|
11
|
+
# flags.printing # => false
|
|
12
|
+
# flags.closed_or_error # => false
|
|
13
|
+
#
|
|
14
|
+
# @see https://docs.octoprint.org/en/master/api/datamodel.html#printer-state
|
|
15
|
+
class StateFlags
|
|
16
|
+
include AutoInitializable
|
|
17
|
+
include Deserializable
|
|
18
|
+
|
|
19
|
+
# @!attribute [r] operational
|
|
20
|
+
# @return [Boolean] true if the printer is operational
|
|
21
|
+
auto_attr :operational, type: Types::Boolean
|
|
22
|
+
|
|
23
|
+
# @!attribute [r] paused
|
|
24
|
+
# @return [Boolean] true if the printer is currently paused
|
|
25
|
+
auto_attr :paused, type: Types::Boolean
|
|
26
|
+
|
|
27
|
+
# @!attribute [r] printing
|
|
28
|
+
# @return [Boolean] true if the printer is currently printing
|
|
29
|
+
auto_attr :printing, type: Types::Boolean
|
|
30
|
+
|
|
31
|
+
# @!attribute [r] pausing
|
|
32
|
+
# @return [Boolean] true if the printer is currently printing and in the process of pausing
|
|
33
|
+
auto_attr :pausing, type: Types::Boolean
|
|
34
|
+
|
|
35
|
+
# @!attribute [r] cancelling
|
|
36
|
+
# @return [Boolean] true if the printer is currently printing and in the process of cancelling
|
|
37
|
+
auto_attr :cancelling, type: Types::Boolean
|
|
38
|
+
|
|
39
|
+
# @!attribute [r] resuming
|
|
40
|
+
# @return [Boolean, nil] true if the printer is in the process of resuming
|
|
41
|
+
auto_attr :resuming, type: Types::Boolean
|
|
42
|
+
|
|
43
|
+
# @!attribute [r] finishing
|
|
44
|
+
# @return [Boolean, nil] true if the printer is in the process of finishing a print
|
|
45
|
+
auto_attr :finishing, type: Types::Boolean
|
|
46
|
+
|
|
47
|
+
# @!attribute [r] sd_ready
|
|
48
|
+
# @return [Boolean] true if the printer's SD card is available and initialized
|
|
49
|
+
auto_attr :sd_ready, type: Types::Boolean
|
|
50
|
+
|
|
51
|
+
# @!attribute [r] error
|
|
52
|
+
# @return [Boolean] true if an unrecoverable error occurred
|
|
53
|
+
auto_attr :error, type: Types::Boolean
|
|
54
|
+
|
|
55
|
+
# @!attribute [r] ready
|
|
56
|
+
# @return [Boolean] true if the printer is operational and ready to receive instructions
|
|
57
|
+
auto_attr :ready, type: Types::Boolean
|
|
58
|
+
|
|
59
|
+
# @!attribute [r] closed_or_error
|
|
60
|
+
# @return [Boolean] true if the printer is disconnected (possibly due to an error)
|
|
61
|
+
auto_attr :closed_or_error, type: Types::Boolean
|
|
62
|
+
|
|
63
|
+
# @!attribute [r] extra
|
|
64
|
+
# @return [Hash, nil] Any additional flags returned by the API
|
|
65
|
+
auto_attr :extra, type: Hash
|
|
66
|
+
|
|
67
|
+
auto_initialize!
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Printer
|
|
6
|
+
# Temperature reading shared by the printer's heaters ({Printer::Tool}, {Printer::Bed} and
|
|
7
|
+
# {Printer::Chamber}).
|
|
8
|
+
#
|
|
9
|
+
# Including this module declares the following attributes on the including class:
|
|
10
|
+
#
|
|
11
|
+
# - +actual+ [Float, nil] Current temperature
|
|
12
|
+
# - +target+ [Float, nil] Target temperature, nil if no target temperature is set
|
|
13
|
+
# - +offset+ [Float, nil] Currently configured temperature offset
|
|
14
|
+
# - +history+ [Array<Printer::TemperatureReading>, nil] The heater's temperature history, only included
|
|
15
|
+
# when requested
|
|
16
|
+
# - +extra+ [Hash, nil] Any additional fields returned by the API
|
|
17
|
+
#
|
|
18
|
+
# @example
|
|
19
|
+
# class Tool < BaseResource
|
|
20
|
+
# include TemperatureAttributes
|
|
21
|
+
# end
|
|
22
|
+
#
|
|
23
|
+
# tool = Tool.from_response({ tool0: { actual: 214.8821, target: 220.0, offset: 0 } }, :tool0)
|
|
24
|
+
# tool.actual # => 214.8821
|
|
25
|
+
module TemperatureAttributes
|
|
26
|
+
extend T::Helpers
|
|
27
|
+
|
|
28
|
+
# Class methods added to the including class.
|
|
29
|
+
module ClassMethods
|
|
30
|
+
# Builds a heater from a temperature response, picking the heater's own data out of the
|
|
31
|
+
# response and out of every history data point.
|
|
32
|
+
#
|
|
33
|
+
# @api private
|
|
34
|
+
# @param response [Hash] A tool, bed or chamber temperature response
|
|
35
|
+
# @param key [Symbol] The heater's key in the response, e.g. +:tool0+ or +:bed+
|
|
36
|
+
# @return [Object] An instance of the including class
|
|
37
|
+
#: (Hash[Symbol, untyped] response, Symbol key) -> untyped
|
|
38
|
+
def from_response(response, key)
|
|
39
|
+
history = response[:history]&.filter_map do |point|
|
|
40
|
+
reading = point[key]
|
|
41
|
+
TemperatureReading.deserialize({ time: point[:time], **reading }.compact) if reading
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
T.unsafe(self).deserialize({ **response.fetch(key, {}), history: history }.compact)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
mixes_in_class_methods(ClassMethods)
|
|
49
|
+
|
|
50
|
+
# Declares the temperature attributes on the including class.
|
|
51
|
+
#
|
|
52
|
+
# @param base [Class] The including class
|
|
53
|
+
# @return [void]
|
|
54
|
+
#: (Module base) -> void
|
|
55
|
+
def self.included(base)
|
|
56
|
+
super
|
|
57
|
+
|
|
58
|
+
klass = base #: as untyped
|
|
59
|
+
klass.include AutoInitializable
|
|
60
|
+
klass.include Deserializable
|
|
61
|
+
klass.auto_attr :actual, type: Float
|
|
62
|
+
klass.auto_attr :target, type: Float
|
|
63
|
+
klass.auto_attr :offset, type: Float
|
|
64
|
+
klass.auto_attr :history, type: TemperatureReading, array: true
|
|
65
|
+
klass.auto_attr :extra, type: Hash
|
|
66
|
+
klass.auto_initialize!
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Printer
|
|
6
|
+
# Temperature data of a single heater (tool, bed or chamber).
|
|
7
|
+
#
|
|
8
|
+
# @example
|
|
9
|
+
# bed = Octoprint::Printer.get.temperature.bed
|
|
10
|
+
# bed.actual # => 50.221
|
|
11
|
+
# bed.target # => 70.0
|
|
12
|
+
# bed.offset # => 5
|
|
13
|
+
#
|
|
14
|
+
# @see https://docs.octoprint.org/en/master/api/datamodel.html#temperature-data
|
|
15
|
+
class TemperatureData
|
|
16
|
+
include AutoInitializable
|
|
17
|
+
include Deserializable
|
|
18
|
+
|
|
19
|
+
# Matches the keys of tool temperatures, e.g. +tool0+, +tool1+
|
|
20
|
+
TOOL_KEY = /\Atool\d+\z/
|
|
21
|
+
|
|
22
|
+
# @!attribute [r] actual
|
|
23
|
+
# @return [Float, nil] Current temperature
|
|
24
|
+
auto_attr :actual, type: Float
|
|
25
|
+
|
|
26
|
+
# @!attribute [r] target
|
|
27
|
+
# @return [Float, nil] Target temperature, nil if no target temperature is set
|
|
28
|
+
auto_attr :target, type: Float
|
|
29
|
+
|
|
30
|
+
# @!attribute [r] offset
|
|
31
|
+
# @return [Float, nil] Currently configured temperature offset, not included in historic data points
|
|
32
|
+
auto_attr :offset, type: Float
|
|
33
|
+
|
|
34
|
+
# @!attribute [r] extra
|
|
35
|
+
# @return [Hash, nil] Any additional fields returned by the API
|
|
36
|
+
auto_attr :extra, type: Hash
|
|
37
|
+
|
|
38
|
+
auto_initialize!
|
|
39
|
+
|
|
40
|
+
# Moves all +tool{n}+ entries of a temperature hash into a +:tools+ hash of {TemperatureData}.
|
|
41
|
+
#
|
|
42
|
+
# @api private
|
|
43
|
+
# @param data [Hash] A temperature state or history data point hash
|
|
44
|
+
# @return [Hash] The modified data hash
|
|
45
|
+
#: (Hash[Symbol, untyped] data) -> Hash[Symbol, untyped]
|
|
46
|
+
def self.extract_tools(data)
|
|
47
|
+
tool_keys = data.keys.select { |key| key.to_s.match?(TOOL_KEY) }
|
|
48
|
+
data[:tools] = tool_keys.to_h { |key| [key, deserialize(data.delete(key))] }
|
|
49
|
+
data
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Octoprint
|
|
5
|
+
class Printer
|
|
6
|
+
# A historic temperature data point.
|
|
7
|
+
#
|
|
8
|
+
# @example
|
|
9
|
+
# point = Octoprint::Printer.get(history: true).temperature.history.first
|
|
10
|
+
# point.time # => 1395651928
|
|
11
|
+
# point.recorded_at # => 2014-03-24 05:05:28 -0400
|
|
12
|
+
# point.tool(0).actual # => 214.8821
|
|
13
|
+
# point.bed.target # => 70.0
|
|
14
|
+
#
|
|
15
|
+
# @see https://docs.octoprint.org/en/master/api/datamodel.html#historic-temperature-data-point
|
|
16
|
+
class TemperatureDataPoint
|
|
17
|
+
include AutoInitializable
|
|
18
|
+
include Deserializable
|
|
19
|
+
|
|
20
|
+
# @!attribute [r] time
|
|
21
|
+
# @return [Integer, nil] Unix timestamp of this data point. Only included in the full printer state
|
|
22
|
+
# ({Printer.get}), not in the tool, bed and chamber responses
|
|
23
|
+
auto_attr :time, type: Integer
|
|
24
|
+
|
|
25
|
+
# @!attribute [r] tools
|
|
26
|
+
# @return [Hash{Symbol => Printer::TemperatureData}] Temperature data per tool, keyed by +:tool0+...
|
|
27
|
+
# Empty when the response contains no tool data
|
|
28
|
+
auto_attr :tools, type: Hash
|
|
29
|
+
|
|
30
|
+
# @!attribute [r] bed
|
|
31
|
+
# @return [Printer::TemperatureData, nil] Temperature data of the heated bed
|
|
32
|
+
auto_attr :bed, type: TemperatureData
|
|
33
|
+
|
|
34
|
+
# @!attribute [r] chamber
|
|
35
|
+
# @return [Printer::TemperatureData, nil] Temperature data of the heated chamber
|
|
36
|
+
auto_attr :chamber, type: TemperatureData
|
|
37
|
+
|
|
38
|
+
# @!attribute [r] extra
|
|
39
|
+
# @return [Hash, nil] Any additional fields returned by the API
|
|
40
|
+
auto_attr :extra, type: Hash
|
|
41
|
+
|
|
42
|
+
auto_initialize!
|
|
43
|
+
|
|
44
|
+
deserialize_config do
|
|
45
|
+
nested :bed, TemperatureData
|
|
46
|
+
nested :chamber, TemperatureData
|
|
47
|
+
|
|
48
|
+
transform do |data|
|
|
49
|
+
TemperatureData.extract_tools(data)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Temperature data of the tool with the given index.
|
|
54
|
+
#
|
|
55
|
+
# @param index [Integer] The tool's index, starting at 0
|
|
56
|
+
# @return [Printer::TemperatureData, nil] The tool's temperature data, nil if there is no such tool
|
|
57
|
+
#: (?Integer index) -> TemperatureData?
|
|
58
|
+
def tool(index = 0)
|
|
59
|
+
tools&.[](:"tool#{index}")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# The data point's timestamp as a Time object.
|
|
63
|
+
#
|
|
64
|
+
# @return [Time, nil] The time of the data point
|
|
65
|
+
#: -> Time?
|
|
66
|
+
def recorded_at
|
|
67
|
+
return nil unless time
|
|
68
|
+
|
|
69
|
+
Time.at(time)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|