Class: SAAL::Envoy::PowerEnergy
- Inherits:
-
Object
- Object
- SAAL::Envoy::PowerEnergy
- Defined in:
- lib/envoy.rb
Constant Summary collapse
- DEFAULT_HOST =
"envoy.local"- DEFAULT_TOKEN =
""- DEFAULT_TIMEOUT =
2- DEFAULT_CACHE_TIMEOUT =
5- DEFAULT_SOURCES =
[ "production_inverters", "production_phase1", "production_phase2", "production_phase3", "production_total", "net_consumption_phase1", "net_consumption_phase2", "net_consumption_phase3", "net_consumption_total", "total_consumption_phase1", "total_consumption_phase2", "total_consumption_phase3", "total_consumption_total", ]
- DEFAULT_TYPES =
[ "w_now", "wh_lifetime", "va_now", "vah_lifetime", ]
- DEFAULT_PREFIX =
"pv"
Instance Method Summary collapse
- #create_sensors ⇒ Object
-
#initialize(defs, opts = {}) ⇒ PowerEnergy
constructor
A new instance of PowerEnergy.
- #read_val(name) ⇒ Object
Constructor Details
#initialize(defs, opts = {}) ⇒ PowerEnergy
Returns a new instance of PowerEnergy.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/envoy.rb', line 32 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
52 53 54 55 56 57 58 59 |
# File 'lib/envoy.rb', line 52 def create_sensors sensors = {} @sources.product(@types).each do |source, type| key = "#{@prefix}_#{source}_#{type}" sensors[key] = PowerEnergyUnderlying.new(key, self) end sensors end |
#read_val(name) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/envoy.rb', line 44 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 |