I'm trying to detect accidentally power disconnects when a player removes an electric pole.
My approach:
- For each power_pole in LuaEntity.neighbours['copper']:
- Check power_pole.electric_network_statistics
- If consumption >> production, raise a warning/notification
- Entities don't seem to appear on electric_network_statistics unless they have been connected/working at some point. E.g. the 'demand/consumption' of never-powered insterters does not appear
- I have to record the neighbors on_pre_player_mined_item, but wait until the pole is actually removed and then maybe 1 more tick for the actual power statistics to update. This feels clumsy.
- The electric_network_id seems to change for the entire network anytime a pole is added. This makes it hard to keep track of all the global power networks in my own table, their lifetimes, and check for recent changes. For example, it would be useful to exclude new power networks with age < 5 mins (or some configurable setting) to avoid alerting for things the player is currently building.
I am looking for feedback on the overall approach, or alternative ways of doing this that I might be overlooking. Any thoughts?