From 70afb189997004716f2793893f1c441676098d8a Mon Sep 17 00:00:00 2001 From: Brett Rowan <121075405+b-rowan@users.noreply.github.com> Date: Fri, 22 Nov 2024 14:00:43 -0700 Subject: [PATCH] Allow miner to revert to last mining mode state when starting --- custom_components/miner/switch.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/custom_components/miner/switch.py b/custom_components/miner/switch.py index f1dc50d..1695700 100644 --- a/custom_components/miner/switch.py +++ b/custom_components/miner/switch.py @@ -64,6 +64,7 @@ def __init__( self._attr_unique_id = f"{self.coordinator.data['mac']}-active" self._attr_is_on = self.coordinator.data["is_mining"] self.updating_switch = False + self._last_mining_mode = None @property def name(self) -> str | None: @@ -89,6 +90,10 @@ async def async_turn_on(self) -> None: raise TypeError(f"{miner}: Shutdown not supported.") self._attr_is_on = True await miner.resume_mining() + if miner.supports_power_modes: + config = await miner.get_config() + config.mining_mode = self._last_mining_mode + await miner.send_config(config) self.updating_switch = True self.async_write_ha_state() @@ -98,6 +103,8 @@ async def async_turn_off(self) -> None: _LOGGER.debug(f"{self.coordinator.entry.title}: Stop mining.") if not miner.supports_shutdown: raise TypeError(f"{miner}: Shutdown not supported.") + if miner.supports_power_modes: + self._last_mining_mode = self.coordinator.data["config"].mining_mode self._attr_is_on = False await miner.stop_mining() self.updating_switch = True