Sha256: c24c1fb61f7d133817c2a10492d56b797f524ec3553631d9f7be676d5f4ee0ea
Contents?: true
Size: 1.74 KB
Versions: 3
Compression:
Stored size: 1.74 KB
Contents
# encoding: UTF-8 module ParseP1 module Electricity def electra_meter_id match_within_one_p1_record('0:96\.1\.1\S(\d{1}[A-Z]{1}\d{1,96})\S') end def electricity_tariff_indicator result = match_within_one_p1_record('0-0:96\.14\.0\S(\d{1,9})\S') result.to_i if result end def electricity_actual_threshold electricity('0-0:17\.0\.0') end def electra_import_low electricity(:type => :import, :tariff => :low) end def electra_import_normal electricity(:type => :import, :tariff => :normal) end def electra_export_low electricity(:type => :export, :tariff => :low) end def electra_export_normal electricity(:type => :export, :tariff => :normal) end def actual_electra electricity(:type => :import, :actual => true) end def electricity(options) if options.is_a?(Hash) if options[:actual] == true get_actual_electricity(options[:type]) else get_electricity("1-0:#{first_electricity_code(options[:type])}.8.#{second_electricity_code(options[:tariff])}") end else get_electricity(options) end end private def get_electricity(obis_code) data.match(/\/[\W|\w]*#{obis_code}\S(\d{1,9}\.\d{1,3})\S[\W|\w]*!/) $1.to_f if $1 end def get_actual_electricity(type) power = get_electricity("1-0:#{first_electricity_code(type)}\.7\.0") (power * 1000).to_i if power#Return as watts instead of kW end def first_electricity_code(code) case code when :import; '1' when :export; '2' end end def second_electricity_code(tariff) case tariff when :low; 1 when :normal; 2 end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
parse_p1-0.1.0 | lib/parse_p1/electricity.rb |
parse_p1-0.0.9 | lib/parse_p1/electricity.rb |
parse_p1-0.0.8 | lib/parse_p1/electricity.rb |