From 325d0d2a7e9535f64982e677f050838a85740bd4 Mon Sep 17 00:00:00 2001 From: Bar Date: Tue, 27 Apr 2021 19:50:32 +0300 Subject: [PATCH] Fix pre-commit --- .github/workflows/constraints.txt | 3 ++ .github/workflows/hassfest.yaml | 2 ++ .github/workflows/pre-commit.yaml | 46 +++++++++++++++++------- .pre-commit-config.yaml | 57 ++++++++++++++++++++++++------ CHANGELOG.md | 14 ++++---- README.md | 30 ++++++++-------- __main__.py | 4 +-- _config.yml | 2 +- custom_components/edgeos/sensor.py | 1 - edgeos.json | 2 +- info.md | 30 ++++++++-------- pyproject.toml | 2 +- setup.cfg | 2 +- 13 files changed, 128 insertions(+), 67 deletions(-) create mode 100644 .github/workflows/constraints.txt diff --git a/.github/workflows/constraints.txt b/.github/workflows/constraints.txt new file mode 100644 index 0000000..75a084f --- /dev/null +++ b/.github/workflows/constraints.txt @@ -0,0 +1,3 @@ +pip==20.3.3 +pre-commit==2.9.3 +nox==2020.12.31 diff --git a/.github/workflows/hassfest.yaml b/.github/workflows/hassfest.yaml index 18c7d19..862840e 100644 --- a/.github/workflows/hassfest.yaml +++ b/.github/workflows/hassfest.yaml @@ -1,3 +1,5 @@ +--- + name: Validate with hassfest on: diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 883644a..9e43ce8 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -1,20 +1,42 @@ -name: pre-commit +name: Linting on: - pull_request: push: - branches: [master] + branches: + - main + - master + - dev + pull_request: jobs: pre-commit: runs-on: ubuntu-latest + name: pre-commit steps: - - uses: actions/checkout@v1 - - uses: actions/setup-python@v1 - - name: set PY - run: echo "::set-env name=PY::$(python -c 'import hashlib, sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')" - - uses: actions/cache@v1 - with: - path: ~/.cache/pre-commit - key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} - - uses: pre-commit/action@v1.0.1 \ No newline at end of file + - uses: actions/checkout@v2.3.4 + - uses: actions/setup-python@v2.2.1 + with: + python-version: "3.9" + - run: | + pip install --constraint=.github/workflows/constraints.txt pip + pip install --constraint=.github/workflows/constraints.txt pre-commit + - name: Compute cache key prefix + if: matrix.os != 'windows-latest' + id: cache_key_prefix + shell: python + run: | + import hashlib + import sys + python = "py{}.{}".format(*sys.version_info[:2]) + payload = sys.version.encode() + sys.executable.encode() + digest = hashlib.sha256(payload).hexdigest() + result = "${{ runner.os }}-{}-{}-pre-commit".format(python, digest) + print("::set-output name=result::{}".format(result)) + - uses: actions/cache@v2.1.3 + if: matrix.os != 'windows-latest' + with: + path: ~/.cache/pre-commit + key: ${{ steps.cache_key_prefix.outputs.result }}-${{ hashFiles('.pre-commit-config.yaml') }} + restore-keys: | + ${{ steps.cache_key_prefix.outputs.result }}- + - run: pre-commit run --all-files --show-diff-on-failure --color=always diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 19709f2..5ba4604 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,28 +1,63 @@ +--- + repos: - repo: https://github.com/asottile/pyupgrade - rev: v2.1.0 + rev: v2.7.2 hooks: - id: pyupgrade - args: [--py37-plus] + args: [--py38-plus] - repo: https://github.com/psf/black - rev: 19.10b0 + rev: 20.8b1 hooks: - id: black args: - --safe - --quiet + files: ^((homeassistant|script|tests)/.+)?[^/]+\.py$ + - repo: https://github.com/codespell-project/codespell + rev: v2.0.0 + hooks: + - id: codespell + args: + - --ignore-words-list=hass,alot,datas,dof,dur,ether,farenheit,hist,iff,ines,ist,lightsensor,mut,nd,pres,referer,ser,serie,te,technik,ue,uint,visability,wan,wanna,withing,iam,incomfort + - --skip="./.*,*.csv,*.json" + - --quiet-level=2 + exclude_types: [csv, json] + exclude: ^tests/fixtures/ - repo: https://gitlab.com/pycqa/flake8 - rev: 3.7.9 + rev: 3.8.4 hooks: - id: flake8 - #additional_dependencies: - # - flake8-docstrings==1.5.0 - # - pydocstyle==5.0.2 - - repo: https://github.com/pre-commit/mirrors-isort - rev: v4.3.21 + additional_dependencies: + - flake8-docstrings==1.5.0 + - pydocstyle==5.1.1 + files: ^(homeassistant|script|tests)/.+\.py$ + - repo: https://github.com/PyCQA/bandit + rev: 1.7.0 + hooks: + - id: bandit + args: + - --quiet + - --format=custom + - --configfile=tests/bandit.yaml + files: ^(homeassistant|script|tests)/.+\.py$ + - repo: https://github.com/PyCQA/isort + rev: 5.5.3 hooks: - id: isort - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.4.0 + rev: v3.2.0 + hooks: + - id: check-executables-have-shebangs + stages: [manual] + - id: check-json + exclude: (.vscode|.devcontainer) + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - id: check-added-large-files + - repo: https://github.com/prettier/prettier + rev: 2.0.4 hooks: - - id: check-json \ No newline at end of file + - id: prettier + stages: [manual] diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c87005..4f08a5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ **Implemented enhancements:** - Moved encryption key of component to .storage directory -- Removed support for non encrypted password (**Breaking Change**) +- Removed support for non encrypted password (**Breaking Change**) **Fixed bugs:** @@ -75,7 +75,7 @@ - Fix incorrect error message displayed when WebSocket or API request failed - Fix retry mechanism of API requests -- Fix integration's options error when device or interface list is empty +- Fix integration's options error when device or interface list is empty ## 2020-05-14 @@ -94,7 +94,7 @@ **Fixed bugs:** -- Fix redundant calculation of bits to bytes as data is already bytes +- Fix redundant calculation of bits to bytes as data is already bytes ## 2020-05-08 #1 @@ -104,7 +104,7 @@ **Fixed bugs:** -- Fix default value of unit in integration's options +- Fix default value of unit in integration's options ## 2020-05-06 @@ -129,7 +129,7 @@ - More enhancements to options, ability to change setup details - Support new translation format of HA 0.109.0 -- Added __main__.py to root directory for debugging +- Added __main__.py to root directory for debugging ## 2020-04-28 #3 @@ -165,7 +165,7 @@ **Implemented enhancements:** -- Simplified the way calculating whether device is connected or not, based on report of traffic analysis instead of calculating amount of traffic (bps) over the last 3 minutes [\#24](https://github.com/elad-bar/ha-edgeos/issues/24) +- Simplified the way calculating whether device is connected or not, based on report of traffic analysis instead of calculating amount of traffic (bps) over the last 3 minutes [\#24](https://github.com/elad-bar/ha-edgeos/issues/24) - Moved service `edgeos.save_debug_data` to Integration -> Options as configuration (that being reset after doing the action once) - Moved service `edgeos.log_events` to Integration -> Options as configuration to toggle upon need - Added ability to configure the log level of the component from Integration - Options, more details in README @@ -196,4 +196,4 @@ **Fixed bugs:** -- Login failure initiated reconnect mechanism instead of die gracefully +- Login failure initiated reconnect mechanism instead of die gracefully diff --git a/README.md b/README.md index 196b4a2..74b2092 100644 --- a/README.md +++ b/README.md @@ -23,12 +23,12 @@ Fields name | Type | Required | Default | Description Name | Textbox | + | - | Represents the integration name Host | Textbox | + | - | Hostname or IP address to access EdgeOS device Username | Textbox | + | - | Username of user with `Operator` level access or higher, better to create a dedicated user for that integration for faster issues identification -Password | Textbox | + | - | -Unit | Drop-down | + | Bytes | Unit for sensors, available options are: Bytes, KiloBytes, MegaBytes - +Password | Textbox | + | - | +Unit | Drop-down | + | Bytes | Unit for sensors, available options are: Bytes, KiloBytes, MegaBytes + ###### EdgeOS Device validation errors Errors | ---- | +--- | Cannot reach device (404) | Invalid credentials (403) | General authentication error (when failed to get valid response from device) | @@ -53,10 +53,10 @@ Fields name | Type | Required | Default | Description --- | --- | --- | --- | --- | Host | Textbox | + | - | Hostname or IP address to access EdgeOS device Username | Textbox | + | - | Username of user with `Operator` level access or higher, better to create a dedicated user for that integration for faster issues identification -Password | Textbox | + | - | +Password | Textbox | + | - | Clear credentials | Check-box | + | Unchecked | Will reset username and password (Not being stored under options) -Unit | Drop-down | + | Bytes | Unit for sensors, available options are: Bytes, KiloBytes, MegaBytes -Consider away interval | Textbox | + | 180 | Consider away interval in seconds +Unit | Drop-down | + | Bytes | Unit for sensors, available options are: Bytes, KiloBytes, MegaBytes +Consider away interval | Textbox | + | 180 | Consider away interval in seconds Monitored devices | Drop-down | + | NONE | Devices to monitor using binary_sensor and sensor Monitored interfaces | Drop-down | + | NONE | Interfaces to monitor using binary_sensor and sensor, Track | Drop-down | + | NONE | Devices to track using device_trac @@ -65,7 +65,7 @@ Update Entities Interval | Textbox | + | 1 | Number of seconds to update entitie Save debug file | Check-box | + | Unchecked | Will store debug file, more details below (Not being stored under options) Log level | Drop-down | + | Default | Changes component's log level (more details below) Log incoming messages | Check-box | + | Unchecked | Whether to log as DEBUG incoming web-socket messages or not - + ###### Log Level's drop-down New feature to set the log level for the component without need to set log_level in `customization:` and restart or call manually `logger.set_level` and loose it after restart. @@ -75,28 +75,28 @@ In case `Default` option is chosen, flow will skip calling the service, after ch ###### Save debug file Will store debug data from the component to HA CONFIG path named `edgeos_data.log` - + ## Components #### Default Name | Type | State | Attributes | ---- | --- | --- | --- | +--- | --- | --- | --- | {Integration Name} System Status | Binary Sensor | Connected or not | CPU
Memory
Up-time
API Last Update
WS Last Update {Integration Name} System Uptime | Sensor | Time since restart in seconds | CPU
Memory
Is Alive
API Last Update
WS Last Update {Integration Name} Unknown Devices | Sensor | Number of unknown devices | Unknown Devices description -#### Monitored Devices +#### Monitored Devices Name | Type | State | Attributes | ---- | --- | --- | --- | +--- | --- | --- | --- | {Integration Name} Device {Device Name} | Binary Sensor | Connected or not | IP
MAC
Name
{Unit}Bytes (Sent)
{Unit}Bytes/ps (Sent)
{Unit}Bytes (Received)
{Unit}Bytes/ps (Received)
Last Activity
Last Changed -#### Monitored Interfaces +#### Monitored Interfaces Name | Type | State | Attributes | ---- | --- | --- | --- | +--- | --- | --- | --- | {Integration Name} Interface {Interface Name} | Binary Sensor | Connected or not | Name
Duplex
Link Speed (Mbps)
address
Packets (Received)
Packets (Sent)
Errors (Received)
Errors (Sent)
Dropped packets (Received)
Dropped packets (Sent)
{Unit}Bytes (Received)
{Unit}Bytes (Sent)
{Unit}Bytes/ps (Received)
{Unit}Bytes/ps (Sent)
Multicast
Last Changed #### Tracked Devices Name | Type | State | Attributes | ---- | --- | --- | --- | +--- | --- | --- | --- | {Integration Name} {Device Name} | Device Tracker | Home or Away | Host
IP
MAC
Name
Last Activity
Connected ### Setting up the integration diff --git a/__main__.py b/__main__.py index b36b4df..77b6c76 100644 --- a/__main__.py +++ b/__main__.py @@ -1,13 +1,13 @@ import asyncio import logging +from test_consts import * + from custom_components.edgeos.managers.configuration_manager import ConfigManager from custom_components.edgeos.managers.data_manager import EdgeOSData from custom_components.edgeos.managers.password_manager import PasswordManager from custom_components.edgeos.managers.version_check import VersionCheck from custom_components.edgeos.models.config_data import ConfigData -from test_consts import * - from homeassistant.core import HomeAssistant logging.basicConfig(filename="log.txt", filemode="a", level="DEBUG") diff --git a/_config.yml b/_config.yml index c741881..f980e76 100644 --- a/_config.yml +++ b/_config.yml @@ -1 +1 @@ -theme: jekyll-theme-slate \ No newline at end of file +theme: jekyll-theme-slate diff --git a/custom_components/edgeos/sensor.py b/custom_components/edgeos/sensor.py index 9aad591..544d8a8 100644 --- a/custom_components/edgeos/sensor.py +++ b/custom_components/edgeos/sensor.py @@ -12,7 +12,6 @@ async_setup_base_entry, ) from custom_components.edgeos.models.entity_data import EntityData - from homeassistant.core import HomeAssistant _LOGGER = logging.getLogger(__name__) diff --git a/edgeos.json b/edgeos.json index 1f0088b..190f4e0 100644 --- a/edgeos.json +++ b/edgeos.json @@ -16,4 +16,4 @@ "https://raw.githubusercontent.com/elad-bar/ha-edgeos/master/custom_components/edgeos/manifest.json" ] } -} \ No newline at end of file +} diff --git a/info.md b/info.md index 196b4a2..74b2092 100644 --- a/info.md +++ b/info.md @@ -23,12 +23,12 @@ Fields name | Type | Required | Default | Description Name | Textbox | + | - | Represents the integration name Host | Textbox | + | - | Hostname or IP address to access EdgeOS device Username | Textbox | + | - | Username of user with `Operator` level access or higher, better to create a dedicated user for that integration for faster issues identification -Password | Textbox | + | - | -Unit | Drop-down | + | Bytes | Unit for sensors, available options are: Bytes, KiloBytes, MegaBytes - +Password | Textbox | + | - | +Unit | Drop-down | + | Bytes | Unit for sensors, available options are: Bytes, KiloBytes, MegaBytes + ###### EdgeOS Device validation errors Errors | ---- | +--- | Cannot reach device (404) | Invalid credentials (403) | General authentication error (when failed to get valid response from device) | @@ -53,10 +53,10 @@ Fields name | Type | Required | Default | Description --- | --- | --- | --- | --- | Host | Textbox | + | - | Hostname or IP address to access EdgeOS device Username | Textbox | + | - | Username of user with `Operator` level access or higher, better to create a dedicated user for that integration for faster issues identification -Password | Textbox | + | - | +Password | Textbox | + | - | Clear credentials | Check-box | + | Unchecked | Will reset username and password (Not being stored under options) -Unit | Drop-down | + | Bytes | Unit for sensors, available options are: Bytes, KiloBytes, MegaBytes -Consider away interval | Textbox | + | 180 | Consider away interval in seconds +Unit | Drop-down | + | Bytes | Unit for sensors, available options are: Bytes, KiloBytes, MegaBytes +Consider away interval | Textbox | + | 180 | Consider away interval in seconds Monitored devices | Drop-down | + | NONE | Devices to monitor using binary_sensor and sensor Monitored interfaces | Drop-down | + | NONE | Interfaces to monitor using binary_sensor and sensor, Track | Drop-down | + | NONE | Devices to track using device_trac @@ -65,7 +65,7 @@ Update Entities Interval | Textbox | + | 1 | Number of seconds to update entitie Save debug file | Check-box | + | Unchecked | Will store debug file, more details below (Not being stored under options) Log level | Drop-down | + | Default | Changes component's log level (more details below) Log incoming messages | Check-box | + | Unchecked | Whether to log as DEBUG incoming web-socket messages or not - + ###### Log Level's drop-down New feature to set the log level for the component without need to set log_level in `customization:` and restart or call manually `logger.set_level` and loose it after restart. @@ -75,28 +75,28 @@ In case `Default` option is chosen, flow will skip calling the service, after ch ###### Save debug file Will store debug data from the component to HA CONFIG path named `edgeos_data.log` - + ## Components #### Default Name | Type | State | Attributes | ---- | --- | --- | --- | +--- | --- | --- | --- | {Integration Name} System Status | Binary Sensor | Connected or not | CPU
Memory
Up-time
API Last Update
WS Last Update {Integration Name} System Uptime | Sensor | Time since restart in seconds | CPU
Memory
Is Alive
API Last Update
WS Last Update {Integration Name} Unknown Devices | Sensor | Number of unknown devices | Unknown Devices description -#### Monitored Devices +#### Monitored Devices Name | Type | State | Attributes | ---- | --- | --- | --- | +--- | --- | --- | --- | {Integration Name} Device {Device Name} | Binary Sensor | Connected or not | IP
MAC
Name
{Unit}Bytes (Sent)
{Unit}Bytes/ps (Sent)
{Unit}Bytes (Received)
{Unit}Bytes/ps (Received)
Last Activity
Last Changed -#### Monitored Interfaces +#### Monitored Interfaces Name | Type | State | Attributes | ---- | --- | --- | --- | +--- | --- | --- | --- | {Integration Name} Interface {Interface Name} | Binary Sensor | Connected or not | Name
Duplex
Link Speed (Mbps)
address
Packets (Received)
Packets (Sent)
Errors (Received)
Errors (Sent)
Dropped packets (Received)
Dropped packets (Sent)
{Unit}Bytes (Received)
{Unit}Bytes (Sent)
{Unit}Bytes/ps (Received)
{Unit}Bytes/ps (Sent)
Multicast
Last Changed #### Tracked Devices Name | Type | State | Attributes | ---- | --- | --- | --- | +--- | --- | --- | --- | {Integration Name} {Device Name} | Device Tracker | Home or Away | Host
IP
MAC
Name
Last Activity
Connected ### Setting up the integration diff --git a/pyproject.toml b/pyproject.toml index a9f7a40..86d9c24 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,2 @@ [tool.black] -target-version = ["py37", "py38"] \ No newline at end of file +target-version = ["py38"] diff --git a/setup.cfg b/setup.cfg index b98bb3d..1620535 100644 --- a/setup.cfg +++ b/setup.cfg @@ -37,4 +37,4 @@ sections = FUTURE,STDLIB,INBETWEENS,THIRDPARTY,FIRSTPARTY,LOCALFOLDER default_section = THIRDPARTY known_first_party = homeassistant,tests forced_separate = tests -combine_as_imports = true \ No newline at end of file +combine_as_imports = true