Class: Particle::Device
Overview
Domain model for one Particle device
Constant Summary
collapse
- ID_REGEX =
/^\h{24}$/
- PRODUCT_IDS =
{
0 => "Core".freeze,
6 => "Photon".freeze,
8 => "P1".freeze,
10 => "Electron".freeze,
31 => "Raspberry Pi".freeze
}
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Model
attribute_reader, #attributes, #inspect
Constructor Details
#initialize(client, attributes) ⇒ Device
Returns a new instance of Device.
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/particle/device.rb', line 16
def initialize(client, attributes)
super(client, attributes)
if attributes.is_a? String
if attributes =~ ID_REGEX
@attributes = { id: attributes }
else
@attributes = { name: attributes }
end
else
@fully_loaded = true if attributes.key?(:variables)
end
end
|
Class Method Details
.claim_path ⇒ Object
182
183
184
|
# File 'lib/particle/device.rb', line 182
def self.claim_path
"v1/devices"
end
|
.list_path ⇒ Object
178
179
180
|
# File 'lib/particle/device.rb', line 178
def self.list_path
"v1/devices"
end
|
.provision_path ⇒ Object
186
187
188
|
# File 'lib/particle/device.rb', line 186
def self.provision_path
"v1/devices"
end
|
Instance Method Details
#change_product(product_id, should_update = false) ⇒ boolean
Change the product_id on the device. Use this carefully, it will impact what updates you receive, and can only be used for products that have given their permission
163
164
165
|
# File 'lib/particle/device.rb', line 163
def change_product(product_id, should_update = false)
@client.change_device_product(self, product_id, should_update)
end
|
#claim ⇒ Object
Add a Particle device to your account
74
75
76
77
|
# File 'lib/particle/device.rb', line 74
def claim
new_device = @client.claim_device(self)
self
end
|
#compile(file_paths) ⇒ OpenStruct
Compile firmware from source code for this device
151
152
153
|
# File 'lib/particle/device.rb', line 151
def compile(file_paths)
@client.compile(file_paths, device_id: id)
end
|
#flash(file_paths, options = {}) ⇒ OpenStruct
Flash new firmware to this device from source code or binary
139
140
141
|
# File 'lib/particle/device.rb', line 139
def flash(file_paths, options = {})
@client.flash_device(self, file_paths, options)
end
|
#function(name, argument = "") ⇒ Object
Also known as:
call
Call a function in the firmware of a Particle device
102
103
104
|
# File 'lib/particle/device.rb', line 102
def function(name, argument = "")
@client.call_function(self, name, argument)
end
|
#function_path(name) ⇒ Object
198
199
200
|
# File 'lib/particle/device.rb', line 198
def function_path(name)
path + "/#{name}"
end
|
#functions ⇒ Object
51
52
53
54
|
# File 'lib/particle/device.rb', line 51
def functions
get_attributes unless @fully_loaded
@attributes[:functions]
end
|
#get_attributes ⇒ Object
65
66
67
68
|
# File 'lib/particle/device.rb', line 65
def get_attributes
@loaded = @fully_loaded = true
@attributes = @client.device_attributes(self)
end
|
#id ⇒ Object
32
33
34
35
|
# File 'lib/particle/device.rb', line 32
def id
get_attributes unless @attributes[:id]
@attributes[:id]
end
|
#id_or_name ⇒ Object
42
43
44
|
# File 'lib/particle/device.rb', line 42
def id_or_name
@attributes[:id] || @attributes[:name]
end
|
#name ⇒ Object
37
38
39
40
|
# File 'lib/particle/device.rb', line 37
def name
get_attributes unless @attributes[:name]
@attributes[:name]
end
|
#path ⇒ Object
194
195
196
|
# File 'lib/particle/device.rb', line 194
def path
"/v1/devices/#{id_or_name}"
end
|
#product ⇒ Object
61
62
63
|
# File 'lib/particle/device.rb', line 61
def product
PRODUCT_IDS[product_id]
end
|
#remove ⇒ Object
Remove a Particle device from your account
83
84
85
|
# File 'lib/particle/device.rb', line 83
def remove
@client.remove_device(self)
end
|
#rename(name) ⇒ Object
Rename a Particle device on your account
92
93
94
|
# File 'lib/particle/device.rb', line 92
def rename(name)
@client.rename_device(self, name)
end
|
#signal(enabled = true) ⇒ boolean
Signal the device to start blinking the RGB LED in a rainbow pattern. Useful to identify a particular device.
124
125
126
|
# File 'lib/particle/device.rb', line 124
def signal(enabled = true)
@client.signal_device(self, enabled)
end
|
#update_keys_path ⇒ Object
190
191
192
|
# File 'lib/particle/device.rb', line 190
def update_keys_path
"/v1/provisioning/#{id}"
end
|
#update_public_key(public_key, algorithm = 'rsa') ⇒ boolean
Update the public key for a device you own
174
175
176
|
# File 'lib/particle/device.rb', line 174
def update_public_key(public_key, algorithm = 'rsa')
@client.update_device_public_key(self, public_key, algorithm)
end
|
#variable(name) ⇒ String, Number
Also known as:
get
Get the value of a variable in the firmware of a Particle device
114
115
116
|
# File 'lib/particle/device.rb', line 114
def variable(name)
@client.get_variable(self, name)
end
|
#variable_path(name) ⇒ Object
202
203
204
|
# File 'lib/particle/device.rb', line 202
def variable_path(name)
path + "/#{name}"
end
|
#variables ⇒ Object
56
57
58
59
|
# File 'lib/particle/device.rb', line 56
def variables
get_attributes unless @fully_loaded
@attributes[:variables]
end
|