Skip to content

Commit

Permalink
Update config options and use GRPC if possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
UpstreamData committed Nov 19, 2023
1 parent e67f559 commit 71cc42e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
16 changes: 14 additions & 2 deletions custom_components/miner/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


class MinerCoordinator(DataUpdateCoordinator):
"""Class to manage fetching update data from the IoTaWatt Energy Device."""
"""Class to manage fetching update data from the Miner."""

miner: pyasic.AnyMiner | None = None

Expand Down Expand Up @@ -53,7 +53,19 @@ async def _async_update_data(self):
self.miner.username = miner_username
self.miner.pwd = miner_password

miner_data = await self.miner.get_data()
miner_data = await self.miner.get_data(
include=[
"hostname",
"mac",
"is_mining",
"fw_ver",
"hashrate",
"nominal_hashrate",
"hashboards",
"wattage",
"wattage_limit",
]
)

except pyasic.APIError as err:
raise UpdateFailed("API Error") from err
Expand Down
25 changes: 17 additions & 8 deletions custom_components/miner/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging

import pyasic
from pyasic.miners.backends import BOSMiner
from homeassistant.components.number import NumberEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback
Expand Down Expand Up @@ -35,13 +36,14 @@ def _create_entity(key: str):
created.add(key)

await coordinator.async_config_entry_first_refresh()
async_add_entities(
[
MinerPowerLimitNumber(
coordinator=coordinator,
)
]
)
if coordinator.miner.supports_autotuning:
async_add_entities(
[
MinerPowerLimitNumber(
coordinator=coordinator,
)
]
)

# @callback
# def new_data_received():
Expand Down Expand Up @@ -118,7 +120,14 @@ async def async_set_native_value(self, value):
f"{self.coordinator.entry.title} does not support setting power limit."
)

result = await miner.set_power_limit(int(value))
if isinstance(miner, BOSMiner):
try:
result = await miner.web.grpc.set_power_target(int(value))
except pyasic.APIError:
result = await miner.set_power_limit(int(value))
else:
result = await miner.set_power_limit(int(value)) # noqa: ignore miner being assumed to be None

if not result:
raise pyasic.APIError("Failed to set wattage.")

Expand Down
15 changes: 8 additions & 7 deletions custom_components/miner/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ def _create_entity(key: str) -> SwitchEntity:
created.add(key)

await coordinator.async_config_entry_first_refresh()
async_add_entities(
[
MinerActiveSwitch(
coordinator=coordinator,
)
]
)
if coordinator.miner.supports_shutdown:
async_add_entities(
[
MinerActiveSwitch(
coordinator=coordinator,
)
]
)

# @callback
# def new_data_received():
Expand Down

0 comments on commit 71cc42e

Please sign in to comment.