# -*- coding: utf-8 -*-
# 只读本目录合成输入，不联网、不修改设备。
import csv
from pathlib import Path
state='idle'; plays=0
for r in csv.DictReader((Path(__file__).parent/'synthetic.csv').open(encoding='utf-8-sig')):
    assert state==r['before']
    event=r['event']; occupied=int(r['occupied']); new=0
    if state=='idle' and event=='enter': state='playing'; new=1
    elif state=='playing' and event=='end': state='wait-clear' if occupied else 'idle'
    elif state=='wait-clear' and event=='leave': state='idle'
    assert state==r['after'] and new==int(r['new_play']),r
    plays+=new
assert plays==2
print('合成占用状态机通过：驻留结束不自动重播，离场重新武装。')
