Update sub-component batteries from parent HA entity in poller and live sync
This commit is contained in:
@@ -804,8 +804,8 @@ def create_app(config_object="config"):
|
||||
ha_live_pct = ha_client.get_state(device.ha_entity_id, timeout=1)
|
||||
if ha_live_pct is not None:
|
||||
changed = False
|
||||
for battery in device.batteries:
|
||||
if battery.status == "installed" and battery.battery_percentage != ha_live_pct:
|
||||
for battery in device.installed_batteries():
|
||||
if battery.battery_percentage != ha_live_pct:
|
||||
battery.battery_percentage = ha_live_pct
|
||||
db.add(BatteryPctLog(
|
||||
battery_id=battery.id,
|
||||
@@ -1144,15 +1144,7 @@ def create_app(config_object="config"):
|
||||
return redirect(url_for("device_detail", device_id=device_id))
|
||||
increment = 1 if request.form.get("increment_cycles") else 0
|
||||
notes = request.form.get("notes", "").strip() or None
|
||||
if device.has_children():
|
||||
installed = [
|
||||
b
|
||||
for child in device.children
|
||||
for b in child.batteries
|
||||
if b.status == "installed"
|
||||
]
|
||||
else:
|
||||
installed = [b for b in device.batteries if b.status == "installed"]
|
||||
installed = device.installed_batteries()
|
||||
if not installed:
|
||||
flash("No installed batteries to log.", "warning")
|
||||
return redirect(url_for("device_detail", device_id=device_id))
|
||||
|
||||
Reference in New Issue
Block a user