Skip to content

Commit

Permalink
Cleanup docs and code.
Browse files Browse the repository at this point in the history
  • Loading branch information
eseglem committed Nov 13, 2023
1 parent 4587d68 commit 3734055
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 94 deletions.
5 changes: 3 additions & 2 deletions .devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.black-formatter",
"ms-python.mypy-type-checker",
"charliermarsh.ruff",
"EditorConfig.EditorConfig",
"redhat.vscode-yaml",
"tamasfe.even-better-toml"
"tamasfe.even-better-toml",
"github.vscode-github-actions"
],
"settings": {
"files.eol": "\n",
"editor.tabSize": 4,
"python.pythonPath": "/usr/bin/python3",
"python.analysis.autoSearchPaths": false,
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
blank_issues_enabled: false
blank_issues_enabled: false
8 changes: 0 additions & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,3 @@ updates:
directory: "/"
schedule:
interval: "monthly"

- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "monthly"
ignore:
# Dependabot should not update Home Assistant as that should match the homeassistant key in hacs.json
- dependency-name: "homeassistant"
31 changes: 0 additions & 31 deletions .github/workflows/lint.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ jobs:
shell: "bash"
run: |
yq -i -o json '.version="${{ github.event.release.tag_name }}"' \
"${{ github.workspace }}/custom_components/hass-wattbox/manifest.json"
"${{ github.workspace }}/custom_components/wattbox/manifest.json"
- name: "ZIP the integration directory"
shell: "bash"
run: |
cd "${{ github.workspace }}/custom_components/hass-wattbox"
cd "${{ github.workspace }}/custom_components/wattbox"
zip hass-wattbox.zip -r ./
- name: "Upload the ZIP file to the release"
uses: softprops/[email protected]
with:
files: ${{ github.workspace }}/custom_components/hass-wattbox/hass-wattbox.zip
files: ${{ github.workspace }}/custom_components/wattbox/hass-wattbox.zip
26 changes: 12 additions & 14 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,35 @@ name: "Validate"
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"
- cron: "0 0 * * *"
push:
branches:
- "master"
- "develop"
pull_request:
branches:
- "main"
- "master"
- "develop"

jobs:
hassfest: # https://developers.home-assistant.io/blog/2020/04/16/hassfest
name: "Hassfest Validation"
runs-on: "ubuntu-latest"
steps:
- name: "Checkout the repository"
uses: "actions/[email protected]"
- name: "Checkout the repository"
uses: "actions/[email protected]"

- name: "Run hassfest validation"
uses: "home-assistant/actions/hassfest@master"
- name: "Run hassfest validation"
uses: "home-assistant/actions/hassfest@master"

hacs: # https://github.com/hacs/action
name: "HACS Validation"
runs-on: "ubuntu-latest"
steps:
- name: "Checkout the repository"
uses: "actions/[email protected]"
- name: "Checkout the repository"
uses: "actions/[email protected]"

- name: "Run HACS validation"
uses: "hacs/action@main"
with:
category: "integration"
# Remove this 'ignore' key when you have added brand images for your integration to https://github.com/home-assistant/brands
ignore: "brands"
- name: "Run HACS validation"
uses: "hacs/action@main"
with:
category: "integration"
42 changes: 42 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
ci:
autoupdate_schedule: monthly

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-toml
- id: check-yaml
args: ["--unsafe"]
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
args: ["--fix=lf"]
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: ["--py38-plus", "--keep-runtime-typing"]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.5
hooks:
- id: ruff
args: ["--fix"]
- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
- id: black
language_version: python
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.0
hooks:
- id: mypy
language_version: python
args: [--config-file=pyproject.toml, custom_components/]
pass_filenames: false
additional_dependencies:
- homeassistant-stubs
- pywattbox [http, ip] @ git+https://github.com/eseglem/pywattbox@develop#pywattbox==0.6.0
- types-beautifulsoup4
12 changes: 7 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ Github is used to host code, to track issues and feature requests, as well as ac
Pull requests are the best way to propose changes to the codebase.

1. Fork the repo and create your branch from `main`.
2. If you've changed something, update the documentation.
3. Make sure your code lints (using `scripts/lint`).
4. Test you contribution.
5. Issue that pull request!
1. If you've changed something, update the documentation.
1. Use `pre-commit`.
1. `pre-commit install` will run it automatically on each commit.
1. `pre-commit run --all` manually runs all checks.
1. Test you contribution.
1. Issue that pull request!

## Any contributions you make will be under the MIT Software License

Expand Down Expand Up @@ -48,7 +50,7 @@ Use [black](https://github.com/ambv/black) to make sure the code follows the sty

## Test your code modification

This custom component is based on [integration_blueprint template](https://github.com/ludeeus/integration_blueprint).
This custom component is based on [ludeeus/integration_blueprint](https://github.com/ludeeus/integration_blueprint).

It comes with development environment in a container, easy to launch
if you use Visual Studio Code. With this container you will have a stand alone
Expand Down
47 changes: 25 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,29 @@

# hass-wattbox

_Home Assistant Component to integrate with [WattBox][wattbox]._
[Home Assistant](home-assistant) Custom Component to integrate with [WattBox][wattbox].

Easiest way to install this component is through [HACS][hacs].

Configuration through `configuration.yaml`, not available in UI yet.
Configuration through `configuration.yaml`. UI based configuration not available yet.

Example Config:

```yaml
wattbox:
- host: 192.168.1.100
name: wattbox1
username: username1
password: password1
- name: WattBox-HTTP
host: !secret wattbox1_ip
port: 80
username: !secret wattbox1_username
password: !secret wattbox1_password
name_regexp: "^Fixed Prefix (.*)$"
skip_regexp: "SKIP"
scan_interval: 00:00:10
- host: 192.168.1.101
name: wattbox2
username: username2
password: password2
- name: WattBox-SSH
host: !secret wattbox2_ip
port: 22
username: !secret wattbox2_username
password: !secret wattbox2_password
scan_interval: 00:00:20
resources:
- auto_reboot
Expand All @@ -43,15 +45,15 @@ wattbox:
Configuration Options:
- _host_: Host IP of the WattBox (Required)
- _port_: Port of the HTTP interface (Default 80)
- _username_: Username for authentication (Default wattbox)
- _password_: Password for authentication (Default wattbox)
- _name_: Name for the WattBox (Default wattbox)
- _resources_: A list of resources to enable (Default all of them)
- _scan_interval_: A time interval run updates at (Default 30s, format HH:MM:SS)
- _name_regexp_: A regexp to extract the name to use for the outlet instead of just the index. If there is a match group, it is used, else the whole match is used.
- _skip_regexp_: A regexp to use that, if the outlet name matches, the outlet is not added as a switch entity.
- **`host`**: Host IP of the WattBox (Required)
- **`name`**: Name for the WattBox (Default WattBox)
- **`port`**: Port of the HTTP interface (Default 80)
- **`username`**: Username for authentication (Default wattbox)
- **`password`**: Password for authentication (Default wattbox)
- **`scan_interval`**: A time interval run updates at (Default 30s, format HH:MM:SS)
- **`resources`**: A list of resources to enable (Default all of them)
- **`name_regexp`**: A regexp to extract the name to use for the outlet instead of just the index. If there is a match group, it is used, else the whole match is used.
- **`skip_regexp`**: A regexp to use that, if the outlet name matches, the outlet is not added as a switch entity.

Resources:

Expand All @@ -71,12 +73,12 @@ Resources:
- power_value
- voltage_value

Be careful, if the WattBox controls the power to its own networking equipment you can turn it off and not have remote access until you fix it. You may even have to plug it in elsewhere to get back online and turn that outlet back on in HA. You can use the _skip_regexp_ option for those outlets.
Be careful, if the WattBox controls the power to its own networking equipment you can turn it off and not have remote access until you fix it. You may even have to plug it in elsewhere to get back online and turn that outlet back on in HA. You can use the `skip_regexp` option for those outlets.

Master switch will turn on / off all the switches that the physical switch on the box does. You can config that through the UI on the wattbox directly. If ALL of the switches controlled by Master are on, then Master will be on. Otherwise it will be off. If any outlets on a wattbox are skipped via _skip_regexp_ then
Master switch will turn on / off all the switches that the physical switch on the box does. You can config that through the UI on the wattbox directly. If ALL of the switches controlled by Master are on, then Master will be on. Otherwise it will be off. If any outlets on a wattbox are skipped via `skip_regexp` then
the master switch for that wattbox will also not be added as an entity.

Based on [integration_blueprint template][blueprint]
Based on: [ludeeus/integration_blueprint][blueprint]

<!---->

Expand All @@ -97,3 +99,4 @@ Based on [integration_blueprint template][blueprint]
[maintenance-shield]: https://img.shields.io/badge/maintainer-Erik%20Seglem%20%40Bedon292-blue
[hacs]: https://github.com/custom-components/hacs
[hacsbadge]: https://img.shields.io/badge/HACS-Custom-orange
[home-assistant]: https://github.com/home-assistant/core
8 changes: 5 additions & 3 deletions custom_components/wattbox/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
PLATFORMS: Final[List[str]] = ["binary_sensor", "sensor", "switch"]
ISSUE_URL: Final[str] = "https://github.com/eseglem/hass-wattbox/issues"

STARTUP: Final[str] = f"""
STARTUP: Final[
str
] = f"""
-------------------------------------------------------------------
{DOMAIN}
Version: {VERSION}
Expand All @@ -42,8 +44,8 @@
TOPIC_UPDATE: Final[str] = "{}_data_update_{}"

# config options
CONF_NAME_REGEXP: Final[str] = 'name_regexp'
CONF_SKIP_REGEXP: Final[str] = 'skip_regexp'
CONF_NAME_REGEXP: Final[str] = "name_regexp"
CONF_SKIP_REGEXP: Final[str] = "skip_regexp"


class _BinarySensorDict(TypedDict):
Expand Down
4 changes: 3 additions & 1 deletion custom_components/wattbox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"integration_type": "device",
"documentation": "https://github.com/eseglem/hass-wattbox",
"issue_tracker": "https://github.com/eseglem/hass-wattbox/issues",
"dependencies": [],
"after_dependencies": [
"component"
],
"codeowners": [
"@eseglem"
],
Expand Down
9 changes: 6 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
homeassistant==2023.8.0
homeassistant-stubs==2023.8.0
pip>=21.0,<23.2
homeassistant==2023.11.0
homeassistant-stubs==2023.11.0
pywattbox [http, ip] @ git+https://github.com/eseglem/pywattbox@develop#pywattbox==0.6.0
ruff
pre-commit
# Issue with default_config, python3.11, and botocore
# See: https://github.com/home-assistant/core/issues/95192
botocore @ git+https://github.com/boto/botocore
2 changes: 1 addition & 1 deletion scripts/lint
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -e

cd "$(dirname "$0")/.."

ruff check . --fix
pre-commit run --all

0 comments on commit 3734055

Please sign in to comment.