Class: TenHsServer::Device
- Defined in:
- lib/ten_hs_server/device.rb
Overview
Adapter for TenHsServer devices endpoint, which returns information for each of the devices in Homeseer
Instance Attribute Summary collapse
-
#_floor ⇒ Object
readonly
Returns the value of attribute _floor.
-
#_name ⇒ Object
readonly
Returns the value of attribute _name.
-
#_room ⇒ Object
readonly
Returns the value of attribute _room.
-
#_type ⇒ Object
readonly
Returns the value of attribute _type.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
-
.all ⇒ Object
Load all devices.
-
.find(id) ⇒ Object
Load a single device.
-
.off(id) ⇒ Object
Turn off a device.
-
.on(id) ⇒ Object
Turn on a device.
-
.toggle(id) ⇒ Object
Toggle a device.
-
.value(id, value) ⇒ Object
Set device value.
Instance Method Summary collapse
- #dim(value) ⇒ Object
- #dimmable ⇒ Object
- #floor ⇒ Object
-
#initialize(id, name = nil, type = nil, room = nil, floor = nil) ⇒ Device
constructor
A new instance of Device.
- #name ⇒ Object
- #off ⇒ Object
- #off? ⇒ Boolean
- #on ⇒ Object
-
#on? ⇒ Boolean
Properties.
- #query ⇒ Object
- #room ⇒ Object
- #status ⇒ Object
-
#toggle ⇒ Object
Methods.
- #type ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(id, name = nil, type = nil, room = nil, floor = nil) ⇒ Device
Returns a new instance of Device.
8 9 10 11 12 13 14 |
# File 'lib/ten_hs_server/device.rb', line 8 def initialize id, name=nil, type=nil, room=nil, floor=nil @id = id @_name = name @_type = type @_room = room @_floor = floor end |
Instance Attribute Details
#_floor ⇒ Object (readonly)
Returns the value of attribute _floor.
6 7 8 |
# File 'lib/ten_hs_server/device.rb', line 6 def _floor @_floor end |
#_name ⇒ Object (readonly)
Returns the value of attribute _name.
6 7 8 |
# File 'lib/ten_hs_server/device.rb', line 6 def _name @_name end |
#_room ⇒ Object (readonly)
Returns the value of attribute _room.
6 7 8 |
# File 'lib/ten_hs_server/device.rb', line 6 def _room @_room end |
#_type ⇒ Object (readonly)
Returns the value of attribute _type.
6 7 8 |
# File 'lib/ten_hs_server/device.rb', line 6 def _type @_type end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/ten_hs_server/device.rb', line 6 def id @id end |
Class Method Details
.all ⇒ Object
Load all devices.
Returns an array of Device instances.
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ten_hs_server/device.rb', line 90 def all response = get "?t=99&f=GetDevices" devices = parse_devices response.body devices.map! do |device| new(device[:id], device[:name], device[:type], device[:location], device[:floor]) end devices end |
.find(id) ⇒ Object
Load a single device.
id - An string describing the device
Returns a hash describing the device.
106 107 108 109 110 111 |
# File 'lib/ten_hs_server/device.rb', line 106 def find id id = URI::encode(id) response = get "?t=99&f=GetDevice&d=#{id}" parse_device response.body end |
.off(id) ⇒ Object
Turn off a device.
id - An string describing the device
Returns a true or false describing the status of the device false = off true = on
148 149 150 151 152 153 |
# File 'lib/ten_hs_server/device.rb', line 148 def off id id = URI::encode(id) response = get "?t=99&f=DeviceOff&d=#{id}" parse_toggle_device response.body end |
.on(id) ⇒ Object
Turn on a device.
id - An string describing the device
Returns a true or false describing the status of the device false = off true = on
134 135 136 137 138 139 |
# File 'lib/ten_hs_server/device.rb', line 134 def on id id = URI::encode(id) response = get "?t=99&f=DeviceOn&d=#{id}" parse_toggle_device response.body end |
.toggle(id) ⇒ Object
Toggle a device.
id - An string describing the device
Returns a true or false describing the status of the device false = off true = on
120 121 122 123 124 125 |
# File 'lib/ten_hs_server/device.rb', line 120 def toggle id id = URI::encode(id) response = get "?t=99&f=ToggleDevice&d=#{id}" parse_toggle_device response.body end |
.value(id, value) ⇒ Object
Set device value.
id - An string describing the device value - The value to give the device
160 161 162 163 164 165 166 |
# File 'lib/ten_hs_server/device.rb', line 160 def value(id, value) id = URI::encode(id) value = URI::encode(value.to_s) response = get "?t=99&f=SetDeviceValue&d=#{id}&a=#{value}" parse_set_device_value response.body end |
Instance Method Details
#dim(value) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/ten_hs_server/device.rb', line 33 def dim value if value == 0 off else on self.class.value(id, value) end end |
#dimmable ⇒ Object
67 68 69 70 |
# File 'lib/ten_hs_server/device.rb', line 67 def dimmable # Boolean that query[:dim] end |
#floor ⇒ Object
63 64 65 |
# File 'lib/ten_hs_server/device.rb', line 63 def floor _floor ? _floor : query[:floor] end |
#name ⇒ Object
59 60 61 |
# File 'lib/ten_hs_server/device.rb', line 59 def name _name ? _name : query[:name] end |
#off ⇒ Object
29 30 31 |
# File 'lib/ten_hs_server/device.rb', line 29 def off self.class.off(id) end |
#off? ⇒ Boolean
47 48 49 |
# File 'lib/ten_hs_server/device.rb', line 47 def off? query[:status] == 3 ? true : false end |
#on ⇒ Object
25 26 27 |
# File 'lib/ten_hs_server/device.rb', line 25 def on self.class.on(id) end |
#on? ⇒ Boolean
Properties
43 44 45 |
# File 'lib/ten_hs_server/device.rb', line 43 def on? query[:status] == 2 ? true : false end |
#query ⇒ Object
16 17 18 |
# File 'lib/ten_hs_server/device.rb', line 16 def query @query || @query = self.class.find(id) end |
#room ⇒ Object
55 56 57 |
# File 'lib/ten_hs_server/device.rb', line 55 def room _room ? _room : query[:location] end |
#status ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/ten_hs_server/device.rb', line 72 def status # Status of device # 2 On # 3 Off # 4 Dimmed query[:status] end |
#toggle ⇒ Object
Methods
21 22 23 |
# File 'lib/ten_hs_server/device.rb', line 21 def toggle self.class.toggle(id) end |
#type ⇒ Object
51 52 53 |
# File 'lib/ten_hs_server/device.rb', line 51 def type _type ? _type : query[:type] end |
#value ⇒ Object
80 81 82 83 |
# File 'lib/ten_hs_server/device.rb', line 80 def value # For dimmable devices this is a value between 0 and 100 query[:value] end |