Skip to content

Commit

Permalink
Fix some actions failures
Browse files Browse the repository at this point in the history
  • Loading branch information
UpstreamData committed Sep 18, 2024
1 parent f1ddcca commit 5ccc54b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ Control your Bitcoin miner from Home Assistant.

**This component will add the following services -**

| Service | Description |
| ------- | ----------- |
| `reboot` | Reboot a miner by IP |
| Service | Description |
| ----------------- | ------------------------------------ |
| `reboot` | Reboot a miner by IP |
| `restart_backend` | Restart the backend of a miner by IP |

## Installation
Expand Down
7 changes: 3 additions & 4 deletions custom_components/miner/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from homeassistant.helpers.debounce import Debouncer
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.helpers.update_coordinator import UpdateFailed
from pyasic import AnyMiner

from .const import CONF_IP
from .const import CONF_RPC_PASSWORD
Expand Down Expand Up @@ -51,6 +50,7 @@ def available(self):
return self.miner is not None

async def get_miner(self):
"""Get a valid Miner instance."""
miner_ip = self.entry.data[CONF_IP]
miner = await pyasic.get_miner(miner_ip)
if miner is None:
Expand All @@ -70,7 +70,6 @@ async def get_miner(self):
self.miner.ssh.pwd = self.entry.data.get(CONF_SSH_PASSWORD, "")
return self.miner


async def _async_update_data(self):
"""Fetch sensors from miners."""
miner = await self.get_miner()
Expand Down Expand Up @@ -106,12 +105,12 @@ async def _async_update_data(self):
hashrate = round(float(miner_data.hashrate), 2)
except TypeError:
hashrate = None

try:
expected_hashrate = round(float(miner_data.expected_hashrate), 2)
except TypeError:
expected_hashrate = None

data = {
"hostname": miner_data.hostname,
"mac": miner_data.mac,
Expand Down
2 changes: 2 additions & 0 deletions custom_components/miner/device_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
}
)


async def async_validate_action_config(
hass: HomeAssistant, config: ConfigType
) -> ConfigType:
"""Validate config."""
return async_validate_entity_schema(hass, config, ACTION_SCHEMA)


async def async_get_actions(
hass: HomeAssistant, device_id: str
) -> list[dict[str, str]]:
Expand Down
1 change: 1 addition & 0 deletions custom_components/miner/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"name": "Miner",
"codeowners": ["@Schnitzel"],
"config_flow": true,
"dependencies": ["network"],
"documentation": "https://github.com/Schnitzel/hass-miner",
"homekit": {},
"iot_class": "local_polling",
Expand Down
8 changes: 6 additions & 2 deletions custom_components/miner/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity, device_registry
from homeassistant.helpers import device_registry
from homeassistant.helpers import entity
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity

Expand Down Expand Up @@ -55,7 +56,10 @@ def device_info(self) -> entity.DeviceInfo:
"""Return device info."""
return entity.DeviceInfo(
identifiers={(DOMAIN, self.coordinator.data["mac"])},
connections={("ip", self.coordinator.data["ip"]), (device_registry.CONNECTION_NETWORK_MAC, self.coordinator.data["mac"])},
connections={
("ip", self.coordinator.data["ip"]),
(device_registry.CONNECTION_NETWORK_MAC, self.coordinator.data["mac"]),
},
configuration_url=f"http://{self.coordinator.data['ip']}",
manufacturer=self.coordinator.data["make"],
model=self.coordinator.data["model"],
Expand Down
6 changes: 1 addition & 5 deletions custom_components/miner/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@

import logging

import pyasic
from homeassistant.const import CONF_MAC, CONF_DEVICE_ID
from homeassistant.const import CONF_DEVICE_ID
from homeassistant.core import HomeAssistant
from homeassistant.core import ServiceCall
from voluptuous import Schema

from .const import CONF_IP, CONF_RPC_PASSWORD, CONF_WEB_USERNAME, CONF_WEB_PASSWORD, CONF_SSH_USERNAME, \
CONF_SSH_PASSWORD
from .const import DOMAIN
from .const import SERVICE_REBOOT
from .const import SERVICE_RESTART_BACKEND
Expand Down
11 changes: 11 additions & 0 deletions custom_components/miner/strings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"title": "HASS-miner",
"config": {
"step": {
"user": {
Expand All @@ -25,5 +26,15 @@
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]",
"no_devices_found": "[%key:common::config_flow::abort::no_devices_found%]"
}
},
"services": {
"reboot": {
"name": "Reboot miner",
"description": "Reboots a miner."
},
"restart_backend": {
"name": "Restart mining on miner",
"description": "Restarts the mining process on a miner."
}
}
}

0 comments on commit 5ccc54b

Please sign in to comment.