class IntesisBox::Client
Attributes
ambtemp[R]
devicename[R]
errcode[R]
errstatus[R]
fansp[R]
ip[R]
limits[R]
mac[R]
mode[R]
model[R]
onoff[R]
rssi[R]
setptemp[R]
vanelr[R]
vaneud[R]
version[R]
Public Class Methods
new(ip, port = 3310)
click to toggle source
# 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
Public Instance Methods
devicename=(value)
click to toggle source
# File lib/intesis_box/client.rb, line 80 def devicename=(value) @io.puts("CFG:DEVICENAME,#{value}") # have to re-query to ensure it got the new value @io.puts("CFG:DEVICENAME") end
onoff=(value)
click to toggle source
# File lib/intesis_box/client.rb, line 61 def onoff=(value) @io.puts("SET,1:ONOFF,#{value ? 'ON' : 'OFF'}") end
ping()
click to toggle source
# File lib/intesis_box/client.rb, line 57 def ping @io.puts("PING") end
poll(timeout = 30)
click to toggle source
# 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
setptemp=(value)
click to toggle source
# File lib/intesis_box/client.rb, line 74 def setptemp=(value) value = value.round return if limits[:setptemp] && (value < limits[:setptemp].first || value > limits[:setptemp].last) @io.puts("SET,1:SETPTEMP,#{value * 10}") end