diff --git a/.devcontainer/README.md b/.devcontainer/README.md index 60458f6..e52fdf3 100644 --- a/.devcontainer/README.md +++ b/.devcontainer/README.md @@ -41,3 +41,20 @@ Run Home Assistant on port 9123 | Launch Home Assistant with your custom compone Run Home Assistant configuration against /config | Check the configuration. Upgrade Home Assistant to latest dev | Upgrade the Home Assistant core version in the container to the latest version of the `dev` branch. Install a specific version of Home Assistant | Install a specific version of Home Assistant core in the container. + +### Step by Step debugging + +With the development container, +you can test your custom component in Home Assistant with step by step debugging. + +You need to modify the `configuration.yaml` file in `.devcontainer` folder +by uncommenting the line: + +```yaml +# debugpy: +``` + +Then launch the task `Run Home Assistant on port 9123`, and launch the debugger +with the existing debugging configuration `Python: Attach Local`. + +For more information, look at [the Remote Python Debugger integration documentation](https://www.home-assistant.io/integrations/debugpy/). \ No newline at end of file diff --git a/.devcontainer/configuration.yaml b/.devcontainer/configuration.yaml index 7af7f06..9ff9d4b 100644 --- a/.devcontainer/configuration.yaml +++ b/.devcontainer/configuration.yaml @@ -4,3 +4,6 @@ logger: default: error logs: custom_components.sagemcom_fast: debug + +# If you need to debug uncomment the line below (doc: https://www.home-assistant.io/integrations/debugpy/) +# debugpy: diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 0bdbaad..33278f9 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,39 +1,36 @@ // See https://aka.ms/vscode-remote/devcontainer.json for format details. { - "image": "ghcr.io/ludeeus/devcontainer/integration:latest", + "image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye", "name": "ha-sagemcom-fast", - "context": "..", - "appPort": [ - "8123:8123" - ], - "postCreateCommand": "container install && pip install -r requirements_dev.txt && pre-commit install && pre-commit install-hooks", - "extensions": [ - "ms-python.python", - "github.vscode-pull-request-github", - "github.copilot", - "ms-python.vscode-pylance" - ], - "settings": { - "files.eol": "\n", - "editor.tabSize": 4, - "terminal.integrated.defaultProfile.linux": "bash", - "terminal.integrated.profiles.linux": { - "zsh": { - "path": "/bin/bash" - } - }, - "python.analysis.autoSearchPaths": false, - "python.linting.pylintEnabled": true, - "python.linting.enabled": true, - "python.linting.pylintArgs": [ - "--disable", - "import-error" - ], - "python.formatting.provider": "black", - "editor.formatOnPaste": false, - "editor.formatOnSave": true, - "editor.formatOnType": true, - "files.trimTrailingWhitespace": true, - "python.linting.mypyEnabled": true, + "forwardPorts": [8123], + "portsAttributes": { + "8123": { + "label": "Home Assistant", + "onAutoForward": "openBrowserOnce" + } + }, + "postCreateCommand": "pip install -r requirements_dev.txt && pre-commit install && pre-commit install-hooks", + "containerEnv": { + "DEVCONTAINER": "1" + }, + "remoteUser": "vscode", + "customizations": { + "vscode": { + "extensions": [ + "ms-python.vscode-pylance", + "ms-python.python", + "redhat.vscode-yaml", + "esbenp.prettier-vscode", + "GitHub.vscode-pull-request-github", + "GitHub.copilot" + ], + "settings": { + "python.pythonPath": "/usr/local/bin/python", + "editor.formatOnPaste": false, + "editor.formatOnSave": true, + "editor.formatOnType": true, + "files.trimTrailingWhitespace": true + } + } } } \ No newline at end of file diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index b9b7614..9033f3e 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,2 +1 @@ * @iMicknl -* @arunpoudel \ No newline at end of file diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..8209473 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +custom: ["https://paypal.me/imick"] diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..a782f40 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,15 @@ +version: 2 +updates: + - package-ecosystem: pip + directory: "/" + schedule: + interval: "daily" + time: "08:00" + open-pull-requests-limit: 10 + + - package-ecosystem: github-actions + directory: "/" + schedule: + interval: "daily" + time: "08:00" + open-pull-requests-limit: 10 diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index f6d86ed..b946465 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -7,6 +7,6 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - - uses: pre-commit/action@v2.0.0 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + - uses: pre-commit/action@v3.0.0 diff --git a/.github/workflows/matchers/python.json b/.github/workflows/matchers/python.json deleted file mode 100644 index 1052a1c..0000000 --- a/.github/workflows/matchers/python.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "problemMatcher": [ - { - "owner": "python", - "pattern": [ - { - "regexp": "^\\s*File\\s\\\"(.*)\\\",\\sline\\s(\\d+),\\sin\\s(.*)$", - "file": 1, - "line": 2 - }, - { - "regexp": "^\\s*raise\\s(.*)\\(\\'(.*)\\'\\)$", - "message": 2 - } - ] - } - ] -} \ No newline at end of file diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index e260e45..a0683aa 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -3,7 +3,7 @@ name: Release Drafter on: push: branches: - - master + - main jobs: update_release_draft: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 3232e35..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: Test (pytest) - -on: - pull_request: - -jobs: - test: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.9", "3.10"] - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements_test.txt - - name: Register Python problem matcher - run: | - echo "::add-matcher::.github/workflows/matchers/python.json" - # - name: Install Pytest Annotation plugin - # run: | - # # Ideally this should be part of our dependencies - # # However this plugin is fairly new and doesn't run correctly - # # on a non-GitHub environment. - # pip install pytest-github-actions-annotate-failures - # - name: Test with pytest - # run: | - # pytest \ - # --cov custom_components/sagemcom_fast \ - # --cov-report=xml --cov-report=html \ - # -o console_output_style=count \ - # -p no:sugar \ - # tests - # - name: Upload coverage artifact - # uses: actions/upload-artifact@v2.1.3 - # with: - # name: coverage-${{ matrix.python-version }} - # path: htmlcov diff --git a/.gitignore b/.gitignore index 5a725e4..cfdf845 100644 --- a/.gitignore +++ b/.gitignore @@ -131,7 +131,9 @@ dmypy.json # Pyre type checker .pyre/ -# HA Config directory for local testing -/Config/ - **/.DS_Store + +# DevContainer +config +!.vscode/tasks.json +!.vscode/launch.json \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 685e82b..04c8674 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,11 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v2.7.2 + rev: v2.31.1 hooks: - id: pyupgrade args: [--py37-plus] - repo: https://github.com/psf/black - rev: 20.8b1 + rev: 22.3.0 hooks: - id: black args: @@ -13,7 +13,7 @@ repos: - --quiet files: ^((custom_components)/.+)?[^/]+\.py$ - repo: https://github.com/codespell-project/codespell - rev: v1.17.1 + rev: v2.1.0 hooks: - id: codespell args: @@ -21,8 +21,8 @@ repos: - --skip="./.*,*.csv,*.json,*.md" - --quiet-level=2 exclude_types: [csv, json] - - repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.4 + - repo: https://github.com/PyCQA/flake8 + rev: 3.9.2 hooks: - id: flake8 additional_dependencies: @@ -30,10 +30,10 @@ repos: - pydocstyle==5.1.1 files: ^(custom_components)/.+\.py$ - repo: https://github.com/PyCQA/isort - rev: 5.5.3 + rev: 5.12.0 hooks: - id: isort - repo: https://github.com/adrienverge/yamllint.git - rev: v1.24.2 + rev: v1.26.3 hooks: - id: yamllint diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..7af76d8 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Home Assistant with Sagemcom Fast", + "type": "python", + "request": "launch", + "python": "/usr/local/bin/python", + "module": "homeassistant", + "cwd": "${workspaceFolder}", + "justMyCode": false, + "args": ["--debug", "-c", "config"] + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 7ab4ba8..3e2ff12 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,27 +2,9 @@ "version": "2.0.0", "tasks": [ { - "label": "Run Home Assistant on port 9123", + "label": "Run Home Assistant on port 8123", "type": "shell", - "command": "container start", - "problemMatcher": [] - }, - { - "label": "Run Home Assistant configuration against /config", - "type": "shell", - "command": "container check", - "problemMatcher": [] - }, - { - "label": "Upgrade Home Assistant to latest dev", - "type": "shell", - "command": "container install", - "problemMatcher": [] - }, - { - "label": "Install a specific version of Home Assistant", - "type": "shell", - "command": "container set-version", + "command": "bash scripts/run", "problemMatcher": [] } ] diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..f7cd7c6 --- /dev/null +++ b/.yamllint @@ -0,0 +1,61 @@ +ignore: | + .github +rules: + braces: + level: error + min-spaces-inside: 0 + max-spaces-inside: 1 + min-spaces-inside-empty: -1 + max-spaces-inside-empty: -1 + brackets: + level: error + min-spaces-inside: 0 + max-spaces-inside: 0 + min-spaces-inside-empty: -1 + max-spaces-inside-empty: -1 + colons: + level: error + max-spaces-before: 0 + max-spaces-after: 1 + commas: + level: error + max-spaces-before: 0 + min-spaces-after: 1 + max-spaces-after: 1 + comments: + level: error + require-starting-space: true + min-spaces-from-content: 2 + comments-indentation: + level: error + document-end: + level: error + present: false + document-start: + level: error + present: false + empty-lines: + level: error + max: 1 + max-start: 0 + max-end: 1 + hyphens: + level: error + max-spaces-after: 1 + indentation: + level: error + spaces: 2 + indent-sequences: true + check-multi-line-strings: false + key-duplicates: + level: error + line-length: disable + new-line-at-end-of-file: + level: error + new-lines: + level: error + type: unix + trailing-spaces: + level: error + truthy: + level: warning diff --git a/README.md b/README.md index ea6cb5e..a2d131f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ - -![screenshot of a device detail page in Home Assistant](https://raw.githubusercontent.com/iMicknl/ha-sagemcom-fast/master/media/sagemcom_fast_device_page.png) +![screenshot of a device detail page in Home Assistant](https://raw.githubusercontent.com/iMicknl/ha-sagemcom-fast/main/media/sagemcom_fast_device_page.png) [![GitHub release](https://img.shields.io/github/release/iMicknl/ha-sagemcom-fast.svg)](https://github.com/iMicknl/ha-sagemcom-fast/releases/) [![HA integration usage](https://img.shields.io/badge/dynamic/json?color=41BDF5&logo=home-assistant&label=integration%20usage&suffix=%20installs&cacheSeconds=15600&url=https://analytics.home-assistant.io/custom_integrations.json&query=$.sagemcom_fast.total)](https://analytics.home-assistant.io/custom_integrations.json) @@ -10,11 +9,13 @@ This integration adds support for Sagemcom F@st routers to Home Assistant. Curre Sagemcom F@st routers are used by many providers worldwide, but many of them did rebrand the router. Examples are the b-box from Proximus, Home Hub from bell and the Smart Hub from BT. ## Installation + ### Manual Copy the `custom_components/sagemcom_fast` to your `custom_components` folder. Reboot Home Assistant and install the Sagemcom F@st integration via the integrations config flow. ### HACS + Add this repository as a custom repository to HACS as described [here](https://hacs.xyz/docs/faq/custom_repositories), search for the `Sagemcom F@st` integration and choose install. Reboot Home Assistant and install the Sagemcom F@st integration via the integrations config flow. ``` @@ -23,7 +24,7 @@ https://github.com/imicknl/ha-sagemcom-fast ## Usage -This integration can only be confgured via the Config Flow. Go to `Configuration -> Integrations -> Add Integration` and choose Sagemcom F@st. The prompt will ask you for your credentials. Please note that some routers require authentication, where others can login with `guest` username and an empty password. +This integration can only be configured via the Config Flow. Go to `Configuration -> Integrations -> Add Integration` and choose Sagemcom F@st. The prompt will ask you for your credentials. Please note that some routers require authentication, where others can login with `guest` username and an empty password. The encryption method differs per device. Please refer to the table below to understand which option to select. If your device is not listed, please try both methods one by one. @@ -32,7 +33,7 @@ The encryption method differs per device. Please refer to the table below to und Have a look at the table below for more information about supported devices. | Router Model | Provider(s) | Authentication Method | Comments | -|-----------------------|----------------------|-----------------------|-------------------------------| +| --------------------- | -------------------- | --------------------- | ----------------------------- | | Sagemcom F@st 3864 | Optus | sha512 | username: guest, password: "" | | Sagemcom F@st 3865b | Proximus (b-box3) | md5 | | | Sagemcom F@st 3890V3 | Delta / Zeelandnet | md5 | | @@ -62,7 +63,6 @@ logger: custom_components.sagemcom_fast: debug ``` - ### Device not supported / working correctly If you are not able to use this integration with your Sagemcom F@st device, please create [an issue](https://github.com/iMicknl/ha-sagemcom-fast/issues/new) with as much information as possible. Turn on debug logging and share the logs in your issue description. diff --git a/custom_components/sagemcom_fast/device_tracker.py b/custom_components/sagemcom_fast/device_tracker.py index 47e9b4e..1305f43 100644 --- a/custom_components/sagemcom_fast/device_tracker.py +++ b/custom_components/sagemcom_fast/device_tracker.py @@ -5,7 +5,7 @@ from typing import Any, Dict, Optional import async_timeout -from homeassistant.components.device_tracker import SOURCE_TYPE_ROUTER +from homeassistant.components.device_tracker import SourceType from homeassistant.components.device_tracker.config_entry import ScannerEntity from homeassistant.core import HomeAssistant from homeassistant.helpers.restore_state import RestoreEntity @@ -107,7 +107,7 @@ def unique_id(self) -> str: @property def source_type(self) -> str: """Return the source type, eg gps or router, of the device.""" - return SOURCE_TYPE_ROUTER + return SourceType.ROUTER @property def is_connected(self) -> bool: diff --git a/custom_components/sagemcom_fast/manifest.json b/custom_components/sagemcom_fast/manifest.json index c0ee6ed..2524d35 100644 --- a/custom_components/sagemcom_fast/manifest.json +++ b/custom_components/sagemcom_fast/manifest.json @@ -1,12 +1,16 @@ { "domain": "sagemcom_fast", "name": "Sagemcom F@st", - "version": "0.2.9", + "codeowners": [ + "@imicknl", + "@arunpoudel" + ], "config_flow": true, "documentation": "https://github.com/imicknl/ha-sagemcom-fast", + "iot_class": "local_polling", "issue_tracker": "https://github.com/imicknl/ha-sagemcom-fast/issues", "requirements": [ - "sagemcom_api===1.0.8" + "sagemcom_api==1.1.0" ], "ssdp": [ { @@ -18,9 +22,5 @@ "manufacturer": "Sagemcom Broadband SAS" } ], - "codeowners": [ - "@imicknl", - "@arunpoudel" - ], - "iot_class": "local_polling" + "version": "0.2.9" } diff --git a/hacs.json b/hacs.json index bd0b719..971aa28 100644 --- a/hacs.json +++ b/hacs.json @@ -1,7 +1,5 @@ { "name": "Sagemcom F@st", - "domains": ["device_tracker", "sensor"], - "homeassistant": "0.115.0", - "render_readme": "true", - "iot_class": "Local Polling" - } \ No newline at end of file + "homeassistant": "2024.1.2", + "render_readme": true +} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 5a0403f..88c06b9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -sagemcom_api==1.0.8 \ No newline at end of file +sagemcom_api==1.1.0 \ No newline at end of file diff --git a/requirements_dev.txt b/requirements_dev.txt index 9fc4c8c..b266e5c 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,4 +1,4 @@ -r requirements.txt -homeassistant==2022.3.3 -pre-commit==2.5.0 \ No newline at end of file +homeassistant==2024.1.2 +pre-commit \ No newline at end of file diff --git a/requirements_test.txt b/requirements_test.txt deleted file mode 100644 index b66ed17..0000000 --- a/requirements_test.txt +++ /dev/null @@ -1,5 +0,0 @@ --r requirements_dev.txt - -pytest==7.0.1 -pytest-homeassistant-custom-component==0.7.2 # 2022.3.3 -pytest-timeout==2.1.0 \ No newline at end of file diff --git a/scripts/run b/scripts/run new file mode 100644 index 0000000..20366e8 --- /dev/null +++ b/scripts/run @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "$0")/.." + +# Create config dir if not present +if [[ ! -d "${PWD}/config" ]]; then + mkdir -p "${PWD}/config" + hass --config "${PWD}/config" --script ensure_config +fi + +# Set the path to custom_components +## This let's us have the structure we want /custom_components/integration_blueprint +## while at the same time have Home Assistant configuration inside /config +## without resulting to symlinks. +export PYTHONPATH="${PYTHONPATH}:${PWD}/custom_components" + +# Start Home Assistant +hass --config "${PWD}/config" --debug \ No newline at end of file