Skip to content

Commit

Permalink
Add smooth tuning to try to prevent rebooting when possible, with max…
Browse files Browse the repository at this point in the history
… diff of 500W, and prevent a case where the wattage limit shown can become an average value that doesn't reflect real state.
  • Loading branch information
UpstreamData committed Nov 19, 2023
1 parent b01f1e6 commit 084967e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions custom_components/miner/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,19 @@ async def async_set_native_value(self, value):
)

if isinstance(miner, BOSMiner):
max_diff = 500
try:
result = await miner.web.grpc.set_power_target(int(value))
diff = int(self.coordinator.data["miner_sensors"]["power_limit"]) - int(value)
smooth_tune = -max_diff < diff < max_diff

if smooth_tune:
if diff < 0:
result = await miner.web.grpc.decrement_power_target(diff)
else:
result = await miner.web.grpc.increment_power_target(diff)
else:
result = await miner.web.grpc.set_power_target(int(value))

except pyasic.APIError:
result = await miner.set_power_limit(int(value))
else:
Expand All @@ -136,6 +147,7 @@ async def async_set_native_value(self, value):

@callback
def _handle_coordinator_update(self) -> None:
self._attr_native_value = self.coordinator.data["miner_sensors"]["power_limit"]
if self.coordinator.data["miner_sensors"]["power_limit"] is not None:
self._attr_native_value = self.coordinator.data["miner_sensors"]["power_limit"]

super()._handle_coordinator_update()

0 comments on commit 084967e

Please sign in to comment.