Skip to content

Commit

Permalink
Final fix current power update through websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
theyosh committed May 28, 2024
1 parent 5a6e22e commit 679d717
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions terrariumEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,8 @@ def callback_relay(self, relay, state):
relay.update(state)
relay_data = relay.to_dict()

orm.commit()

# Update enclosure states to reflect the new relay states
if self.__engine["thread"] is not None and self.__engine["thread"].is_alive() and hasattr(self, "enclosures"):
self._update_enclosures(True)
Expand Down Expand Up @@ -1908,16 +1910,6 @@ def get_power_usage_water_flow(self, force=False, totals=True):
},
}

with orm.db_session():
for relay in Relay.select(
lambda r: r.id in self.relays.keys() and not r.id in self.settings["exclude_ids"]
):
data["power"]["current"] += relay.current_wattage
data["power"]["max"] += relay.wattage

data["flow"]["current"] += relay.current_flow
data["flow"]["max"] += relay.flow

if totals:
total = self.total_power_and_water_usage(force)

Expand All @@ -1932,6 +1924,16 @@ def get_power_usage_water_flow(self, force=False, totals=True):
# Total water costs is in L
data["flow"]["costs"] = data["flow"]["total"] * self.settings["water_price"]

with orm.db_session():
for relay in Relay.select(
lambda r: r.id in self.relays.keys() and not r.id in self.settings["exclude_ids"]
):
data["power"]["current"] += relay.current_wattage
data["power"]["max"] += relay.wattage

data["flow"]["current"] += relay.current_flow
data["flow"]["max"] += relay.flow

return data

def total_power_and_water_usage(self, force=False, background=False, thread_return=None):
Expand Down

0 comments on commit 679d717

Please sign in to comment.