Skip to content

Commit

Permalink
Fixed graphing issue when rebooting/restarting TerrariumPI. #239
Browse files Browse the repository at this point in the history
  • Loading branch information
theyosh committed Jul 7, 2019
1 parent 13a013c commit 81ae531
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions terrariumEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ def __load_power_switches(self,data = None):

prev_state = {}
if starting_up:
logger.info('Loading previous power switch states from the last 2 minutes')
logger.info('Loading previous power switch states from the last 12 hours')
start = int(time.time())
prev_data = self.collector.get_history(['switches'],start,start-840)
prev_data = self.collector.get_history(['switches'],start,start-43200)

if 'switches' in prev_data:
for switch in prev_data['switches']:
Expand Down
10 changes: 7 additions & 3 deletions terrariumSwitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,11 @@ def set_state(self, state, force = False):
state,force))

if self.get_state() is not state or terrariumUtils.is_true(force):
old_state = self.get_state()

try:
old_state = self.get_state()
self.set_hardware_state(state,force)
self.state = state
changed = True

logger.info('Changed power switch \'{}\' of type \'{}\' at address \'{}\' from state \'{}\' to state \'{}\' (Forced:{})'.format(self.get_name(),
self.get_type(),
self.get_address(),
Expand All @@ -192,6 +191,11 @@ def set_state(self, state, force = False):
self.get_state(),
state,force))

if (old_state is not None) or (old_state is None and state == 0):
# This is due to a bug that will graph 0 watt usage in the graph after rebooting.
# Fix is to add power and water usage in constructor
changed = old_state != self.get_state()

if changed and self.callback is not None:
self.callback(self.get_data())

Expand Down

0 comments on commit 81ae531

Please sign in to comment.