diff --git a/app/helpers/InSyncState.rb b/app/helpers/InSyncState.rb index 1e818c7..9e2fb25 100644 --- a/app/helpers/InSyncState.rb +++ b/app/helpers/InSyncState.rb @@ -47,9 +47,8 @@ class InSyncState < StatePattern::State end def handle_frame(frame_lines) - # gas flag - next_is_gas = false - + gas_pattern = /^([0-1:24\.2\.1]+)\((\d{12}[SW])\)\((\d{5}\.\d{3})\*m3\)$/ + # prepare DB record last_reading = Reading.last reading = Reading.new @@ -80,13 +79,10 @@ class InSyncState < StatePattern::State end if line.match(/0-0:96.14.0/) # Hoog/laag tarief reading.high_tarif = line.split(/0-0:96.14.0\(|\)/).join.eql?("0002") - end - if next_is_gas && line.match(/\(/) - next_is_gas = false - reading.total_m3_gas_consumed = line.split(/\(|\)/).join.to_f - end - if line.match(/0-1:24.3.0/) # Gas verbruik (1x per uur een nieuwe stand) - next_is_gas = true # the usage is on the next line + end + if match = line.match(/0-1:24.3.0/) # Gas verbruik (1x per uur een nieuwe stand) + p "Gas reading: #{match[1]} (#{match[2]})" + reading.total_m3_gas_consumed = match[3].to_f end }