test_conformance_002.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import pytest
  2. from pyopenadr import OpenADRClient, OpenADRServer, enums
  3. from pyopenadr.utils import generate_id, create_message, parse_message
  4. from datetime import datetime, timezone, timedelta
  5. from pprint import pprint
  6. @pytest.mark.asyncio
  7. async def test_conformance_002():
  8. """
  9. The uid element is REQUIRED for each eiEventSignal interval. Within a sin-
  10. gle oadrDistributeEvent eiEventSignal, uid MUST be expressed as an inter-
  11. val number with a base of 0 and an increment of 1 for each subsequent in-
  12. terval.
  13. """
  14. event_id = generate_id()
  15. event = {'event_descriptor':
  16. {'event_id': event_id,
  17. 'modification_number': 0,
  18. 'modification_date': datetime.now(),
  19. 'priority': 0,
  20. 'market_context': 'MarketContext001',
  21. 'created_date_time': datetime.now(),
  22. 'event_status': enums.EVENT_STATUS.FAR,
  23. 'test_event': False,
  24. 'vtn_comment': 'No Comment'},
  25. 'active_period':
  26. {'dtstart': datetime.now(),
  27. 'duration': timedelta(minutes=30)},
  28. 'event_signals':
  29. [{'intervals': [{'duration': timedelta(minutes=10),
  30. 'signal_payload': 100},
  31. {'duration': timedelta(minutes=10),
  32. 'signal_payload': 200},
  33. {'duration': timedelta(minutes=10),
  34. 'signal_payload': 300}],
  35. 'signal_name': enums.SIGNAL_NAME.SIMPLE,
  36. 'signal_type': enums.SIGNAL_TYPE.DELTA,
  37. 'signal_id': generate_id()
  38. }]
  39. }
  40. # Create a message with this event
  41. msg = create_message('oadrDistributeEvent',
  42. response={'response_code': 200,
  43. 'response_description': 'OK',
  44. 'request_id': generate_id()},
  45. request_id=generate_id(),
  46. vtn_id=generate_id(),
  47. events=[event])
  48. # Parse the message
  49. parsed_type, parsed_msg = parse_message(msg)
  50. assert parsed_type == 'oadrDistributeEvent'
  51. intervals = parsed_msg['events'][0]['event_signals'][0]['intervals']
  52. # Verify that the interval uid's are numbered consecutively and starting at 0
  53. assert intervals[0]['uid'] == 0
  54. assert intervals[0]['signal_payload'] == 100
  55. assert intervals[1]['uid'] == 1
  56. assert intervals[1]['signal_payload'] == 200
  57. assert intervals[2]['uid'] == 2
  58. assert intervals[2]['signal_payload'] == 300