Class: Dirigera::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/dirigera/device.rb

Direct Known Subclasses

Blinds, Light, Outlet

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#clientObject (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_levelObject



29
30
31
# File 'lib/dirigera/device.rb', line 29

def battery_level
  @data['attributes']['batteryPercentage']
end

#created_atObject



21
22
23
# File 'lib/dirigera/device.rb', line 21

def created_at
  Time.parse(@data['createdAt'])
end

#idObject



9
10
11
# File 'lib/dirigera/device.rb', line 9

def id
  @data['id']
end

#last_seen_atObject



25
26
27
# File 'lib/dirigera/device.rb', line 25

def last_seen_at
  Time.parse(@data['lastSeen'])
end

#nameObject



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

Returns:

  • (Boolean)


33
34
35
# File 'lib/dirigera/device.rb', line 33

def reachable?
  @data['isReachable']
end

#reloadObject



48
49
50
# File 'lib/dirigera/device.rb', line 48

def reload
  @data = @client.get("/devices/#{id}")
end

#roomObject



37
38
39
# File 'lib/dirigera/device.rb', line 37

def room
  @data['room']
end

#typeObject



13
14
15
# File 'lib/dirigera/device.rb', line 13

def type
  @data['type']
end