|
@@ -1,4 +1,5 @@
|
|
|
from pyopenadr.utils import create_message, parse_message, generate_id
|
|
|
+from pyopenadr import enums
|
|
|
from pprint import pprint
|
|
|
from termcolor import colored
|
|
|
from datetime import datetime, timezone, timedelta
|
|
@@ -47,7 +48,7 @@ def create_dummy_event(ven_id):
|
|
|
|
|
|
def test_message(message_type, **data):
|
|
|
message = create_message(message_type, **data)
|
|
|
- #print(message)
|
|
|
+ # print(message)
|
|
|
parsed = parse_message(message)[1]
|
|
|
|
|
|
if parsed == data:
|
|
@@ -142,8 +143,8 @@ test_message('oadrRequestReregistration', ven_id='123ABC')
|
|
|
test_message('oadrRegisterReport', request_id=generate_id(), reports=[{'report_id': generate_id(),
|
|
|
'report_descriptions': [{
|
|
|
'r_id': generate_id(),
|
|
|
- 'report_subject': {'ven_id': '123ABC'},
|
|
|
- 'report_data_source': {'ven_id': '123ABC'},
|
|
|
+ 'report_subjects': [{'ven_id': '123ABC'}],
|
|
|
+ 'report_data_sources': [{'ven_id': '123ABC'}],
|
|
|
'report_type': 'reading',
|
|
|
'reading_type': 'Direct Read',
|
|
|
'market_context': 'http://localhost',
|
|
@@ -154,8 +155,99 @@ test_message('oadrRegisterReport', request_id=generate_id(), reports=[{'report_i
|
|
|
'created_date_time': datetime.now(timezone.utc)}],
|
|
|
ven_id='123ABC',
|
|
|
report_request_id=generate_id())
|
|
|
+test_message('oadrRegisterReport', **{'request_id': '8a4f859883', 'reports': [{'report_id': generate_id(),
|
|
|
+ 'duration': timedelta(seconds=7200),
|
|
|
+ 'report_descriptions': [{'r_id': 'resource1_status',
|
|
|
+ 'report_data_sources': [{'resource_id': 'resource1'}],
|
|
|
+ 'report_type': 'x-resourceStatus',
|
|
|
+ 'reading_type': 'x-notApplicable',
|
|
|
+ 'market_context': 'http://MarketContext1',
|
|
|
+ 'sampling_rate': {'min_period': timedelta(seconds=60), 'max_period': timedelta(seconds=60), 'on_change': False}}],
|
|
|
+ 'report_request_id': '0',
|
|
|
+ 'report_specifier_id': '789ed6cd4e_telemetry_status',
|
|
|
+ 'report_name': 'METADATA_TELEMETRY_STATUS',
|
|
|
+ 'created_date_time': datetime(2019, 11, 20, 15, 4, 52, 638621, tzinfo=timezone.utc)},
|
|
|
+ {'report_id': generate_id(),
|
|
|
+ 'duration': timedelta(seconds=7200),
|
|
|
+ 'report_descriptions': [{'r_id': 'resource1_energy',
|
|
|
+ 'report_data_sources': [{'resource_id': 'resource1'}],
|
|
|
+ 'report_type': 'usage',
|
|
|
+ 'energy_real': {'item_description': 'RealEnergy',
|
|
|
+ 'item_units': 'Wh',
|
|
|
+ 'si_scale_code': 'n'},
|
|
|
+ 'reading_type': 'Direct Read',
|
|
|
+ 'market_context': 'http://MarketContext1',
|
|
|
+ 'sampling_rate': {'min_period': timedelta(seconds=60), 'max_period': timedelta(seconds=60), 'on_change': False}},
|
|
|
+ {'r_id': 'resource1_power',
|
|
|
+ 'report_data_sources': [{'resource_id': 'resource1'}],
|
|
|
+ 'report_type': 'usage',
|
|
|
+ 'power_real': {'item_description': 'RealPower',
|
|
|
+ 'item_units': 'W',
|
|
|
+ 'si_scale_code': 'n',
|
|
|
+ 'power_attributes': {'hertz': 60, 'voltage': 110, 'ac': False}},
|
|
|
+ 'reading_type': 'Direct Read',
|
|
|
+ 'market_context': 'http://MarketContext1',
|
|
|
+ 'sampling_rate': {'min_period': timedelta(seconds=60), 'max_period': timedelta(seconds=60), 'on_change': False}}],
|
|
|
+ 'report_request_id': '0',
|
|
|
+ 'report_specifier_id': '789ed6cd4e_telemetry_usage',
|
|
|
+ 'report_name': 'METADATA_TELEMETRY_USAGE',
|
|
|
+ 'created_date_time': datetime(2019, 11, 20, 15, 4, 52, 638621, tzinfo=timezone.utc)},
|
|
|
+ {'report_id': generate_id(),
|
|
|
+ 'duration': timedelta(seconds=7200),
|
|
|
+ 'report_descriptions': [{'r_id': 'resource1_energy',
|
|
|
+ 'report_data_sources': [{'resource_id': 'resource1'}],
|
|
|
+ 'report_type': 'usage',
|
|
|
+ 'energy_real': {'item_description': 'RealEnergy',
|
|
|
+ 'item_units': 'Wh',
|
|
|
+ 'si_scale_code': 'n'},
|
|
|
+ 'reading_type': 'Direct Read',
|
|
|
+ 'market_context': 'http://MarketContext1',
|
|
|
+ 'sampling_rate': {'min_period': timedelta(seconds=60), 'max_period': timedelta(seconds=60), 'on_change': False}},
|
|
|
+ {'r_id': 'resource1_power',
|
|
|
+ 'report_data_sources': [{'resource_id': 'resource1'}],
|
|
|
+ 'report_type': 'usage',
|
|
|
+ 'power_real': {'item_description': 'RealPower',
|
|
|
+ 'item_units': 'W', 'si_scale_code': 'n',
|
|
|
+ 'power_attributes': {'hertz': 60, 'voltage': 110, 'ac': False}},
|
|
|
+ 'reading_type': 'Direct Read',
|
|
|
+ 'market_context': 'http://MarketContext1',
|
|
|
+ 'sampling_rate': {'min_period': timedelta(seconds=60), 'max_period': timedelta(seconds=60), 'on_change': False}}],
|
|
|
+ 'report_request_id': '0',
|
|
|
+ 'report_specifier_id': '789ed6cd4e_history_usage',
|
|
|
+ 'report_name': 'METADATA_HISTORY_USAGE',
|
|
|
+ 'created_date_time': datetime(2019, 11, 20, 15, 4, 52, 638621, tzinfo=timezone.utc)}], 'ven_id': 's3cc244ee6'})
|
|
|
test_message('oadrResponse', response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()}, ven_id='123ABC')
|
|
|
test_message('oadrResponse', response={'response_code': 200, 'response_description': 'OK', 'request_id': None}, ven_id='123ABC')
|
|
|
-#test_message('oadrUpdatedReport')
|
|
|
-#test_message('oadrUpdateReport')
|
|
|
+test_message('oadrUpdatedReport', response={'response_code': 200, 'response_description': 'OK', 'request_id': generate_id()}, ven_id='123ABC', cancel_report={'request_id': generate_id(), 'report_request_id': [generate_id(), generate_id(), generate_id()], 'report_to_follow': False, 'ven_id': '123ABC'})
|
|
|
+test_message('oadrUpdateReport', request_id=generate_id(), reports=[{'report_id': generate_id(),
|
|
|
+ 'report_name': enums.REPORT_NAME.values[0],
|
|
|
+ 'created_date_time': datetime.now(timezone.utc),
|
|
|
+ 'report_request_id': generate_id(),
|
|
|
+ 'report_specifier_id': generate_id(),
|
|
|
+ 'report_descriptions': [{'r_id': generate_id(),
|
|
|
+ 'report_subjects': [{'ven_id': '123ABC'}, {'ven_id': 'DEF456'}],
|
|
|
+ 'report_data_sources': [{'ven_id': '123ABC'}],
|
|
|
+ 'report_type': enums.REPORT_TYPE.values[0],
|
|
|
+ 'reading_type': enums.READING_TYPE.values[0],
|
|
|
+ 'market_context': 'http://localhost',
|
|
|
+ 'sampling_rate': {'min_period': timedelta(minutes=1),
|
|
|
+ 'max_period': timedelta(minutes=2),
|
|
|
+ 'on_change': False}}]}], ven_id='123ABC')
|
|
|
+# for report_name in enums.REPORT_NAME.values:
|
|
|
+# for reading_type in enums.READING_TYPE.values:
|
|
|
+# for report_type in enums.REPORT_TYPE.values:
|
|
|
+# test_message('oadrUpdateReport', request_id=generate_id(), reports=[{'report_id': generate_id(),
|
|
|
+# 'report_name': report_name,
|
|
|
+# 'created_date_time': datetime.now(timezone.utc),
|
|
|
+# 'report_request_id': generate_id(),
|
|
|
+# 'report_specifier_id': generate_id(),
|
|
|
+# 'report_descriptions': [{'r_id': generate_id(),
|
|
|
+# 'report_subjects': [{'ven_id': '123ABC'}, {'ven_id': 'DEF456'}],
|
|
|
+# 'report_data_sources': [{'ven_id': '123ABC'}],
|
|
|
+# 'report_type': report_type,
|
|
|
+# 'reading_type': reading_type,
|
|
|
+# 'market_context': 'http://localhost',
|
|
|
+# 'sampling_rate': {'min_period': timedelta(minutes=1),
|
|
|
+# 'max_period': timedelta(minutes=2),
|
|
|
+# 'on_change': False}}]}], ven_id='123ABC')
|
|
|
|