Class: SAAL::DINRelay::OutletGroup

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

Constant Summary collapse

DEFAULT_TIMEOUT =
2
DEFAULT_CACHE_TIMEOUT =
60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ OutletGroup

Returns a new instance of OutletGroup.



36
37
38
39
40
41
42
43
44
45
# File 'lib/dinrelay.rb', line 36

def initialize(opts={})
  @host = opts[:host] || opts['host'] || 'localhost'
  @port = opts[:port] || opts['port'] || 80
  @user = opts[:user] || opts['user'] || 'admin'
  @pass = opts[:pass] || opts['pass'] || '1234'
  @timeout = opts[:timeout] || opts['timeout'] || DEFAULT_TIMEOUT
  @cache_timeout = opts[:cache_timeout] || opts['cache_timeout'] || DEFAULT_CACHE_TIMEOUT
  @cache = nil
  @cachehit = nil
end

Instance Attribute Details

#cache_timeoutObject

Returns the value of attribute cache_timeout.



34
35
36
# File 'lib/dinrelay.rb', line 34

def cache_timeout
  @cache_timeout
end

#hostObject

Returns the value of attribute host.



34
35
36
# File 'lib/dinrelay.rb', line 34

def host
  @host
end

#passObject

Returns the value of attribute pass.



34
35
36
# File 'lib/dinrelay.rb', line 34

def pass
  @pass
end

#portObject

Returns the value of attribute port.



34
35
36
# File 'lib/dinrelay.rb', line 34

def port
  @port
end

#timeoutObject

Returns the value of attribute timeout.



34
35
36
# File 'lib/dinrelay.rb', line 34

def timeout
  @timeout
end

#userObject

Returns the value of attribute user.



34
35
36
# File 'lib/dinrelay.rb', line 34

def user
  @user
end

Instance Method Details

#set_state(num, state) ⇒ Object



55
56
57
58
59
# File 'lib/dinrelay.rb', line 55

def set_state(num, state)
  @cachetime = nil
  response = do_get("/outlet?#{num}=#{state}")
  response != nil
end

#state(num) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/dinrelay.rb', line 47

def state(num)
  if !@cachetime or @cachetime < Time.now - @cache_timeout
    @cache = do_get('/index.htm')
    @cachetime = Time.now
  end
  return @cache ? parse_index_html(@cache.body)[num] : nil
end