Class: SAAL::Envoy::ACQuality
- Inherits:
-
Object
- Object
- SAAL::Envoy::ACQuality
- Defined in:
- lib/envoy.rb
Constant Summary collapse
- DEFAULT_HOST =
"envoy.local"- DEFAULT_TOKEN =
""- DEFAULT_TIMEOUT =
2- DEFAULT_CACHE_TIMEOUT =
5- DEFAULT_SOURCES =
["total","phase1","phase2","phase3",]
- DEFAULT_TYPES =
["frequency","voltage"]
- DEFAULT_PREFIX =
"ac"
Instance Method Summary collapse
- #create_sensors ⇒ Object
-
#initialize(defs, opts = {}) ⇒ ACQuality
constructor
A new instance of ACQuality.
- #read_val(name) ⇒ Object
Constructor Details
#initialize(defs, opts = {}) ⇒ ACQuality
151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/envoy.rb', line 151 def initialize(defs, opts={}) @host = defs[:host] || defs['host'] || DEFAULT_HOST @token = defs[:token] || defs['token'] || DEFAULT_TOKEN @timeout = opts[:timeout] || opts['timeout'] || DEFAULT_TIMEOUT @cache_timeout = opts[:cache_timeout] || opts['cache_timeout'] || DEFAULT_CACHE_TIMEOUT @cache = nil @cachetime = nil @sources = defs[:sources] || defs['source'] || DEFAULT_SOURCES @types = defs[:types] || defs['types'] || DEFAULT_TYPES @prefix = defs[:prefix] || defs['prefix'] || DEFAULT_PREFIX end |
Instance Method Details
#create_sensors ⇒ Object
171 172 173 174 175 176 177 178 |
# File 'lib/envoy.rb', line 171 def create_sensors sensors = {} @sources.product(@types).each do |source, type| key = "#{@prefix}_#{source}_#{type}" sensors[key] = .new(key, self) end sensors end |
#read_val(name) ⇒ Object
163 164 165 166 167 168 169 |
# File 'lib/envoy.rb', line 163 def read_val(name) if !@cachetime or @cachetime < Time.now - @cache_timeout @cache = read_all() @cachetime = Time.now end return @cache ? @cache[name] : nil end |