|
@@ -1,4 +1,4 @@
|
|
-from openleadr import OpenADRClient, OpenADRServer, enable_default_logging
|
|
|
|
|
|
+from openleadr import OpenADRClient, OpenADRServer, enable_default_logging, objects, utils
|
|
import pytest
|
|
import pytest
|
|
import asyncio
|
|
import asyncio
|
|
import datetime
|
|
import datetime
|
|
@@ -197,3 +197,47 @@ async def test_request_event():
|
|
message_type, message_payload = await client.request_event()
|
|
message_type, message_payload = await client.request_event()
|
|
assert message_type == 'oadrResponse'
|
|
assert message_type == 'oadrResponse'
|
|
await server.stop()
|
|
await server.stop()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@pytest.mark.asyncio
|
|
|
|
+async def test_raw_event():
|
|
|
|
+ now = datetime.datetime.now(datetime.timezone.utc)
|
|
|
|
+ server = OpenADRServer(vtn_id='myvtn')
|
|
|
|
+ server.add_handler('on_create_party_registration', on_create_party_registration)
|
|
|
|
+ event = objects.Event(event_descriptor=objects.EventDescriptor(event_id='event001',
|
|
|
|
+ modification_number=0,
|
|
|
|
+ event_status='far',
|
|
|
|
+ market_context='http://marketcontext01'),
|
|
|
|
+ event_signals=[objects.EventSignal(signal_id='signal001',
|
|
|
|
+ signal_type='level',
|
|
|
|
+ signal_name='simple',
|
|
|
|
+ intervals=[objects.Interval(dtstart=now,
|
|
|
|
+ duration=datetime.timedelta(minutes=10),
|
|
|
|
+ signal_payload=1)]),
|
|
|
|
+ objects.EventSignal(signal_id='signal002',
|
|
|
|
+ signal_type='price',
|
|
|
|
+ signal_name='ELECTRICITY_PRICE',
|
|
|
|
+ intervals=[objects.Interval(dtstart=now,
|
|
|
|
+ duration=datetime.timedelta(minutes=10),
|
|
|
|
+ signal_payload=1)])],
|
|
|
|
+ targets=[objects.Target(ven_id='ven123')])
|
|
|
|
+ loop = asyncio.get_event_loop()
|
|
|
|
+ event_callback_future = loop.create_future()
|
|
|
|
+ server.add_raw_event(ven_id='ven123', event=event, callback=partial(event_callback, future=event_callback_future))
|
|
|
|
+
|
|
|
|
+ on_event_future = loop.create_future()
|
|
|
|
+ client = OpenADRClient(ven_name='myven',
|
|
|
|
+ vtn_url='http://localhost:8080/OpenADR2/Simple/2.0b')
|
|
|
|
+ client.add_handler('on_event', partial(on_event_opt_in, future=on_event_future))
|
|
|
|
+
|
|
|
|
+ await server.run_async()
|
|
|
|
+ await client.run()
|
|
|
|
+ event = await on_event_future
|
|
|
|
+ assert len(event['event_signals']) == 2
|
|
|
|
+
|
|
|
|
+ result = await event_callback_future
|
|
|
|
+ assert result == 'optIn'
|
|
|
|
+
|
|
|
|
+ await client.stop()
|
|
|
|
+ await server.stop()
|
|
|
|
+
|