Skip to content

Commit

Permalink
Merge pull request VOLTTRON#2919 from Siecje/elseif
Browse files Browse the repository at this point in the history
Simplify else: if code
  • Loading branch information
craig8 authored Jun 8, 2023
2 parents 49a2584 + 3b9592b commit 6881c4a
Show file tree
Hide file tree
Showing 12 changed files with 1,849 additions and 96 deletions.
7 changes: 3 additions & 4 deletions deprecated/Darksky/tests/test_darksky.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,10 @@ def test_success_forecast(volttron_instance, cleanup_cache, weather, query_agent
num_records = cursor.fetchone()[0]
if service_name == service:
assert num_records is records_amount * len(locations)
elif identity == 'platform.darksky_perf':
assert num_records is 0
else:
if identity == 'platform.darksky_perf':
assert num_records is 0
else:
assert num_records is records_amount * len(locations)
assert num_records is records_amount * len(locations)

assert len(query_data) == len(locations)

Expand Down
25 changes: 12 additions & 13 deletions examples/EnergyPlusAgent/energyplus/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,20 +371,19 @@ def check_advance(self):
self.tns_actuate,
headers={},
message={}).get(timeout=10)
else:
if self.EnergyPlus_sim.hour > self.EnergyPlus_sim.currenthour or self.EnergyPlus_sim.passtime:
self.EnergyPlus_sim.passtime = True
self.cosim_sync_counter += timestep
if self.cosim_sync_counter < self.EnergyPlus_sim.co_sim_timestep:
self.advance_simulation(None, None, None, None, None, None)
else:
self.cosim_sync_counter = 0
self.vip.pubsub.publish('pubsub',
self.tns_actuate,
headers={},
message={}).get(timeout=10)
else:
elif self.EnergyPlus_sim.hour > self.EnergyPlus_sim.currenthour or self.EnergyPlus_sim.passtime:
self.EnergyPlus_sim.passtime = True
self.cosim_sync_counter += timestep
if self.cosim_sync_counter < self.EnergyPlus_sim.co_sim_timestep:
self.advance_simulation(None, None, None, None, None, None)
else:
self.cosim_sync_counter = 0
self.vip.pubsub.publish('pubsub',
self.tns_actuate,
headers={},
message={}).get(timeout=10)
else:
self.advance_simulation(None, None, None, None, None, None)

return

Expand Down
19 changes: 9 additions & 10 deletions services/contrib/MarketServiceAgent/market_service/market.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,16 @@ def clear_market(self):
error_code = BAD_STATE
error_message = 'Programming error in Market class. State of {} and clear market signal arrived. ' \
'This represents a logic error.'.format(self.state)
elif not self.has_market_formed():
error_code = NOT_FORMED
error_message = 'The market {} has not received a buy and a sell reservation.'.format(self.market_name)
else:
if not self.has_market_formed():
error_code = NOT_FORMED
error_message = 'The market {} has not received a buy and a sell reservation.'.format(self.market_name)
else:
quantity, price, aux = self.offers.settle()
_log.info("Clearing mixmarket: {} Price: {} Qty: {}".format(self.market_name, price, quantity))
aux = {}
if price is None or quantity is None:
error_code = NO_INTERSECT
error_message = "Error: The supply and demand curves do not intersect. The market {} failed to clear.".format(self.market_name)
quantity, price, aux = self.offers.settle()
_log.info("Clearing mixmarket: {} Price: {} Qty: {}".format(self.market_name, price, quantity))
aux = {}
if price is None or quantity is None:
error_code = NO_INTERSECT
error_message = "Error: The supply and demand curves do not intersect. The market {} failed to clear.".format(self.market_name)
_log.info("Clearing price for Market: {} Price: {} Qty: {}".format(self.market_name, price, quantity))
timestamp = self._get_time()
timestamp_string = utils.format_timestamp(timestamp)
Expand Down
9 changes: 4 additions & 5 deletions services/core/DNP3Agent/dnp3/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,10 @@ def validate_point(self):
raise ValueError('Missing selector_block_end for block named {}'.format(self.name))
if self.selector_block_start > self.selector_block_end:
raise ValueError('Selector block end index < start index for block named {}'.format(self.name))
else:
if self.selector_block_start is not None:
raise ValueError('selector_block_start defined for non-selector-block point {}'.format(self.name))
if self.selector_block_end is not None:
raise ValueError('selector_block_end defined for non-selector-block point {}'.format(self.name))
elif self.selector_block_start is not None:
raise ValueError('selector_block_start defined for non-selector-block point {}'.format(self.name))
elif self.selector_block_end is not None:
raise ValueError('selector_block_end defined for non-selector-block point {}'.format(self.name))

def as_json(self):
"""Return a json description of the PointDefinition."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,20 +268,19 @@ def do_edit_directories(self, line):
print("No change made to '{0}'".format(dir_key))
else:
self._directories[dir_key] = dir
elif line not in self._directories:
print("Directory type '{0}' does not exist".format(line))
print("Please select another directory type from: {0}".format([k for k in self._directories.keys()]))
print("Enter a directory type. Press <Enter> if edit all: ", end='')
self.do_edit_directories(input().lower())
else:
if line not in self._directories:
print("Directory type '{0}' does not exist".format(line))
print("Please select another directory type from: {0}".format([k for k in self._directories.keys()]))
print("Enter a directory type. Press <Enter> if edit all: ", end='')
self.do_edit_directories(input().lower())
print("Enter the directory path for {0}. Press <Enter> if no change needed: ".format(line), end='')
dir_path = input()
dir = self.get_existed_directory(dir_path, line) if dir_path else None
if not dir or dir == self._directories[line]:
print("No change made to {0}".format(line))
else:
print("Enter the directory path for {0}. Press <Enter> if no change needed: ".format(line), end='')
dir_path = input()
dir = self.get_existed_directory(dir_path, line) if dir_path else None
if not dir or dir == self._directories[line]:
print("No change made to {0}".format(line))
else:
self._directories[line] = dir
self._directories[line] = dir

self.do_list_directories('')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,10 @@ def _table(self):
return table_map[table]
except KeyError:
raise Exception("Invalid modbus table '{0}' for register '{1}'".format(table, self._name))
elif self._datatype == helpers.BOOL:
return helpers.COIL_READ_WRITE if self._writable else helpers.COIL_READ_ONLY
else:
if self._datatype == helpers.BOOL:
return helpers.COIL_READ_WRITE if self._writable else helpers.COIL_READ_ONLY
else:
return helpers.REGISTER_READ_WRITE if self._writable else helpers.REGISTER_READ_ONLY
return helpers.REGISTER_READ_WRITE if self._writable else helpers.REGISTER_READ_ONLY

@property
def _op_mode(self):
Expand Down
Loading

0 comments on commit 6881c4a

Please sign in to comment.