Class: IntesisBox::Client
- Inherits:
-
Object
- Object
- IntesisBox::Client
- Defined in:
- lib/intesis_box/client.rb
Instance Attribute Summary collapse
-
#ambtemp ⇒ Object
readonly
Returns the value of attribute ambtemp.
-
#devicename ⇒ Object
Returns the value of attribute devicename.
-
#errcode ⇒ Object
readonly
Returns the value of attribute errcode.
-
#errstatus ⇒ Object
readonly
Returns the value of attribute errstatus.
-
#fansp ⇒ Object
readonly
Returns the value of attribute fansp.
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#limits ⇒ Object
readonly
Returns the value of attribute limits.
-
#mac ⇒ Object
readonly
Returns the value of attribute mac.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#onoff ⇒ Object
Returns the value of attribute onoff.
-
#rssi ⇒ Object
readonly
Returns the value of attribute rssi.
-
#setptemp ⇒ Object
Returns the value of attribute setptemp.
-
#vanelr ⇒ Object
readonly
Returns the value of attribute vanelr.
-
#vaneud ⇒ Object
readonly
Returns the value of attribute vaneud.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(ip, port = 3310) ⇒ Client
constructor
A new instance of Client.
- #ping ⇒ Object
- #poll(timeout = 30) ⇒ Object
Constructor Details
#initialize(ip, port = 3310) ⇒ Client
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/intesis_box/client.rb', line 10 def initialize(ip, port = 3310) @limits = {} @ip = ip @io = TCPSocket.new(ip, port) @io.puts("LIMITS:*") poll(1) @io.puts("CFG:DEVICENAME") poll(1) @io.puts("GET,1:*") poll(1) # this is purposely last, since mac is what we check for it being ready @io.puts("ID") poll(1) end |
Instance Attribute Details
#ambtemp ⇒ Object (readonly)
Returns the value of attribute ambtemp.
8 9 10 |
# File 'lib/intesis_box/client.rb', line 8 def ambtemp @ambtemp end |
#devicename ⇒ Object
Returns the value of attribute devicename.
7 8 9 |
# File 'lib/intesis_box/client.rb', line 7 def devicename @devicename end |
#errcode ⇒ Object (readonly)
Returns the value of attribute errcode.
8 9 10 |
# File 'lib/intesis_box/client.rb', line 8 def errcode @errcode end |
#errstatus ⇒ Object (readonly)
Returns the value of attribute errstatus.
8 9 10 |
# File 'lib/intesis_box/client.rb', line 8 def errstatus @errstatus end |
#fansp ⇒ Object (readonly)
Returns the value of attribute fansp.
8 9 10 |
# File 'lib/intesis_box/client.rb', line 8 def fansp @fansp end |
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
5 6 7 |
# File 'lib/intesis_box/client.rb', line 5 def ip @ip end |
#limits ⇒ Object (readonly)
Returns the value of attribute limits.
6 7 8 |
# File 'lib/intesis_box/client.rb', line 6 def limits @limits end |
#mac ⇒ Object (readonly)
Returns the value of attribute mac.
5 6 7 |
# File 'lib/intesis_box/client.rb', line 5 def mac @mac end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
8 9 10 |
# File 'lib/intesis_box/client.rb', line 8 def mode @mode end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/intesis_box/client.rb', line 5 def model @model end |
#onoff ⇒ Object
Returns the value of attribute onoff.
8 9 10 |
# File 'lib/intesis_box/client.rb', line 8 def onoff @onoff end |
#rssi ⇒ Object (readonly)
Returns the value of attribute rssi.
5 6 7 |
# File 'lib/intesis_box/client.rb', line 5 def rssi @rssi end |
#setptemp ⇒ Object
Returns the value of attribute setptemp.
8 9 10 |
# File 'lib/intesis_box/client.rb', line 8 def setptemp @setptemp end |
#vanelr ⇒ Object (readonly)
Returns the value of attribute vanelr.
8 9 10 |
# File 'lib/intesis_box/client.rb', line 8 def vanelr @vanelr end |
#vaneud ⇒ Object (readonly)
Returns the value of attribute vaneud.
8 9 10 |
# File 'lib/intesis_box/client.rb', line 8 def vaneud @vaneud end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
5 6 7 |
# File 'lib/intesis_box/client.rb', line 5 def version @version end |
Instance Method Details
#ping ⇒ Object
57 58 59 |
# File 'lib/intesis_box/client.rb', line 57 def ping @io.puts("PING") end |
#poll(timeout = 30) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/intesis_box/client.rb', line 26 def poll(timeout = 30) return false if @io.wait_readable(timeout).nil? loop do line = @io.readline.strip cmd, args = line.split(':', 2) case cmd when "ID" @model, @mac, _ip, _protocol, @version, @rssi = args.split(',') when "LIMITS" function, limits = args.split(",",2) limits = limits[1...-1].split(",") next if function == 'ONOFF' limits.map! { |l| l.to_f / 10 } if %w{SETPTEMP AMBTEMP}.include?(function) @limits[function.downcase.to_sym] = limits when "CHN,1" function, value = args.split(",") value = value == 'ON' if function == 'ONOFF' value = value.to_f / 10 if %w{SETPTEMP AMBTEMP}.include?(function) value = value.to_i if function == 'ERRCODE' value = nil if value == -3276.8 instance_variable_set(:"@#{function.downcase}", value) when "CFG" function, value = args.split(",", 2) @devicename = value if function == 'DEVICENAME' end break unless @io.ready? end true end |