class SAAL::Envoy::ACQuality

Constants

DEFAULT_CACHE_TIMEOUT
DEFAULT_HOST
DEFAULT_PREFIX
DEFAULT_SOURCES
DEFAULT_TIMEOUT
DEFAULT_TYPES

Public Class Methods

new(defs, opts={}) click to toggle source
    # File lib/envoy.rb
148 def initialize(defs, opts={})
149   @host = defs[:host] || defs['host'] || DEFAULT_HOST
150   @timeout = opts[:timeout] || opts['timeout'] || DEFAULT_TIMEOUT
151   @cache_timeout = opts[:cache_timeout] || opts['cache_timeout'] || DEFAULT_CACHE_TIMEOUT
152   @cache = nil
153   @cachetime = nil
154   @sources = defs[:sources] || defs['source'] || DEFAULT_SOURCES
155   @types = defs[:types] || defs['types'] || DEFAULT_TYPES
156   @prefix = defs[:prefix] || defs['prefix'] || DEFAULT_PREFIX
157 end

Public Instance Methods

create_sensors() click to toggle source
    # File lib/envoy.rb
167 def create_sensors
168   sensors = {}
169   @sources.product(@types).each do |source, type|
170     key = "#{@prefix}_#{source}_#{type}"
171     sensors[key] = ACQualityUnderlying.new(key, self)
172   end
173   sensors
174 end
read_val(name) click to toggle source
    # File lib/envoy.rb
159 def read_val(name)
160   if !@cachetime or @cachetime < Time.now - @cache_timeout
161     @cache = read_all()
162     @cachetime = Time.now
163   end
164   return @cache ? @cache[name] : nil
165 end

Private Instance Methods

read_all() click to toggle source
    # File lib/envoy.rb
186 def read_all
187   response = SAAL::do_http_get(@host, 80, "/ivp/meters/readings", nil, nil, @timeout)
188   return nil if !response
189 
190   values = JSON.parse(response.body)
191   outputs = {}
192   source = values[0]
193   save_vals(outputs, "total", source)
194   if source["channels"]
195     save_vals(outputs, "phase1", source["channels"][0])
196     save_vals(outputs, "phase2", source["channels"][1])
197     save_vals(outputs, "phase3", source["channels"][2])
198   end
199 
200   outputs
201 end
save_vals(dest, name, source) click to toggle source
    # File lib/envoy.rb
177 def save_vals(dest, name, source)
178   {
179    "voltage" => "voltage",
180    "freq" => "frequency",
181   }.each do |type, label|
182     dest["#{@prefix}_#{name}_#{label}"] = source[type]
183   end
184 end