3030)
3131from frequenz .sdk .microgrid .client import Connection
3232from frequenz .sdk .microgrid .component import Component , ComponentCategory
33+ from tests .timeseries .mock_microgrid import MockMicrogrid
3334
3435from ..conftest import SAFETY_TIMEOUT
3536from ..power .test_distribution_algorithm import Bound , Metric , battery_msg , inverter_msg
@@ -81,15 +82,10 @@ def component_graph(self) -> tuple[set[Component], set[Connection]]:
8182
8283 async def test_constructor (self , mocker : MockerFixture ) -> None :
8384 """Test if gets all necessary data."""
84- components , connections = self .component_graph ()
85- mock_microgrid = MockMicrogridClient (components , connections )
86- mock_microgrid .initialize (mocker )
87-
88- attrs = {"get_working_batteries.return_value" : {306 }}
89- mocker .patch (
90- "frequenz.sdk.actor.power_distributing.power_distributing.BatteryPoolStatus" ,
91- return_value = MagicMock (spec = BatteryPoolStatus , ** attrs ),
92- )
85+ mockgrid = MockMicrogrid (grid_side_meter = True )
86+ mockgrid .add_batteries (2 )
87+ mockgrid .add_batteries (1 , no_meter = True )
88+ await mockgrid .start (mocker )
9389
9490 channel = Broadcast [Request ]("power_distributor" )
9591 channel_registry = ChannelRegistry (name = "power_distributor" )
@@ -100,9 +96,28 @@ async def test_constructor(self, mocker: MockerFixture) -> None:
10096 battery_status_sender = battery_status_channel .new_sender (),
10197 )
10298
103- assert distributor ._bat_inv_map == {106 : 105 , 206 : 205 , 306 : 305 }
104- assert distributor ._inv_bat_map == {105 : 106 , 205 : 206 , 305 : 306 }
99+ assert distributor ._bat_inv_map == {9 : 8 , 19 : 18 , 29 : 28 }
100+ assert distributor ._inv_bat_map == {8 : 9 , 18 : 19 , 28 : 29 }
101+
102+ await distributor ._stop_actor ()
103+ await mockgrid .cleanup ()
104+
105+ # Test if it works without grid side meter
106+ mockgrid = MockMicrogrid (grid_side_meter = False )
107+ mockgrid .add_batteries (1 )
108+ mockgrid .add_batteries (2 , no_meter = True )
109+ await mockgrid .start (mocker )
110+ distributor = PowerDistributingActor (
111+ requests_receiver = channel .new_receiver (),
112+ channel_registry = channel_registry ,
113+ battery_status_sender = battery_status_channel .new_sender (),
114+ )
115+
116+ assert distributor ._bat_inv_map == {9 : 8 , 19 : 18 , 29 : 28 }
117+ assert distributor ._inv_bat_map == {8 : 9 , 18 : 19 , 28 : 29 }
118+
105119 await distributor ._stop_actor ()
120+ await mockgrid .cleanup ()
106121
107122 async def init_mock_microgrid (self , mocker : MockerFixture ) -> MockMicrogridClient :
108123 """Create mock microgrid and send initial data from the components.
0 commit comments