parse_p1 0.0.9 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ * 0.1.0
2
+ Parse Gas values with different OBIS codes because of RF module on Gas meter
3
+
1
4
  * 0.0.9
2
5
  Another improvement of irregular data
3
6
 
data/lib/parse_p1/gas.rb CHANGED
@@ -5,21 +5,21 @@ module ParseP1
5
5
  module Gas
6
6
 
7
7
  def gas_meter_id
8
- match_within_one_p1_record('1:96\.1\.0\S(\d{1,96})\S')
8
+ match_within_one_p1_record('[1|2]:96\.1\.0\S(\d{1,96})\S')
9
9
  end
10
10
 
11
11
  #Only 2 digits for year!
12
12
  def last_hourly_reading_gas
13
- result = match_within_one_p1_record('0-1:24\.3\.0\S(\d{12})\S')
13
+ result = match_within_one_p1_record('0-[1|2]:24\.3\.0\S(\d{12})\S')
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
17
  def measurement_unit_gas
18
- match_within_one_p1_record('0-1:24\.2\.1\S\S(\w+)\S')
18
+ match_within_one_p1_record('0-[1|2]:24\.2\.1\S\S(\w+)\S')
19
19
  end
20
20
 
21
21
  def gas_usage
22
- result = match_within_one_p1_record('\S0-1:24\.2\.1\S\S\w+\S\W{1,2}\S(\d{5}\.\d{3})\S')
22
+ result = match_within_one_p1_record('\S0-[1|2]:24\.2\.1\S\S\w+\S\W{1,2}\S(\d{5}\.\d{3})\S')
23
23
  result.to_f if result
24
24
  end
25
25
 
@@ -1,3 +1,3 @@
1
1
  module ParseP1
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -7,6 +7,7 @@ class TestParseP1 < Test::Unit::TestCase
7
7
  setup do
8
8
  #Data string as received on a Ruby on Rails application with some uncleared data in front of it
9
9
  @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-1:24.1.0(3)\r\n0-1:96.1.0(1234567890123456789012345678901234)\r\n0-1:24.3.0(120502150000)(00)(60)(1)(0-1:24.2.1)(m3)\r\n(00092.112)\r\n0-1:24.4.0(1)\r\n!"
10
+ # @data = "//ISk5\\2MT382-1003\r\n\r\n0-0:96.1.1(5A424556303035303735343938383131)\r\n1-0:1.8.1(01472.740*kWh)\r\n1-0:1.8.2(01664.635*kWh)\r\n1-0:2.8.1(00000.000*kWh)\r\n1-0:2.8.2(00000.001*kWh)\r\n0-0:96.14.0(0001)\r\n1-0:1.7.0(0000.51*kW)\r\n1-0:2.7.0(0000.00*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(3338303034303031323138333338363132)\r\n0-2:24.3.0(130615120000)(00)(60)(1)(0-2:24.2.1)(m3)\r\n(02910.805)\r\n0-2:24.4.0(1)\r\n!"
10
11
  @p1 = ParseP1::Base.new(@data)
11
12
  end
12
13
 
@@ -110,6 +111,33 @@ class TestParseP1 < Test::Unit::TestCase
110
111
 
111
112
  end
112
113
 
114
+ context 'Gas data send through RF (different OBIS codes)' do
115
+
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
+ should 'return the total usage of gas' do
136
+ assert_equal 92.112, @p2.gas_usage
137
+ end
138
+
139
+ end
140
+
113
141
  context 'Data with irregularities' do
114
142
 
115
143
  setup do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parse_p1
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-11 00:00:00.000000000 Z
12
+ date: 2013-06-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: shoulda
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  segments:
108
108
  - 0
109
- hash: -231798999645191839
109
+ hash: 1064997931082939182
110
110
  required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  none: false
112
112
  requirements:
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  segments:
117
117
  - 0
118
- hash: -231798999645191839
118
+ hash: 1064997931082939182
119
119
  requirements: []
120
120
  rubyforge_project: parse_p1
121
121
  rubygems_version: 1.8.25