Skip to content

Commit

Permalink
feat: rework and update devcontainer
Browse files Browse the repository at this point in the history
  • Loading branch information
jcwillox committed Jul 29, 2023
1 parent ef9903f commit 436f68c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 68 deletions.
16 changes: 8 additions & 8 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ In the container you will have a dedicated Home Assistant core instance running

- [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
- Docker
- For Linux, macOS, or Windows 10 Pro/Enterprise/Education use the [current release version of Docker](https://docs.docker.com/install/)
- Windows 10 Home requires [WSL 2](https://docs.microsoft.com/windows/wsl/wsl2-install) and the current Edge version of Docker Desktop (see instructions [here](https://docs.docker.com/docker-for-windows/wsl-tech-preview/)). This can also be used for Windows Pro/Enterprise/Education.
- For Linux, macOS, or Windows 10 Pro/Enterprise/Education use the [current release version of Docker](https://docs.docker.com/install/)
- Windows 10 Home requires [WSL 2](https://docs.microsoft.com/windows/wsl/wsl2-install) and the current Edge version of Docker Desktop (see instructions [here](https://docs.docker.com/docker-for-windows/wsl-tech-preview/)). This can also be used for Windows Pro/Enterprise/Education.
- [Visual Studio code](https://code.visualstudio.com/)
- [Remote - Containers (VSC Extension)][extension-link]

Expand All @@ -35,12 +35,12 @@ When a task is currently running (like `Run Home Assistant on port 9123` for the

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.
| 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. |

### Step by Step debugging

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Loads default set of integrations. Do not remove.
default_config:

logger:
default: info
logs:
custom_components.auto_backup: debug

backup:
# If you need to debug uncomment the line below (doc: https://www.home-assistant.io/integrations/debugpy/)
# debugpy:

automation: !include automations.yaml
73 changes: 43 additions & 30 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
// See https://aka.ms/vscode-remote/devcontainer.json for format details.
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"image": "ghcr.io/ludeeus/devcontainer/integration:stable",
"name": "Auto Backup integration development",
"context": "..",
"appPort": [
"9123:8123"
],
"postCreateCommand": "container install",
"extensions": [
"ms-python.python",
"github.vscode-pull-request-github",
"ryanluker.vscode-coverage-gutters",
"ms-python.vscode-pylance",
"keesschollaart.vscode-home-assistant"
],
"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
}
}
"name": "jcwillox/hass-auto-backup",

// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bookworm",

// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers-contrib/features/poetry:2": {}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [8123],
"portsAttributes": {
"8123": {
"label": "Home Assistant",
"onAutoForward": "notify"
}
},

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "poetry install",

// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"editorconfig.editorconfig",
"christian-kohler.path-intellisense",
"esbenp.prettier-vscode",
"redhat.vscode-yaml",
"ms-python.python",
"ms-python.black-formatter",
"keesschollaart.vscode-home-assistant",
"tamasfe.even-better-toml"
]
}
}

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
5 changes: 5 additions & 0 deletions .devcontainer/hass.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

export PYTHONPATH="${PYTHONPATH}:${PWD}/custom_components"

hass -c .devcontainer/config --debug
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,5 @@ cython_debug/

# PyCharm
.idea/
.devcontainer/config/*
!.devcontainer/config/configuration.yaml
38 changes: 10 additions & 28 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run Home Assistant on port 9123",
"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",
"problemMatcher": []
}
]
}
"version": "2.0.0",
"tasks": [
{
"label": "Run Home Assistant on port 8123",
"type": "shell",
"command": "poetry run .devcontainer/hass.sh",
"problemMatcher": []
}
]
}

0 comments on commit 436f68c

Please sign in to comment.