From e5f2b959e700ce0d36708fb4f0156b8064c21277 Mon Sep 17 00:00:00 2001 From: poorva1209 Date: Fri, 14 Apr 2023 14:32:33 -0700 Subject: [PATCH] resolved issues after testing. calling get context after message bus connection. --- gridappsd/field_interface/agents/agents.py | 22 +++++++++++----------- gridappsd/field_interface/context.py | 5 ++--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/gridappsd/field_interface/agents/agents.py b/gridappsd/field_interface/agents/agents.py index 68ae39b..0ae2f7c 100644 --- a/gridappsd/field_interface/agents/agents.py +++ b/gridappsd/field_interface/agents/agents.py @@ -89,11 +89,6 @@ def __init__(self, def connect(self): - if self.agent_area_dict is None: - context = LocalContext.get_context_by_message_bus( - self.downstream_message_bus) - self.agent_area_dict = context['data'] - if self.upstream_message_bus is not None: self.upstream_message_bus.connect() if self.downstream_message_bus is not None: @@ -101,6 +96,11 @@ def connect(self): if self.downstream_message_bus is None and self.upstream_message_bus is None: raise ValueError( "Either upstream or downstream bus must be specified!") + + if self.agent_area_dict is None: + context = LocalContext.get_context_by_message_bus( + self.downstream_message_bus) + self.agent_area_dict = context['data'] self.subscribe_to_measurement() self.subscribe_to_messages() @@ -230,11 +230,11 @@ def __init__(self, downstream_message_bus_def, agent_config, feeder_dict, simulation_id) - if feeder_dict is not None: + if self.agent_area_dict is not None: feeder = cim.Feeder(mRID=downstream_message_bus_def.id) self.feeder_area = DistributedModel(connection=self.connection, feeder=feeder, - topology=feeder_dict) + topology=self.agent_area_dict) class SwitchAreaAgent(DistributedAgent): @@ -249,10 +249,10 @@ def __init__(self, super().__init__(upstream_message_bus_def, downstream_message_bus_def, agent_config, switch_area_dict, simulation_id) - if switch_area_dict is not None: + if self.agent_area_dict is not None: self.switch_area = SwitchArea(downstream_message_bus_def.id, self.connection) - self.switch_area.initialize_switch_area(switch_area_dict) + self.switch_area.initialize_switch_area(self.agent_area_dict) class SecondaryAreaAgent(DistributedAgent): @@ -267,10 +267,10 @@ def __init__(self, super().__init__(upstream_message_bus_def, downstream_message_bus_def, agent_config, secondary_area_dict, simulation_id) - if secondary_area_dict is not None: + if self.agent_area_dict is not None: self.secondary_area = SecondaryArea(downstream_message_bus_def.id, self.connection) - self.secondary_area.initialize_secondary_area(secondary_area_dict) + self.secondary_area.initialize_secondary_area(self.agent_area_dict) class CoordinatingAgent: diff --git a/gridappsd/field_interface/context.py b/gridappsd/field_interface/context.py index d6fa6c9..35dec86 100644 --- a/gridappsd/field_interface/context.py +++ b/gridappsd/field_interface/context.py @@ -23,9 +23,8 @@ def get_context_by_message_bus(cls, downstream_message_bus: FieldMessageBus): """ request = {'request_type' : 'get_context', - 'downstream_message_bus_id': downstream_message_bus.id, - 'agents': True, - 'devices': True} + 'downstream_message_bus_id': downstream_message_bus.id + } return downstream_message_bus.get_response(t.context_request_queue(downstream_message_bus.id), request) @classmethod