Skip to content

Commit

Permalink
precommits
Browse files Browse the repository at this point in the history
  • Loading branch information
Schnitzel committed May 31, 2022
1 parent c6af842 commit e9cabc6
Show file tree
Hide file tree
Showing 19 changed files with 105 additions and 238 deletions.
6 changes: 2 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"image": "ghcr.io/ludeeus/devcontainer/integration:stable",
"name": "miner integration development",
"context": "..",
"appPort": [
"9123:8123"
],
"appPort": ["9123:8123"],
"postCreateCommand": "container install",
"extensions": [
"ms-python.python",
Expand All @@ -27,4 +25,4 @@
"editor.formatOnType": true,
"files.trimTrailingWhitespace": true
}
}
}
28 changes: 10 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
rev: v4.2.0
hooks:
- id: check-added-large-files
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: local
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
name: black
entry: black
language: system
types: [python]
require_serial: true
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
name: flake8
entry: flake8
language: system
types: [python]
require_serial: true
- repo: https://github.com/asottile/reorder_python_imports
rev: v3.1.0
hooks:
- id: reorder-python-imports
name: Reorder python imports
entry: reorder-python-imports
language: system
types: [python]
args: [--application-directories=custom_components]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.2.1
rev: v2.6.2
hooks:
- id: prettier
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
[![hacs][hacsbadge]][hacs]
[![Project Maintenance][maintenance-shield]][user_profile]


Controll your Braiins OS+ enabled Bitcoin miner from Home Assistant

**This component will set up the following platforms.**

| Platform | Description |
| --------------- | ------------------------------------------------------------------------- |
| `sensor` | Show info from miner API. |
| `number` | Set Power Limit of Miner. |
| `switch` | Switch Miner on and off |
| Platform | Description |
| -------- | ------------------------- |
| `sensor` | Show info from miner API. |
| `number` | Set Power Limit of Miner. |
| `switch` | Switch Miner on and off |

## Installation

Expand All @@ -29,7 +28,6 @@ Installation and usage:

[![Installation and usage](http://img.youtube.com/vi/eL83eYLbgQM/0.jpg)](http://www.youtube.com/watch?v=eL83eYLbgQM)


## Contributions are welcome!

If you want to contribute to this please read the [Contribution guidelines](CONTRIBUTING.md)
Expand Down
3 changes: 1 addition & 2 deletions custom_components/miner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant

from miners.miner_factory import MinerFactory
from .coordinator import MinerCoordinator

from .const import DOMAIN
from .coordinator import MinerCoordinator

# TODO List the platforms that you want to support.
# For your initial PR, limit it to 1 platform.
Expand Down
20 changes: 10 additions & 10 deletions custom_components/miner/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
"""Config flow for Miner."""
from homeassistant.helpers import config_entry_flow
from homeassistant import config_entries, core, exceptions
from .const import DOMAIN, CONF_IP, CONF_HOSTNAME

from API import APIError

import ipaddress
import logging

import voluptuous as vol

from API import APIError
from homeassistant import config_entries
from homeassistant import core
from homeassistant import exceptions
from miners.miner_factory import MinerFactory
import logging

from .const import CONF_HOSTNAME
from .const import CONF_IP
from .const import DOMAIN

_LOGGER = logging.getLogger(__name__)

Expand All @@ -31,10 +32,9 @@ async def validate_input(

miner_ip = ipaddress.ip_address(data.get(CONF_IP))
miner_factory = MinerFactory()
miner_data = {}
try:
miner = await miner_factory.get_miner(miner_ip)
miner_data = await miner.get_data()
await miner.get_data()
except APIError:
return {"base": "cannot_connect"}
except Exception: # pylint: disable=broad-except
Expand Down
2 changes: 1 addition & 1 deletion custom_components/miner/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

DOMAIN = "miner"
CONF_IP = "ip"
CONF_HOSTNAME = "hostname"
CONF_HOSTNAME = "hostname"
22 changes: 9 additions & 13 deletions custom_components/miner/coordinator.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
"""IoTaWatt DataUpdateCoordinator."""
from __future__ import annotations

from datetime import datetime, timedelta
import ipaddress
import logging
from datetime import timedelta

from miners.miner_factory import MinerFactory
from miners import BaseMiner

from API import APIError
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.helpers import httpx_client
from homeassistant.helpers.debounce import Debouncer
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from .const import CONF_IP, CONF_HOSTNAME

from API import APIError
import ipaddress
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.helpers.update_coordinator import UpdateFailed
from miners import BaseMiner
from miners.miner_factory import MinerFactory

from .parse_data import safe_parse_api_data
from .const import CONF_HOSTNAME
from .const import CONF_IP

_LOGGER = logging.getLogger(__name__)

Expand Down
10 changes: 3 additions & 7 deletions custom_components/miner/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
"name": "Miner",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/miner",
"requirements": [
"minerinterface==0.5.2"
],
"requirements": ["minerinterface==0.5.2"],
"ssdp": [],
"zeroconf": [],
"homekit": {},
"dependencies": [],
"codeowners": [
"@Schnitzel"
],
"codeowners": ["@Schnitzel"],
"iot_class": "local_polling",
"version": "0.1.0"
}
}
26 changes: 5 additions & 21 deletions custom_components/miner/number.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,16 @@
"""Support for IoTaWatt Energy monitor."""
from __future__ import annotations

from collections.abc import Callable
from dataclasses import dataclass
import logging
import yaml
from unittest import case

from homeassistant.components import switch

from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.components.number import (
NumberEntity,
)
import yaml
from homeassistant.components.number import NumberEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import entity, entity_registry
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
from homeassistant.core import callback
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import StateType
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util import dt

from .const import (
DOMAIN,
Expand Down
66 changes: 0 additions & 66 deletions custom_components/miner/parse_data.py

This file was deleted.

29 changes: 10 additions & 19 deletions custom_components/miner/sensor.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
"""Support for IoTaWatt Energy monitor."""
from __future__ import annotations

import logging
from collections.abc import Callable
from dataclasses import dataclass
import logging
from unittest import case

from homeassistant.components import switch

from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.components.number import (
NumberEntity,
)
from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.components.sensor import SensorEntity
from homeassistant.components.sensor import SensorEntityDescription
from homeassistant.components.sensor import SensorStateClass
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_CELSIUS, POWER_WATT
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import entity, entity_registry
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
from homeassistant.const import POWER_WATT
from homeassistant.const import TEMP_CELSIUS
from homeassistant.core import callback
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import StateType
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util import dt

from .const import (
DOMAIN,
Expand Down
25 changes: 6 additions & 19 deletions custom_components/miner/switch.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
"""Support for IoTaWatt Energy monitor."""
from __future__ import annotations

import logging
from collections.abc import Callable
from dataclasses import dataclass
import logging
from unittest import case

from homeassistant.components import switch

from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.components.switch import (
SwitchEntity,
)
from homeassistant.components.sensor import SensorEntityDescription
from homeassistant.components.switch import SwitchEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import entity, entity_registry
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
from homeassistant.core import callback
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import StateType
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util import dt

from .const import (
DOMAIN,
Expand Down
Loading

0 comments on commit e9cabc6

Please sign in to comment.