Class: Dirigera::Device
- Inherits:
-
Object
- Object
- Dirigera::Device
- Defined in:
- lib/dirigera/device.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #battery_level ⇒ Object
- #created_at ⇒ Object
- #id ⇒ Object
-
#initialize(data, client) ⇒ Device
constructor
A new instance of Device.
- #last_seen_at ⇒ Object
- #name ⇒ Object
- #name=(new_name) ⇒ Object
- #reachable? ⇒ Boolean
- #reload ⇒ Object
- #room ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(data, client) ⇒ Device
Returns a new instance of Device.
2 3 4 5 |
# File 'lib/dirigera/device.rb', line 2 def initialize(data, client) @data = data @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/dirigera/device.rb', line 7 def client @client end |
Instance Method Details
#battery_level ⇒ Object
29 30 31 |
# File 'lib/dirigera/device.rb', line 29 def battery_level @data['attributes']['batteryPercentage'] end |
#created_at ⇒ Object
21 22 23 |
# File 'lib/dirigera/device.rb', line 21 def created_at Time.parse(@data['createdAt']) end |
#id ⇒ Object
9 10 11 |
# File 'lib/dirigera/device.rb', line 9 def id @data['id'] end |
#last_seen_at ⇒ Object
25 26 27 |
# File 'lib/dirigera/device.rb', line 25 def last_seen_at Time.parse(@data['lastSeen']) end |
#name ⇒ Object
17 18 19 |
# File 'lib/dirigera/device.rb', line 17 def name @data['attributes']['customName'] end |
#name=(new_name) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/dirigera/device.rb', line 41 def name=(new_name) response = @client.patch("/devices/#{id}", [{ attributes: { customName: new_name } }]) raise "Failed to update name" unless response.code == 202 @data['attributes']['customName'] = new_name end |
#reachable? ⇒ Boolean
33 34 35 |
# File 'lib/dirigera/device.rb', line 33 def reachable? @data['isReachable'] end |
#reload ⇒ Object
48 49 50 |
# File 'lib/dirigera/device.rb', line 48 def reload @data = @client.get("/devices/#{id}") end |
#room ⇒ Object
37 38 39 |
# File 'lib/dirigera/device.rb', line 37 def room @data['room'] end |
#type ⇒ Object
13 14 15 |
# File 'lib/dirigera/device.rb', line 13 def type @data['type'] end |