Skip to content

Commit

Permalink
New devcontainer configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
nbogojevic committed Feb 20, 2023
1 parent bf0277b commit 6c9da57
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 56 deletions.
11 changes: 4 additions & 7 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The easiest way to get started with custom integration development is to use Visual Studio Code with devcontainers. This approach will create a preconfigured development environment with all the tools you need.

In the container you will have a dedicated Home Assistant core instance running with your custom component code. You can configure this instance by updating the `./devcontainer/configuration.yaml` file.
In the container you will have a dedicated Home Assistant core instance running with your custom component code. You can configure this instance by updating the `./configuration.yaml` file.

**Prerequisites**

Expand Down Expand Up @@ -37,24 +37,21 @@ The available tasks are:

Task | Description
-- | --
Run Home Assistant on port 9123 | Launch Home Assistant with your custom component code and the configuration defined in `.devcontainer/configuration.yaml`.
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.
Run Home Assistant on port 8123 | Launch Home Assistant with your custom component code and the configuration defined in `./configuration.yaml`.

### 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
You need to modify the `configuration.yaml` file in `./` folder
by uncommenting the line:

```yaml
# debugpy:
```

Then launch the task `Run Home Assistant on port 9123`, and launch the debugger
Then launch the task `Run Home Assistant on port 8123`, 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/).
62 changes: 34 additions & 28 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
// See https://aka.ms/vscode-remote/devcontainer.json for format details.
{
"image": "ghcr.io/ludeeus/devcontainer/integration:stable",
"image": "mcr.microsoft.com/vscode/devcontainers/python:0-3.10-bullseye",
"name": "Midea Air Appliance (LAN) integration development",
"appPort": [
"9123:8123"
"forwardPorts": [
8123
],
"runArgs": [
"--cap-add=NET_ADMIN"
],
"postCreateCommand": [
"./.devcontainer/postCreateCommand.sh"
"./.devcontainer/setup.sh"
],
"extensions": [
"ms-python.python",
"github.vscode-pull-request-github",
"ryanluker.vscode-coverage-gutters",
"ms-python.vscode-pylance"
],
"settings": {
"files.eol": "\n",
"editor.tabSize": 4,
"terminal.integrated.defaultProfile.linux": "bash",
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash"
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"github.vscode-pull-request-github",
"ryanluker.vscode-coverage-gutters",
"ms-python.vscode-pylance"
],
"settings": {
"files.eol": "\n",
"editor.tabSize": 4,
"terminal.integrated.defaultProfile.linux": "bash",
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash"
}
},
"python.pythonPath": "/usr/bin/python3",
"python.analysis.autoSearchPaths": false,
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.formatting.provider": "black",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"files.trimTrailingWhitespace": true
}
},
"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
}
}
},
"remoteUser": "vscode"
}
8 changes: 8 additions & 0 deletions .devcontainer/develop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -e

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

# Start Home Assistant
hass -c . --debug
11 changes: 11 additions & 0 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -e

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

# Create custom components dummy module file
touch custom_components/__init__.py

# Install requirements
python3 -m pip install --requirement requirements.txt
17 changes: 16 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,19 @@ dmypy.json
.pyre/

# custom components dummy module file
custom_components/__init__.py
custom_components/__init__.py

# Home Assistant configuration
.cloud
.HA_VERSION
.storage
automations.yaml
blueprints
configuration.yaml
deps
home-assistant_v2*
home-assistant.log*
tts
scenes.yaml
scripts.yaml
secrets.yaml
22 changes: 2 additions & 20 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": ".devcontainer/develop.sh",
"problemMatcher": []
}
]
Expand Down
9 changes: 9 additions & 0 deletions configuration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

# Loads default set of integrations. Do not remove.
default_config:

logger:
default: info
logs:
custom_components.midea_dehumidifier_lan: info
midea_beautiful: info
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pip>=21.0,<23.1
colorlog
homeassistant

0 comments on commit 6c9da57

Please sign in to comment.