|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import logging |
4 | | -import uuid |
5 | 4 | from dataclasses import fields |
6 | 5 | from enum import Enum |
7 | 6 | from typing import Any, Dict, List, NamedTuple, Optional, Tuple |
@@ -100,31 +99,35 @@ def time_updated(timestamp): |
100 | 99 |
|
101 | 100 | for ctrl_index, ctrl in enumerate(controls): |
102 | 101 | if not ctrl.EventStatus: |
103 | | - _log.debug(f"Setting up event for ctrl {ctrl_index} current_time: {timestamp} start_time: {ctrl.interval.start}") |
104 | | - if timestamp > ctrl.interval.start and timestamp < ctrl.interval.start + ctrl.interval.duration: |
105 | | - ctrl.EventStatus = m.EventStatus(currentStatus=1, dateTime=timestamp, potentiallySuperseded=False, reason="Active") |
| 102 | + if ctrl.interval is not None: |
| 103 | + _log.debug(f"Setting up event for ctrl {ctrl_index} current_time: {timestamp} start_time: {ctrl.interval.start}") |
| 104 | + if timestamp > ctrl.interval.start and timestamp < ctrl.interval.start + ctrl.interval.duration: |
| 105 | + ctrl.EventStatus = m.EventStatus(currentStatus=1, dateTime=timestamp, potentiallySuperseded=False, reason="Active") |
| 106 | + else: |
| 107 | + ctrl.EventStatus = m.EventStatus(currentStatus=0, dateTime=timestamp, potentiallySuperseded=False, reason="Scheduled") |
| 108 | + _log.debug(f"ctrl.EventStatus is {ctrl.EventStatus}") |
106 | 109 | else: |
107 | 110 | ctrl.EventStatus = m.EventStatus(currentStatus=0, dateTime=timestamp, potentiallySuperseded=False, reason="Scheduled") |
108 | | - _log.debug(f"ctrl.EventStatus is {ctrl.EventStatus}") |
109 | 111 |
|
110 | | - # Active control |
111 | | - if ctrl.interval.start < timestamp and timestamp < ctrl.interval.start + ctrl.interval.duration: |
112 | | - if ctrl.EventStatus.currentStatus == 0: |
113 | | - _log.debug(f"Activating control {ctrl_index}") |
114 | | - ctrl.EventStatus.currentStatus = 1 # Active |
115 | | - ctrl.EventStatus.dateTime = timestamp |
116 | | - ctrl.EventStatus.reason = f"Control event active {ctrl.mRID}" |
117 | | - |
118 | | - if ctrl.mRID not in [x.mRID for x in current_active]: |
119 | | - DERProgramAdapter.add_child(derp, hrefs.DER_CONTROL_ACTIVE, ctrl) |
120 | | - |
121 | | - elif timestamp > ctrl.interval.start + ctrl.interval.duration: |
122 | | - if ctrl.EventStatus.currentStatus == 1: |
123 | | - _log.debug(f"Deactivating control {ctrl_index}") |
124 | | - |
125 | | - ctrl.EventStatus.currentStatus = -1 # for me this means complete |
126 | | - DERProgramAdapter.remove_child(derp, hrefs.DER_CONTROL_ACTIVE, ctrl) |
127 | | - |
| 112 | + if ctrl.EventStatus: |
| 113 | + # Active control |
| 114 | + if ctrl.interval.start < timestamp and timestamp < ctrl.interval.start + ctrl.interval.duration: |
| 115 | + if ctrl.EventStatus.currentStatus == 0: |
| 116 | + _log.debug(f"Activating control {ctrl_index}") |
| 117 | + ctrl.EventStatus.currentStatus = 1 # Active |
| 118 | + ctrl.EventStatus.dateTime = timestamp |
| 119 | + ctrl.EventStatus.reason = f"Control event active {ctrl.mRID}" |
| 120 | + |
| 121 | + if ctrl.mRID not in [x.mRID for x in current_active]: |
| 122 | + DERProgramAdapter.add_child(derp, hrefs.DER_CONTROL_ACTIVE, ctrl) |
| 123 | + |
| 124 | + elif timestamp > ctrl.interval.start + ctrl.interval.duration: |
| 125 | + if ctrl.EventStatus.currentStatus == 1: |
| 126 | + _log.debug(f"Deactivating control {ctrl_index}") |
| 127 | + |
| 128 | + ctrl.EventStatus.currentStatus = -1 # for me this means complete |
| 129 | + DERProgramAdapter.remove_child(derp, hrefs.DER_CONTROL_ACTIVE, ctrl) |
| 130 | + |
128 | 131 |
|
129 | 132 | def initialize_der_program_adapter(sender): |
130 | 133 |
|
|
0 commit comments