InventoCasa / ha-advanced-blueprints

Advanced Blueprints combined with pyscript for extra useful automations
139 stars 33 forks source link

Bug line 289 min() to max() method #76

Closed bravepasta closed 2 weeks ago

bravepasta commented 3 weeks ago

Reviewing the python code in line 289 where the dev calculates the simple moving average of historical data.

avg_excess_power = int(sum(PvExcessControl.pv_history[-inst.appliance_switch_interval:]) / min([1,inst.appliance_switch_interval]))

Wouldn't be the min() method always returning 1 as the values for inst.appliance_switch_interval is an integer between 1 and 60? If the use of min() is wrong, would instead the use of max() be correct?

This bug is also present in line 298.

InventoCasa commented 3 weeks ago

I think you're correct, thanks for noticing this. Will fix it asap. Seems like I didn't pay enough attention when reviewing the latest PR.