Skip to content

Commit

Permalink
Merge branch 'amosyuen:main' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
misa1515 committed Nov 3, 2023
2 parents 5e3d59b + 399fef9 commit 7aa8d97
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 130 deletions.
52 changes: 25 additions & 27 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
// See https://aka.ms/vscode-remote/devcontainer.json for format details.
{
"image": "ghcr.io/ludeeus/devcontainer/integration:stable",
"name": "TP-Link Deco integration development",
"context": "..",
"appPort": ["9123:8123"],
"postCreateCommand": ".devcontainer/setup.sh",
"mounts": [
"source=${localEnv:HOME}${localEnv:USERPROFILE}/.gitconfig,target=/root/.gitconfig,type=bind,consistency=cached"
],
"extensions": [
"ms-python.python",
"github.vscode-pull-request-github",
"ryanluker.vscode-coverage-gutters",
"ms-python.vscode-pylance",
"esbenp.prettier-vscode"
],
"settings": {
"files.eol": "\n",
"editor.tabSize": 4,
"terminal.integrated.shell.linux": "/bin/bash",
"python.pythonPath": "/usr/bin/python3",
"python.analysis.autoSearchPaths": false,
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.formatting.provider": "black",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"files.trimTrailingWhitespace": true
"image": "mcr.microsoft.com/devcontainers/python:3.11-bullseye",
"postStartCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}",
"postAttachCommand": ".devcontainer/setup.sh",
"forwardPorts": [8123],
"portsAttributes": {
"8123": {
"label": "Home Assistant",
"onAutoForward": "notify"
}
},
"customizations": {
"vscode": {
"extensions": [
"esbenp.prettier-vscode",
"github.vscode-pull-request-github",
"ms-vscode-remote.remote-containers",
"ms-python.black-formatter",
"ms-python.vscode-pylance",
"ryanluker.vscode-coverage-gutters"
]
}
},
"remoteUser": "vscode",
"features": {
"ghcr.io/devcontainers/features/rust:1": {}
}
}
20 changes: 20 additions & 0 deletions .devcontainer/develop.sh
Original file line number Diff line number Diff line change
@@ -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 <root>/custom_components/integration_blueprint
## while at the same time have Home Assistant configuration inside <root>/config
## without resulting to symlinks.
export PYTHONPATH="${PYTHONPATH}:${PWD}/custom_components"

# Start Home Assistant
hass --config "${PWD}/config" --debug
4 changes: 1 addition & 3 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ set -e

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

pip3 install -r .github/workflows/constraints.txt
pip3 install --requirement requirements.txt
pre-commit install

container install
13 changes: 6 additions & 7 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
- package-ecosystem: pip
directory: "/.github/workflows"
schedule:
interval: daily
- package-ecosystem: pip
interval: weekly
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: daily
interval: weekly
ignore:
# Dependabot should not update Home Assistant as that should match the homeassistant key in hacs.json
- dependency-name: "homeassistant"
5 changes: 0 additions & 5 deletions .github/workflows/constraints.txt

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.5.1
uses: dependabot/fetch-metadata@v1.6.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Enable auto-merge for Dependabot PRs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ jobs:
uses: actions/checkout@v4

- name: Run Labeler
uses: crazy-max/ghaction-github-labeler@v4.2.0
uses: crazy-max/ghaction-github-labeler@v5.0.0
with:
skip-delete: true
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Run release-drafter
uses: release-drafter/release-drafter@v5.24.0
uses: release-drafter/release-drafter@v5.25.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 3 additions & 3 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ jobs:
uses: actions/checkout@v4

- name: Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/[email protected].0
uses: actions/[email protected].1
with:
python-version: ${{ env.DEFAULT_PYTHON }}

- name: Upgrade pip
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip install --constraint=requirements.txt pip
pip --version
- name: Install Python modules
run: |
pip install --constraint=.github/workflows/constraints.txt pre-commit black flake8 reorder-python-imports
pip install --constraint=requirements.txt pre-commit black flake8 reorder-python-imports
- name: Run pre-commit on all files
run: |
Expand Down
16 changes: 12 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# artifacts
__pycache__
pythonenv*
.python-version
.pytest*
*.egg-info
*/build/*
*/dist/*

# misc
.coverage
venv
.venv
coverage.xml

# Home Assistant configuration
config/*
!config/configuration.yaml
48 changes: 48 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# The contents of this file is based on https://github.com/home-assistant/core/blob/dev/pyproject.toml

target-version = "py310"

select = [
"B007", # Loop control variable {name} not used within loop body
"B014", # Exception handler with duplicate exception
"C", # complexity
"D", # docstrings
"E", # pycodestyle
"F", # pyflakes/autoflake
"ICN001", # import concentions; {name} should be imported as {asname}
"PGH004", # Use specific rule codes when using noqa
"PLC0414", # Useless import alias. Import alias does not rename original package.
"SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass
"SIM117", # Merge with-statements that use the same scope
"SIM118", # Use {key} in {dict} instead of {key} in {dict}.keys()
"SIM201", # Use {left} != {right} instead of not {left} == {right}
"SIM212", # Use {a} if {a} else {b} instead of {b} if not {a} else {a}
"SIM300", # Yoda conditions. Use 'age == 42' instead of '42 == age'.
"SIM401", # Use get from dict with default instead of an if block
"T20", # flake8-print
"TRY004", # Prefer TypeError exception for invalid type
"RUF006", # Store a reference to the return value of asyncio.create_task
"UP", # pyupgrade
"W", # pycodestyle
]

ignore = [
"D202", # No blank lines allowed after function docstring
"D203", # 1 blank line required before class docstring
"D213", # Multi-line docstring summary should start at the second line
"D404", # First word of the docstring should not be This
"D406", # Section name should end with a newline
"D407", # Section name underlining
"D411", # Missing blank line before section
"E501", # line too long
"E731", # do not assign a lambda expression, use a def
]

[flake8-pytest-style]
fixture-parentheses = false

[pyupgrade]
keep-runtime-typing = true

[mccabe]
max-complexity = 25
34 changes: 0 additions & 34 deletions .vscode/launch.json

This file was deleted.

17 changes: 11 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
{
"python.linting.pylintArgs": ["--rcfile=setup.cfg"],
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.pythonPath": "venv/bin/python",
"files.associations": {
"*.yaml": "home-assistant"
"analysis.autoSearchPaths": false,
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"editor.formatOnSave": true,
"editor.tabSize": 4,
"files.eol": "\n",
"files.trimTrailingWhitespace": true,
"terminal.integrated.shell.linux": "/bin/bash",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
}
}
22 changes: 2 additions & 20 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,14 @@
"version": "2.0.0",
"tasks": [
{
"label": "Run Home Assistant on port 9123",
"label": "Run Home Assistant on port 8123",
"type": "shell",
"command": "container start",
"command": ".devcontainer/develop.sh",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"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",
"problemMatcher": []
}
]
}
File renamed without changes.
21 changes: 6 additions & 15 deletions custom_components/tplink_deco/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ async def async_create_config_data(hass: HomeAssistant, config_entry: ConfigEntr

async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
"""Set up this integration using UI."""
_LOGGER.debug("async_setup_entry: Config entry %s", config_entry.entry_id)

if hass.data.get(DOMAIN) is None:
hass.data.setdefault(DOMAIN, {})

Expand Down Expand Up @@ -194,11 +196,13 @@ async def async_reboot_deco(service: ServiceCall) -> None:
)

config_entry.async_on_unload(config_entry.add_update_listener(update_listener))

return True


async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Handle removal of an entry."""
_LOGGER.debug("async_unload_entry: Config entry %s", config_entry.entry_id)
data = hass.data[DOMAIN][config_entry.entry_id]
deco_coordinator = data.get(COORDINATOR_DECOS_KEY)
clients_coordinator = data.get(COORDINATOR_CLIENTS_KEY)
Expand All @@ -223,27 +227,14 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->

async def async_reload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
"""Reload config entry."""
_LOGGER.debug("async_reload_entry: Config entry %s", config_entry)
await async_unload_entry(hass, config_entry)
await async_setup_entry(hass, config_entry)


async def update_listener(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
"""Update options."""
if not config_entry.options or config_entry.data == config_entry.options:
_LOGGER.debug(
"update_listener: No changes in options for %s", config_entry.entry_id
)
return

_LOGGER.debug(
"update_listener: Updating options and reloading %s", config_entry.entry_id
)
hass.config_entries.async_update_entry(
entry=config_entry,
title=config_entry.options.get(CONF_HOST),
data=config_entry.options,
options={},
)
_LOGGER.debug("update_listener: Reloading %s", config_entry.entry_id)
await async_reload_entry(hass, config_entry)


Expand Down
Loading

0 comments on commit 7aa8d97

Please sign in to comment.