parse_p1 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -4
- data/CHANGELOG +5 -2
- data/Gemfile +1 -0
- data/lib/parse_p1.rb +1 -0
- data/lib/parse_p1/base.rb +33 -7
- data/lib/parse_p1/electricity.rb +25 -38
- data/lib/parse_p1/gas.rb +20 -5
- data/lib/parse_p1/version.rb +1 -1
- data/parse_p1.gemspec +1 -1
- data/test/helper.rb +2 -0
- data/test/parse_p1_IskraMT171_meter_test.rb +99 -0
- data/test/parse_p1_landisgyr_e350_test.rb +99 -0
- data/test/parse_p1_test.rb +17 -35
- metadata +36 -31
- data/.rvmrc +0 -1
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 385d560b817db7e1f0e047f3783d8908525cdd8d
|
4
|
+
data.tar.gz: 9b0be70a66a5ee4f991b80acc0ec7ee5aa9969fd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c70945d8d2cb78e3b6dc4401c8f0cb93ae6db1ed031614a0b31d25415b81bd68b2cc4624e3a7cda003862ecb2f33b2e125f6a4790831c8c4ba2c618d4c8809d2
|
7
|
+
data.tar.gz: 0d0a1f7e827738f43084f013a8978f9dcf11739228d63f396aad78b3b3e7ac3bd9d3126163e14ad3d25c61fedf05ce018dfe57edb3339f633f7d064d37875bd7
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
parse_p1
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.2
|
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
* 0.1.1
|
2
|
+
Major refactor to simplify and increase robustness of parser, it now also handles the Landys & Gyr E350 meter
|
3
|
+
|
1
4
|
* 0.1.0
|
2
5
|
Parse Gas values with different OBIS codes because of RF module on Gas meter
|
3
6
|
|
@@ -9,7 +12,7 @@
|
|
9
12
|
|
10
13
|
* 0.0.7
|
11
14
|
Set encoding to UTF8
|
12
|
-
|
15
|
+
|
13
16
|
* 0.0.6
|
14
17
|
Added so called direct methods electra_import_normal, electra_import_low, electra_export_normal and electra_export_low
|
15
18
|
|
@@ -26,4 +29,4 @@
|
|
26
29
|
Parsing of electricity and gas values
|
27
30
|
|
28
31
|
* 0.0.1
|
29
|
-
Initial release
|
32
|
+
Initial release
|
data/Gemfile
CHANGED
data/lib/parse_p1.rb
CHANGED
data/lib/parse_p1/base.rb
CHANGED
@@ -7,27 +7,53 @@ module ParseP1
|
|
7
7
|
include ParseP1::Electricity
|
8
8
|
include ParseP1::Gas
|
9
9
|
|
10
|
-
attr_reader :data
|
10
|
+
attr_reader :data, :device_id, :obis_records
|
11
11
|
|
12
12
|
def initialize(data)
|
13
|
-
@data = data
|
13
|
+
@data = data.split('/').last.split('!').first.split
|
14
|
+
@obis_records = {}
|
15
|
+
extract_obis_records(@data)
|
14
16
|
end
|
15
17
|
|
16
18
|
def valid?
|
17
|
-
|
19
|
+
electra_meter_id.is_a?(String) && actual_electra.is_a?(Float) && gas_meter_id.is_a?(String) && gas_usage.is_a?(Float)
|
18
20
|
end
|
19
21
|
|
20
22
|
def device_id
|
21
|
-
|
23
|
+
data.shift
|
22
24
|
end
|
23
25
|
|
24
26
|
private
|
25
27
|
|
26
|
-
def
|
27
|
-
data.
|
28
|
+
def extract_obis_records(data)
|
29
|
+
data.each do |item|
|
30
|
+
obis_values = item.split('(')
|
31
|
+
previous_values = []
|
32
|
+
|
33
|
+
key = extract_key(obis_values)
|
34
|
+
|
35
|
+
#Values without a key are associated with the last known key
|
36
|
+
if key.nil?
|
37
|
+
key = @obis_records.keys.last
|
38
|
+
previous_values = @obis_records[key] if key
|
39
|
+
end
|
40
|
+
|
41
|
+
@obis_records[key] = previous_values + cleanup(obis_values)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def extract_key(record)
|
46
|
+
record.first.match(obis_record_pattern)
|
28
47
|
$1
|
29
48
|
end
|
30
49
|
|
50
|
+
def cleanup(obis_values)
|
51
|
+
obis_values[1..-1].map {|value| value[-1] == ')' ? value.chop : value }
|
52
|
+
end
|
53
|
+
|
54
|
+
def obis_record_pattern
|
55
|
+
/(\d+-\d+:\d+\.\d+.\d+)/
|
56
|
+
end
|
31
57
|
end
|
32
58
|
|
33
|
-
end
|
59
|
+
end
|
data/lib/parse_p1/electricity.rb
CHANGED
@@ -5,76 +5,63 @@ module ParseP1
|
|
5
5
|
module Electricity
|
6
6
|
|
7
7
|
def electra_meter_id
|
8
|
-
|
8
|
+
result = obis_records['0-0:96.1.1']
|
9
|
+
result.first if result
|
9
10
|
end
|
10
11
|
|
11
12
|
def electricity_tariff_indicator
|
12
|
-
|
13
|
-
result.to_i if result
|
13
|
+
get_electricity('0-0:96.14.0')
|
14
14
|
end
|
15
15
|
|
16
16
|
def electricity_actual_threshold
|
17
|
-
|
17
|
+
get_electricity('0-0:17.0.0')
|
18
18
|
end
|
19
19
|
|
20
20
|
def electra_import_low
|
21
|
-
|
21
|
+
get_electricity('1-0:1.8.1')
|
22
22
|
end
|
23
23
|
|
24
24
|
def electra_import_normal
|
25
|
-
|
25
|
+
get_electricity('1-0:1.8.2')
|
26
26
|
end
|
27
27
|
|
28
28
|
def electra_export_low
|
29
|
-
|
29
|
+
get_electricity('1-0:2.8.1')
|
30
30
|
end
|
31
31
|
|
32
32
|
def electra_export_normal
|
33
|
-
|
33
|
+
get_electricity('1-0:2.8.2')
|
34
34
|
end
|
35
35
|
|
36
|
+
#Only for backward compatibility
|
36
37
|
def actual_electra
|
37
|
-
|
38
|
+
electra_import_actual
|
39
|
+
end
|
40
|
+
|
41
|
+
def electra_import_actual
|
42
|
+
get_electricity('1-0:1.7.0') * 1000
|
43
|
+
end
|
44
|
+
|
45
|
+
def electra_export_actual
|
46
|
+
get_electricity('1-0:2.7.0') * 1000
|
38
47
|
end
|
39
48
|
|
40
49
|
def electricity(options)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
else
|
45
|
-
get_electricity("1-0:#{first_electricity_code(options[:type])}.8.#{second_electricity_code(options[:tariff])}")
|
46
|
-
end
|
50
|
+
message = "electra_#{options[:type].to_s}_"
|
51
|
+
if options[:actual] == true
|
52
|
+
send(message + 'actual')
|
47
53
|
else
|
48
|
-
|
54
|
+
send(message + "#{options[:tariff].to_s}")
|
49
55
|
end
|
50
56
|
end
|
51
57
|
|
52
58
|
private
|
53
59
|
|
54
60
|
def get_electricity(obis_code)
|
55
|
-
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
def get_actual_electricity(type)
|
60
|
-
power = get_electricity("1-0:#{first_electricity_code(type)}\.7\.0")
|
61
|
-
(power * 1000).to_i if power#Return as watts instead of kW
|
62
|
-
end
|
63
|
-
|
64
|
-
def first_electricity_code(code)
|
65
|
-
case code
|
66
|
-
when :import; '1'
|
67
|
-
when :export; '2'
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def second_electricity_code(tariff)
|
72
|
-
case tariff
|
73
|
-
when :low; 1
|
74
|
-
when :normal; 2
|
75
|
-
end
|
61
|
+
result = obis_records[obis_code]
|
62
|
+
result ? result.first.to_f : 0.0
|
76
63
|
end
|
77
64
|
|
78
65
|
end
|
79
66
|
|
80
|
-
end
|
67
|
+
end
|
data/lib/parse_p1/gas.rb
CHANGED
@@ -5,24 +5,39 @@ module ParseP1
|
|
5
5
|
module Gas
|
6
6
|
|
7
7
|
def gas_meter_id
|
8
|
-
|
8
|
+
obis_records['0-1:96.1.0'].first
|
9
9
|
end
|
10
10
|
|
11
11
|
#Only 2 digits for year!
|
12
12
|
def last_hourly_reading_gas
|
13
|
-
result =
|
13
|
+
result = get_gas(0)
|
14
14
|
DateTime.new(('20'+result[0..1]).to_i, result[2..3].to_i, result[4..5].to_i, result[6..7].to_i, result[8..9].to_i) if result
|
15
15
|
end
|
16
16
|
|
17
|
+
#TODO remove this silly method?
|
17
18
|
def measurement_unit_gas
|
18
|
-
|
19
|
+
'm3'
|
19
20
|
end
|
20
21
|
|
21
22
|
def gas_usage
|
22
|
-
result =
|
23
|
+
result = get_gas(-1)
|
23
24
|
result.to_f if result
|
24
25
|
end
|
25
26
|
|
27
|
+
private
|
28
|
+
|
29
|
+
def get_gas(index_of_values)
|
30
|
+
gas_obis_codes.each do |obis_code|
|
31
|
+
@result = obis_records[obis_code]
|
32
|
+
break unless @result.nil?
|
33
|
+
end
|
34
|
+
@result[index_of_values] if @result
|
35
|
+
end
|
36
|
+
|
37
|
+
def gas_obis_codes
|
38
|
+
['0-1:24.3.0', '0-1:24.2.1', '0-2:24.1.0', '0-2:24.3.0', '0-2:24.2.1', '0-2:24.4.0']
|
39
|
+
end
|
40
|
+
|
26
41
|
end
|
27
42
|
|
28
|
-
end
|
43
|
+
end
|
data/lib/parse_p1/version.rb
CHANGED
data/parse_p1.gemspec
CHANGED
@@ -11,7 +11,6 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.summary = %q{Parsing P1 Companion Standard used by Dutch Smart Meters}
|
12
12
|
s.description = %q{Parsing P1 Companion Standard used by Dutch Smart Meters. Used in combination with a Nanode posting the P1 data to emonWeb.org}
|
13
13
|
s.licenses = ['MIT']
|
14
|
-
s.rubyforge_project = "parse_p1"
|
15
14
|
|
16
15
|
s.extra_rdoc_files = [
|
17
16
|
'CHANGELOG',
|
@@ -24,6 +23,7 @@ Gem::Specification.new do |s|
|
|
24
23
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
25
24
|
s.require_paths = ["lib"]
|
26
25
|
|
26
|
+
s.add_development_dependency 'minitest'
|
27
27
|
s.add_development_dependency 'shoulda'
|
28
28
|
s.add_development_dependency 'guard'
|
29
29
|
s.add_development_dependency 'guard-test'
|
data/test/helper.rb
CHANGED
@@ -0,0 +1,99 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
|
5
|
+
class TestParseP1_IskraMT171Meter < Test::Unit::TestCase
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@data = "/XMX5XMXABCE100085870\r\n\r\n0-0:96.1.1(31333836343734322020202020202020)\r\n1-0:1.8.1(00477.462*kWh)\r\n1-0:1.8.2(00546.069*kWh)\r\n1-0:2.8.1(00013.172*kWh)\r\n1-0:2.8.2(00031.349*kWh)\r\n0-0:96.14.0(0001)\r\n1-0:1.7.0(0000.23*kW)\r\n1-0:2.7.0(0000.00*kW)\r\n0-0:17.0.0(999*A)\r\n0-0:96.3.10(1)\r\n0-0:96.13.1()\r\n0-0:96.13.0()\r\n0-1:96.1.0(3238303131303038333134303934333133)\r\n0-1:24.1.0(03)\r\n0-1:24.3.0(131013140000)(08)(60)(1)(0-1:24.2.0)(m3)\r\n(00143.136)\r\n0-1:24.4.0(1)\r\n!"
|
9
|
+
|
10
|
+
@p1 = ParseP1::Base.new(@data)
|
11
|
+
end
|
12
|
+
|
13
|
+
should 'tell if string is P1 valid' do
|
14
|
+
assert_equal true, @p1.valid?
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'Device identifiers' do
|
18
|
+
|
19
|
+
should 'return the device_id of the meter' do
|
20
|
+
assert_equal 'XMX5XMXABCE100085870', @p1.device_id
|
21
|
+
end
|
22
|
+
|
23
|
+
#Sn (n=0..96), octet string is NOT true
|
24
|
+
should 'return the electra meter identifier of the meter' do
|
25
|
+
assert_equal '31333836343734322020202020202020', @p1.electra_meter_id
|
26
|
+
end
|
27
|
+
|
28
|
+
#Sn (n=0..96) octet string
|
29
|
+
should 'return the gas meter identifier of the meter' do
|
30
|
+
assert_equal '3238303131303038333134303934333133', @p1.gas_meter_id
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'Electricity data' do
|
36
|
+
|
37
|
+
#S4 tag 4 bit string is NOT true
|
38
|
+
should 'return the electricity tariff indicator' do
|
39
|
+
assert_equal 1, @p1.electricity_tariff_indicator
|
40
|
+
end
|
41
|
+
|
42
|
+
#F4(1,1)
|
43
|
+
should 'return the electricity actual threshold' do
|
44
|
+
assert_equal 999.0, @p1.electricity_actual_threshold
|
45
|
+
end
|
46
|
+
|
47
|
+
#F9 (3,3)
|
48
|
+
should 'return imported electricty with low tarif' do
|
49
|
+
assert_equal 477.462, @p1.electricity(:type => :import, :tariff => :low)
|
50
|
+
assert_equal 477.462, @p1.electra_import_low
|
51
|
+
end
|
52
|
+
|
53
|
+
#F9 (3,3)
|
54
|
+
should 'return imported electricty with normal tarif' do
|
55
|
+
assert_equal 546.069, @p1.electricity(:type => :import, :tariff => :normal)
|
56
|
+
assert_equal 546.069, @p1.electra_import_normal
|
57
|
+
end
|
58
|
+
|
59
|
+
#F9 (3,3)
|
60
|
+
should 'return electricty produced by client low tarif' do
|
61
|
+
assert_equal 13.172, @p1.electricity(:type => :export, :tariff => :low)
|
62
|
+
assert_equal 13.172, @p1.electra_export_low
|
63
|
+
end
|
64
|
+
|
65
|
+
#F9 (3,3)
|
66
|
+
should 'return electricty produced by client normal tarif' do
|
67
|
+
assert_equal 31.349, @p1.electricity(:type => :export, :tariff => :normal)
|
68
|
+
assert_equal 31.349, @p1.electra_export_normal
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'Actual data' do
|
72
|
+
|
73
|
+
#F5 (3,3)
|
74
|
+
should 'return actual power imported' do
|
75
|
+
assert_equal 230, @p1.electricity(:type => :import, :actual => true)
|
76
|
+
assert_equal 230, @p1.actual_electra
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'Gas data' do
|
84
|
+
|
85
|
+
should 'return the last hourly reading of gas usage' do
|
86
|
+
assert_equal DateTime.new(2013,10,13,14,0), @p1.last_hourly_reading_gas
|
87
|
+
end
|
88
|
+
|
89
|
+
should 'return the measurement unit of gas usage' do
|
90
|
+
assert_equal 'm3', @p1.measurement_unit_gas
|
91
|
+
end
|
92
|
+
|
93
|
+
should 'return the total usage of gas' do
|
94
|
+
assert_equal 143.136, @p1.gas_usage
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
|
5
|
+
class TestParseP1LandisGyrE350 < Test::Unit::TestCase
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@data = "/ABA5LGAAGGB231007559\n\n1-3:0.2.8(40)\n0-0:1.0.0(150407214315S)\n0-0:96.1.1(4190303034303031356660323031353135)\n1-0:1.8.1(002622.819*kWh)\n1-0:2.8.1(000079.439*kWh)\n1-0:1.8.2(001693.579*kWh)\n1-0:2.8.2(000215.374*kWh)\n0-0:96.14.0(0002)\n1-0:1.7.0(00.524*kW)\n1-0:2.7.0(01.230*kW)\n0-0:17.0.0(999.9*kW)\n0-0:96.3.10(1)\n0-0:96.7.21(00003)\n0-0:96.7.9(00001)\n1-0:99.97.0(1)(0-0:96.7.19)(150327114234W)(0000007487*s)\n1-0:32.32.0(00000)\n1-0:32.36.0(00000)\n0-0:96.13.1()\n0-0:96.13.0()\n1-0:31.7.0(002*A)\n1-0:21.7.0(00.524*kW)\n1-0:22.7.0(00.000*kW)\n0-1:24.1.0(003)\n0-1:96.1.0(4736303136353631323035999235153337)\n0-1:24.2.1(150407210000S)(02638.655*m3)\n0-1:24.4.0(1)\n!"
|
9
|
+
@p1 = ParseP1::Base.new(@data)
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'Device identifiers' do
|
13
|
+
|
14
|
+
should 'return the device_id of the meter' do
|
15
|
+
assert_equal 'ABA5LGAAGGB231007559', @p1.device_id
|
16
|
+
end
|
17
|
+
|
18
|
+
should 'return the electra meter identifier of the meter' do
|
19
|
+
assert_equal '4190303034303031356660323031353135', @p1.electra_meter_id
|
20
|
+
end
|
21
|
+
|
22
|
+
should 'return the gas meter identifier of the meter' do
|
23
|
+
assert_equal '4736303136353631323035999235153337', @p1.gas_meter_id
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'Electricity data' do
|
29
|
+
|
30
|
+
#S4 tag 4 bit string is NOT true
|
31
|
+
should 'return the electricity tariff indicator' do
|
32
|
+
assert_equal 2, @p1.electricity_tariff_indicator
|
33
|
+
end
|
34
|
+
|
35
|
+
#F4(1,1)
|
36
|
+
should 'return the electricity actual threshold' do
|
37
|
+
assert_equal 999.9, @p1.electricity_actual_threshold
|
38
|
+
end
|
39
|
+
|
40
|
+
#F9 (3,3)
|
41
|
+
should 'return imported electricty with low tarif' do
|
42
|
+
assert_equal 2622.819, @p1.electricity(:type => :import, :tariff => :low)
|
43
|
+
assert_equal 2622.819, @p1.electra_import_low
|
44
|
+
end
|
45
|
+
|
46
|
+
#F9 (3,3)
|
47
|
+
should 'return imported electricty with normal tarif' do
|
48
|
+
assert_equal 1693.579, @p1.electricity(:type => :import, :tariff => :normal)
|
49
|
+
assert_equal 1693.579, @p1.electra_import_normal
|
50
|
+
end
|
51
|
+
|
52
|
+
#F9 (3,3)
|
53
|
+
should 'return electricty produced by client low tarif' do
|
54
|
+
assert_equal 79.439, @p1.electricity(:type => :export, :tariff => :low)
|
55
|
+
assert_equal 79.439, @p1.electra_export_low
|
56
|
+
end
|
57
|
+
|
58
|
+
#F9 (3,3)
|
59
|
+
should 'return electricty produced by client normal tarif' do
|
60
|
+
assert_equal 215.374, @p1.electricity(:type => :export, :tariff => :normal)
|
61
|
+
assert_equal 215.374, @p1.electra_export_normal
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'Actual data' do
|
65
|
+
|
66
|
+
#F5 (3,3)
|
67
|
+
should 'return actual power imported' do
|
68
|
+
assert_equal 524, @p1.electricity(:type => :import, :actual => true)
|
69
|
+
assert_equal 524, @p1.actual_electra
|
70
|
+
assert_equal 524, @p1.electra_import_actual
|
71
|
+
end
|
72
|
+
|
73
|
+
#F5 (3,3)
|
74
|
+
should 'return actual power in case of a low tarif' do
|
75
|
+
assert_equal 1230, @p1.electricity(:type => :export, :actual => true)
|
76
|
+
assert_equal 1230, @p1.electra_export_actual
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'Gas data' do
|
84
|
+
|
85
|
+
should 'return the last hourly reading of gas usage' do
|
86
|
+
assert_equal DateTime.new(2015,4,7,21,0), @p1.last_hourly_reading_gas
|
87
|
+
end
|
88
|
+
|
89
|
+
should 'return the measurement unit of gas usage' do
|
90
|
+
assert_equal 'm3', @p1.measurement_unit_gas
|
91
|
+
end
|
92
|
+
|
93
|
+
should 'return the total usage of gas' do
|
94
|
+
assert_equal 2638.655, @p1.gas_usage
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
data/test/parse_p1_test.rb
CHANGED
@@ -11,10 +11,6 @@ class TestParseP1 < Test::Unit::TestCase
|
|
11
11
|
@p1 = ParseP1::Base.new(@data)
|
12
12
|
end
|
13
13
|
|
14
|
-
should 'return the p1_string' do
|
15
|
-
assert_equal @data, @p1.data
|
16
|
-
end
|
17
|
-
|
18
14
|
should 'tell if string is P1 valid' do
|
19
15
|
assert_equal true, @p1.valid?
|
20
16
|
end
|
@@ -22,15 +18,16 @@ class TestParseP1 < Test::Unit::TestCase
|
|
22
18
|
context 'Device identifiers' do
|
23
19
|
|
24
20
|
should 'return the device_id of the meter' do
|
25
|
-
|
21
|
+
assert_equal 'ABc1\1AB123-4567', @p1.device_id
|
26
22
|
end
|
27
23
|
|
28
24
|
#Sn (n=0..96), octet string is NOT true
|
29
25
|
should 'return the electra meter identifier of the meter' do
|
26
|
+
# '4530303034303031353330323031353134'
|
30
27
|
assert_equal '1A123456789012345678901234567890', @p1.electra_meter_id
|
31
28
|
end
|
32
29
|
|
33
|
-
#Sn (n=0..96) octet string
|
30
|
+
#Sn (n=0..96) octet string
|
34
31
|
should 'return the gas meter identifier of the meter' do
|
35
32
|
assert_equal '1234567890123456789012345678901234', @p1.gas_meter_id
|
36
33
|
end
|
@@ -49,11 +46,6 @@ class TestParseP1 < Test::Unit::TestCase
|
|
49
46
|
assert_equal 999.0, @p1.electricity_actual_threshold
|
50
47
|
end
|
51
48
|
|
52
|
-
#F9 (3,3)
|
53
|
-
should 'return electricity with a corresponding obis code' do
|
54
|
-
assert_equal 136.787, @p1.electricity('1-0:1.8.1')
|
55
|
-
end
|
56
|
-
|
57
49
|
#F9 (3,3)
|
58
50
|
should 'return imported electricty with low tarif' do
|
59
51
|
assert_equal 136.787, @p1.electricity(:type => :import, :tariff => :low)
|
@@ -83,12 +75,14 @@ class TestParseP1 < Test::Unit::TestCase
|
|
83
75
|
#F5 (3,3)
|
84
76
|
should 'return actual power imported' do
|
85
77
|
assert_equal 3200, @p1.electricity(:type => :import, :actual => true)
|
86
|
-
assert_equal 3200, @p1.actual_electra
|
78
|
+
assert_equal 3200, @p1.actual_electra #Still in use for backward compability
|
79
|
+
assert_equal 3200, @p1.electra_import_actual
|
87
80
|
end
|
88
81
|
|
89
82
|
#F5 (3,3)
|
90
83
|
should 'return actual power in case of a low tarif' do
|
91
84
|
assert_equal 120, @p1.electricity(:type => :export, :actual => true)
|
85
|
+
assert_equal 120, @p1.electra_export_actual
|
92
86
|
end
|
93
87
|
|
94
88
|
end
|
@@ -113,27 +107,15 @@ class TestParseP1 < Test::Unit::TestCase
|
|
113
107
|
|
114
108
|
context 'Gas data send through RF (different OBIS codes)' do
|
115
109
|
|
116
|
-
setup do
|
117
|
-
#Different OBIS codes for RF gas measurement:
|
118
|
-
# => 0-2:24.1.0
|
119
|
-
# => 0-2:96.1.0
|
120
|
-
# => 0-2:24.3.0
|
121
|
-
# => 0-2:24.2.1
|
122
|
-
# => 0-2:24.4.0
|
123
|
-
data = "sBs\u0012C\u0002\u0002\nK*r\"CKR[Wh)\r\n1-0:2.8.1(00000.000*kWh)\r\n1-0:2.8.2(00000.\r\n/ABc1\\1AB123-4567\r\n\r\n0-0:96.1.1(1A123456789012345678901234567890)\r\n1-0:1.8.1(00136.787*kWh)\r\n1-0:1.8.2(00131.849*kWh)\r\n1-0:2.8.1(00002.345*kWh)\r\n1-0:2.8.2(00054.976*kWh)\r\n0-0:96.14.0(0002)\r\n1-0:1.7.0(0003.20*kW)\r\n1-0:2.7.0(0000.12*kW)\r\n0-0:17.0.0(0999.00*kW)\r\n0-0:96.3.10(1)\r\n0-0:96.13.1()\r\n0-0:96.13.0()\r\n0-2:24.1.0(3)\r\n0-2:96.1.0(1234567890123456789012345678901234)\r\n0-2:24.3.0(120502150000)(00)(60)(1)(0-2:24.2.1)(m3)\r\n(00092.112)\r\n0-2:24.4.0(1)\r\n!"
|
124
|
-
@p2 = ParseP1::Base.new(@data)
|
125
|
-
end
|
126
|
-
|
127
|
-
should 'return the last hourly reading of gas usage' do
|
128
|
-
assert_equal DateTime.new(2012,5,2,15,0), @p2.last_hourly_reading_gas
|
129
|
-
end
|
130
|
-
|
131
|
-
should 'return the measurement unit of gas usage' do
|
132
|
-
assert_equal 'm3', @p2.measurement_unit_gas
|
133
|
-
end
|
134
|
-
|
135
110
|
should 'return the total usage of gas' do
|
136
|
-
|
111
|
+
def p1_data(obis_code)
|
112
|
+
"sBs\u0012C\u0002\u0002\nK*r\"CKR[Wh)\r\n1-0:2.8.1(00000.000*kWh)\r\n1-0:2.8.2(00000.\r\n/ABc1\\1AB123-4567\r\n\r\n0-0:96.1.1(1A123456789012345678901234567890)\r\n1-0:1.8.1(00136.787*kWh)\r\n1-0:1.8.2(00131.849*kWh)\r\n1-0:2.8.1(00002.345*kWh)\r\n1-0:2.8.2(00054.976*kWh)\r\n0-0:96.14.0(0002)\r\n1-0:1.7.0(0003.20*kW)\r\n1-0:2.7.0(0000.12*kW)\r\n0-0:17.0.0(0999.00*kW)\r\n0-0:96.3.10(1)\r\n0-0:96.13.1()\r\n0-0:96.13.0()\r\n0-1:24.1.0(3)\r\n0-2:96.1.0(1234567890123456789012345678901234)\r\n" +obis_code + "(120502150000)(00)(60)(1)(0-2:24.2.1)(m3)\r\n(00092.112)\r\n0-1:24.4.0(1)\r\n!"
|
113
|
+
end
|
114
|
+
|
115
|
+
['0-2:24.1.0', '0-2:24.3.0', '0-2:24.2.1', '0-2:24.4.0'].each do |obis_code|
|
116
|
+
p1 = ParseP1::Base.new(p1_data(obis_code))
|
117
|
+
assert_equal 92.112, p1.gas_usage
|
118
|
+
end
|
137
119
|
end
|
138
120
|
|
139
121
|
end
|
@@ -151,9 +133,9 @@ class TestParseP1 < Test::Unit::TestCase
|
|
151
133
|
should 'tell if a very meshed string is P1 valid' do
|
152
134
|
@irregular_data.each do |record|
|
153
135
|
p1 = ParseP1::Base.new(record)
|
154
|
-
|
136
|
+
assert p1.valid?
|
155
137
|
assert p1.gas_usage.is_a?(Float)
|
156
|
-
assert p1.actual_electra.is_a?(
|
138
|
+
assert p1.actual_electra.is_a?(Float)
|
157
139
|
assert p1.device_id.is_a?(String)
|
158
140
|
assert p1.electra_meter_id.is_a?(String)
|
159
141
|
assert p1.gas_meter_id.is_a?(String)
|
@@ -166,4 +148,4 @@ class TestParseP1 < Test::Unit::TestCase
|
|
166
148
|
|
167
149
|
end
|
168
150
|
|
169
|
-
end
|
151
|
+
end
|
metadata
CHANGED
@@ -1,62 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parse_p1
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Frank Oxener
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-04-16 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
14
27
|
- !ruby/object:Gem::Dependency
|
15
28
|
name: shoulda
|
16
29
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
30
|
requirements:
|
19
|
-
- -
|
31
|
+
- - ">="
|
20
32
|
- !ruby/object:Gem::Version
|
21
33
|
version: '0'
|
22
34
|
type: :development
|
23
35
|
prerelease: false
|
24
36
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
37
|
requirements:
|
27
|
-
- -
|
38
|
+
- - ">="
|
28
39
|
- !ruby/object:Gem::Version
|
29
40
|
version: '0'
|
30
41
|
- !ruby/object:Gem::Dependency
|
31
42
|
name: guard
|
32
43
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
44
|
requirements:
|
35
|
-
- -
|
45
|
+
- - ">="
|
36
46
|
- !ruby/object:Gem::Version
|
37
47
|
version: '0'
|
38
48
|
type: :development
|
39
49
|
prerelease: false
|
40
50
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
51
|
requirements:
|
43
|
-
- -
|
52
|
+
- - ">="
|
44
53
|
- !ruby/object:Gem::Version
|
45
54
|
version: '0'
|
46
55
|
- !ruby/object:Gem::Dependency
|
47
56
|
name: guard-test
|
48
57
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
58
|
requirements:
|
51
|
-
- -
|
59
|
+
- - ">="
|
52
60
|
- !ruby/object:Gem::Version
|
53
61
|
version: '0'
|
54
62
|
type: :development
|
55
63
|
prerelease: false
|
56
64
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
65
|
requirements:
|
59
|
-
- -
|
66
|
+
- - ">="
|
60
67
|
- !ruby/object:Gem::Version
|
61
68
|
version: '0'
|
62
69
|
description: Parsing P1 Companion Standard used by Dutch Smart Meters. Used in combination
|
@@ -70,9 +77,10 @@ extra_rdoc_files:
|
|
70
77
|
- LICENSE.txt
|
71
78
|
- README.md
|
72
79
|
files:
|
73
|
-
- .gitignore
|
74
|
-
- .
|
75
|
-
- .
|
80
|
+
- ".gitignore"
|
81
|
+
- ".ruby-gemset"
|
82
|
+
- ".ruby-version"
|
83
|
+
- ".travis.yml"
|
76
84
|
- CHANGELOG
|
77
85
|
- Gemfile
|
78
86
|
- Guardfile
|
@@ -90,38 +98,35 @@ files:
|
|
90
98
|
- lib/parse_p1/version.rb
|
91
99
|
- parse_p1.gemspec
|
92
100
|
- test/helper.rb
|
101
|
+
- test/parse_p1_IskraMT171_meter_test.rb
|
102
|
+
- test/parse_p1_landisgyr_e350_test.rb
|
93
103
|
- test/parse_p1_test.rb
|
94
104
|
homepage: http://github.com/dovadi/parse_p1
|
95
105
|
licenses:
|
96
106
|
- MIT
|
107
|
+
metadata: {}
|
97
108
|
post_install_message:
|
98
109
|
rdoc_options: []
|
99
110
|
require_paths:
|
100
111
|
- lib
|
101
112
|
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
-
none: false
|
103
113
|
requirements:
|
104
|
-
- -
|
114
|
+
- - ">="
|
105
115
|
- !ruby/object:Gem::Version
|
106
116
|
version: '0'
|
107
|
-
segments:
|
108
|
-
- 0
|
109
|
-
hash: 1064997931082939182
|
110
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
-
none: false
|
112
118
|
requirements:
|
113
|
-
- -
|
119
|
+
- - ">="
|
114
120
|
- !ruby/object:Gem::Version
|
115
121
|
version: '0'
|
116
|
-
segments:
|
117
|
-
- 0
|
118
|
-
hash: 1064997931082939182
|
119
122
|
requirements: []
|
120
|
-
rubyforge_project:
|
121
|
-
rubygems_version:
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.4.5
|
122
125
|
signing_key:
|
123
|
-
specification_version:
|
126
|
+
specification_version: 4
|
124
127
|
summary: Parsing P1 Companion Standard used by Dutch Smart Meters
|
125
128
|
test_files:
|
126
129
|
- test/helper.rb
|
130
|
+
- test/parse_p1_IskraMT171_meter_test.rb
|
131
|
+
- test/parse_p1_landisgyr_e350_test.rb
|
127
132
|
- test/parse_p1_test.rb
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm use 1.9.3@parse_p1 --create
|