It would appear that LuaEntity.is_connected_to_electric_network() doesn't actually tell you if an entity is connected to an electric network or not.
Instead, it tells you if the entity is connected to an electric network that has an energy source.
I.e.
Calling this on the assembler returns false, even though it is clearly connected to an electric network.
If i now then add an electrical source like an accumulator or a steam engine, now it will return true regardless if there is any electricity in it or not.
This seems like a bug because even though it is connected to an electric network, the flashing alert icon says it's not connected to anything, even though it is.
[0.17.79] LuaEntity.is_connected_to_electric_network() is wrong
Re: [0.17.79] LuaEntity.is_connected_to_electric_network() is wrong
I will count this as Not a bug
is_connected_to_electric_network is exactly same check as for disconnected icon. It is implemented to look for energy producers and is looks intentional.
If you want to detect if entity is in range of any electric pole, you may use LuaEntity.electric_network_id read: for entities outside of any power poles it will be nil. For entities in range of at least one power pole you will get non-nil value. In case of multiple networks in range you will get ID of only one of them, but still non-nil.
is_connected_to_electric_network is exactly same check as for disconnected icon. It is implemented to look for energy producers and is looks intentional.
If you want to detect if entity is in range of any electric pole, you may use LuaEntity.electric_network_id read: for entities outside of any power poles it will be nil. For entities in range of at least one power pole you will get non-nil value. In case of multiple networks in range you will get ID of only one of them, but still non-nil.