Skip to content

Commit

Permalink
Try to fix reboot handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
b-rowan committed Jun 21, 2024
1 parent 382dec2 commit 0f2dab8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
1 change: 0 additions & 1 deletion custom_components/miner/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def device_info(self) -> entity.DeviceInfo:
model=self.coordinator.data["model"],
sw_version=self.coordinator.data["fw_ver"],
name=f"{self.coordinator.entry.title}",

)

@property
Expand Down
28 changes: 22 additions & 6 deletions custom_components/miner/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import logging

import pyasic
from homeassistant.const import CONF_MAC
from homeassistant.core import HomeAssistant
from homeassistant.core import ServiceCall

from .const import CONF_IP
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 All @@ -19,15 +21,29 @@ async def async_setup_services(hass: HomeAssistant) -> None:
"""Service handler setup."""

async def get_miner(call: ServiceCall):
ip = call.data.get(CONF_IP)
mac = call.data.get(CONF_MAC)
miners = hass.data[DOMAIN]

if ip:
return await pyasic.get_miner(ip)
else:
if mac is None or mac not in miners:
LOGGER.error(
f"Cannot reboot, must specify an IP from [{miners}]",
f"Cannot get miner, must specify a mac from [{miners}]",
)
return
miner = await pyasic.get_miner(miners[mac].data[CONF_IP])

entry = miners[mac]
if miner.api is not None:
if miner.api.pwd is not None:
miner.api.pwd = entry.data.get(CONF_RPC_PASSWORD, "")

if miner.web is not None:
miner.web.username = entry.data.get(CONF_WEB_USERNAME, "")
miner.web.pwd = entry.data.get(CONF_WEB_PASSWORD, "")

if miner.ssh is not None:
miner.ssh.username = entry.data.get(CONF_SSH_USERNAME, "")
miner.ssh.pwd = entry.data.get(CONF_SSH_PASSWORD, "")
return miner


async def reboot(call: ServiceCall) -> None:
Expand Down
8 changes: 4 additions & 4 deletions custom_components/miner/services.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
reboot:
fields:
ip:
mac:
required: true
example: 192.168.1.60
example: 01:23:45:67:89:00
selector:
text:

restart_backend:
fields:
ip:
mac:
required: true
example: 192.168.1.60
example: 01:23:45:67:89:00
selector:
text:

0 comments on commit 0f2dab8

Please sign in to comment.