New gas reading logic

This commit is contained in:
Aart van Halteren
2025-07-17 12:30:09 +02:00
parent 40d4956be3
commit 92ae0eee50

View File

@@ -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
}