Which is line 38?
I think your problem is going to be that you are trying to do arithmetic with item.state, and unlike numbers, state objects don’t have arithmetic methods. (item.state can have values “banana”, OFF, etc. not just numeric)
You’ll need to cast as numeric types.