Describe the bug
This is an issue in FeederAgent, SwitchAreaAgent, and SecondaryAreaAgent classes in agents.py. I will use the FeederAgent class to illustrate. self.feeder_area is only defined in the FeederAgent.init() function if self.agent_area_dict is not None. self.agent_area_dict is None if the FeederAgent instance was created with the argument, feeder_dict = None. This is allowed by design as you can call the parent class DistributedAgent.connect() and that will query the proper area context manager to populate self.agent_area_dict. However, feeder_dict is an designed as an attribute of the child class and thus never gets created in this scenario. So an error gets thrown if you try to use it.
To solve this I defined the feeder_dict as None by default in the init function and then created a connect function that calls the parent class's connect function and then proceeds to properly assign feeder_dict.
here is the code example of my proposed solution:
class FeederAgent(DistributedAgent):
def __init__(self,
upstream_message_bus_def: MessageBusDefinition,
downstream_message_bus_def: MessageBusDefinition,
agent_config: Dict,
feeder_dict=None,
simulation_id=None):
super(FeederAgent,
self).__init__(upstream_message_bus_def,
downstream_message_bus_def, agent_config,
feeder_dict, simulation_id)
**self.feeder_area = None
self.downstream_message_bus_def = downstream_message_bus_def**
if self.agent_area_dict is not None:
feeder = cim.Feeder(mRID=self.downstream_message_bus_def.id)
self.feeder_area = DistributedModel(connection=self.connection,
feeder=feeder,
topology=self.agent_area_dict)
**def connect(self):
super().connect()
if self.feeder_area is None:
feeder = cim.Feeder(mRID=self.downstream_message_bus_def.id)
self.feeder_area = DistributedModel(connection=self.connection,
feeder=feeder,
topology=self.agent_area_dict)**
To Reproduce
Steps to reproduce the behavior:
- create an instance of FeederAgent with feeder_dict = None.
- call the instance's connect function.
- try and print the instances feeder_area attribute
Expected behavior
after connect is called feeder_area should be properly defined.
Describe the bug
This is an issue in FeederAgent, SwitchAreaAgent, and SecondaryAreaAgent classes in agents.py. I will use the FeederAgent class to illustrate. self.feeder_area is only defined in the FeederAgent.init() function if self.agent_area_dict is not None. self.agent_area_dict is None if the FeederAgent instance was created with the argument, feeder_dict = None. This is allowed by design as you can call the parent class DistributedAgent.connect() and that will query the proper area context manager to populate self.agent_area_dict. However, feeder_dict is an designed as an attribute of the child class and thus never gets created in this scenario. So an error gets thrown if you try to use it.
To solve this I defined the feeder_dict as None by default in the init function and then created a connect function that calls the parent class's connect function and then proceeds to properly assign feeder_dict.
here is the code example of my proposed solution:
To Reproduce
Steps to reproduce the behavior:
Expected behavior
after connect is called feeder_area should be properly defined.