Skip to content

Commit

Permalink
Add lots of tests, dev container
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawolanin committed Jan 23, 2022
1 parent c7fac62 commit c361dd6
Show file tree
Hide file tree
Showing 20 changed files with 1,178 additions and 291 deletions.
60 changes: 60 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
## Developing with Visual Studio Code + devcontainer

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.

**Prerequisites**

- [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.
- [Visual Studio code](https://code.visualstudio.com/)
- [Remote - Containers (VSC Extension)][extension-link]

[More info about requirements and devcontainer in general](https://code.visualstudio.com/docs/remote/containers#_getting-started)

[extension-link]: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers

**Getting started:**

1. Fork the repository.
2. Clone the repository to your computer.
3. Open the repository using Visual Studio code.

When you open this repository with Visual Studio code you are asked to "Reopen in Container", this will start the build of the container.

_If you don't see this notification, open the command palette and select `Remote-Containers: Reopen Folder in Container`._

### Tasks

The devcontainer comes with some useful tasks to help you with development, you can start these tasks by opening the command palette and select `Tasks: Run Task` then select the task you want to run.

When a task is currently running (like `Run Home Assistant on port 9123` for the docs), it can be restarted by opening the command palette and selecting `Tasks: Restart Running Task`, then select the task you want to restart.

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.

### 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/).
9 changes: 9 additions & 0 deletions .devcontainer/configuration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
default_config:

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

# If you need to debug uncomment the line below (doc: https://www.home-assistant.io/integrations/debugpy/)
debugpy:
31 changes: 31 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// See https://aka.ms/vscode-remote/devcontainer.json for format details.
{
"image": "ludeeus/container:integration-debian",
"name": "Mail And Packages integration development",
"context": "..",
"appPort": [
"9123:8123",
"5678:5678"
],
"postCreateCommand": "container install",
"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.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
}
}
35 changes: 35 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
// Example of attaching to local debug server
"name": "Python: Attach Local",
"type": "python",
"request": "attach",
"port": 5678,
"host": "localhost",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "."
}
]
},
{
// Example of attaching to my production server
"name": "Python: Attach Remote",
"type": "python",
"request": "attach",
"port": 5678,
"host": "homeassistant.local",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/usr/src/homeassistant"
}
]
}
]
}

29 changes: 29 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"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": []
}
]
}
116 changes: 68 additions & 48 deletions custom_components/mail_and_packages/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,35 +224,35 @@
"royal_packages": {},
"royal_tracking": {"pattern": ["[A-Za-z]{2}[0-9]{9}GB"]},
# Poczta Polska SA
"pocztapolska_delivered": {},
"pocztapolska_delivering": {
"poczta_polska_delivered": {},
"poczta_polska_delivering": {
"email": ["[email protected]", "[email protected]"],
"subject": ["Poczta Polska S.A. eINFO"],
},
"pocztapolska_packages": {},
"pocztapolska_tracking": {
"poczta_polska_packages": {},
"poczta_polska_tracking": {
# http://emonitoring.poczta-polska.pl/?numer=00359007738913296666
"pattern": ["\\d{20}"]
},
# InPost.pl
"inpostpl_delivered": {
"inpost_pl_delivered": {
"email": ["[email protected]", "[email protected]"],
"subject": [
"InPost - Potwierdzenie odbioru przesyłki",
"InPost - Paczka umieszczona w Paczkomacie",
],
},
"inpostpl_delivering": {
"email": ["[email protected]"],
"inpost_pl_delivering": {
"email": ["[email protected]", "[email protected]"],
"subject": ["paczka jest w drodze", "jest już prawie u Ciebie"],
},
"inpostpl_packages": {},
"inpostpl_tracking": {
"inpost_pl_packages": {},
"inpost_pl_tracking": {
# https://inpost.pl/sledzenie-przesylek?number=520113017830399002575123
"pattern": ["\\d{24}"]
},
# DPD Poland
"dpdcompl_delivered": {
"dpd_com_pl_delivered": {
"email": [
"[email protected]",
"[email protected]",
Expand All @@ -265,12 +265,13 @@
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
],
"subject": [
"została doręczona",
],
},
"dpdcompl_delivering": {
"dpd_com_pl_delivering": {
"email": [
"[email protected]",
"[email protected]",
Expand All @@ -283,26 +284,38 @@
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
],
"subject": [
"Bezpieczne_dor=C4=99czenie_Twojej_paczki",
"Bezpieczne doręczenie",
"przesyłka została nadana",
],
"subject": ["Bezpieczne doręczenie"],
"body": ["Dziś doręczamy"],
"body": ["Dzi=C5=9B dor=C4=99czamy", "DPD Polska"],
},
"dpdcompl_packages": {},
"dpdcompl_tracking": {
"dpd_com_pl_packages": {},
"dpd_com_pl_tracking": {
# https://tracktrace.dpd.com.pl/parcelDetails?p1=13490015284111
"pattern": ["\\d{13}[A-Z0-9]{1,2}"],
},
# GLS
"gls_delivered": {
"email": ["[email protected]"],
"email": [
"[email protected]",
"[email protected]",
],
"subject": [
"informacja o dostawie",
],
"body": ["została dzisiaj dostarczona"],
},
"gls_delivering": {
"email": ["[email protected]"],
"email": [
"[email protected]",
"[email protected]",
],
"subject": ["paczka w drodze"],
"body": ["Zespół GLS"],
},
"gls_packages": {},
"gls_tracking": {
Expand Down Expand Up @@ -527,71 +540,77 @@
key="auspost_packages",
),
# Poczta Polska SA
"pocztapolska_delivering": SensorEntityDescription(
name="Poczta Polska SA Packages Delivering",
# "poczta_polska_delivered": SensorEntityDescription(
# name="Poczta Polska Delivered",
# native_unit_of_measurement="package(s)",
# icon="mdi:package-variant",
# key="poczta_polska_delivered",
# ),
"poczta_polska_delivering": SensorEntityDescription(
name="Mail Poczta Polska Delivering",
native_unit_of_measurement="package(s)",
icon="mdi:truck-delivery",
key="pocztapolska_delivering",
key="poczta_polska_delivering",
),
"pocztapolska_packages": SensorEntityDescription(
name="Poczta Polska SA Packages",
"poczta_polska_packages": SensorEntityDescription(
name="Mail Poczta Polska Packages",
native_unit_of_measurement="package(s)",
icon="mdi:package-variant-closed",
key="pocztapolska_packages",
key="poczta_polska_packages",
),
"inpostpl_delivering": SensorEntityDescription(
name="InPost.pl Packages Delivering",
# InPost.pl
"inpost_pl_delivering": SensorEntityDescription(
name="Mail InPost.pl Delivering",
native_unit_of_measurement="package(s)",
icon="mdi:truck-delivery",
key="inpostpl_delivering",
key="inpost_pl_delivering",
),
# InPost.pl
"inpostpl_delivered": SensorEntityDescription(
name="InPost.pl Packages Delivered",
"inpost_pl_delivered": SensorEntityDescription(
name="Mail InPost.pl Delivered",
native_unit_of_measurement="package(s)",
icon="mdi:package-variant",
key="inpostpl_delivered",
key="inpost_pl_delivered",
),
"inpostpl_packages": SensorEntityDescription(
name="InPost.pl Packages",
"inpost_pl_packages": SensorEntityDescription(
name="Mail InPost.pl Packages",
native_unit_of_measurement="package(s)",
icon="mdi:package-variant-closed",
key="inpostpl_packages",
key="inpost_pl_packages",
),
# DPD Poland
"dpdcompl_delivering": SensorEntityDescription(
name="DPD.com.pl Packages Delivering",
"dpd_com_pl_delivering": SensorEntityDescription(
name="Mail DPD.com.pl Delivering",
native_unit_of_measurement="package(s)",
icon="mdi:truck-delivery",
key="dpdcompl_delivering",
key="dpd_com_pl_delivering",
),
"dpdcompl_delivered": SensorEntityDescription(
name="DPD.com.pl Packages Delivered",
"dpd_com_pl_delivered": SensorEntityDescription(
name="Mail DPD.com.pl Delivered",
native_unit_of_measurement="package(s)",
icon="mdi:package-variant",
key="dpdcompl_delivered",
key="dpd_com_pl_delivered",
),
"dpdcompl_packages": SensorEntityDescription(
name="DPD.com.pl Packages",
"dpd_com_pl_packages": SensorEntityDescription(
name="Mail DPD.com.pl Packages",
native_unit_of_measurement="package(s)",
icon="mdi:package-variant-closed",
key="dpdcompl_packages",
key="dpd_com_pl_packages",
),
# GLS
"gls_delivering": SensorEntityDescription(
name="GLS Packages Delivering",
name="Mail GLS Delivering",
native_unit_of_measurement="package(s)",
icon="mdi:truck-delivery",
key="gls_delivering",
),
"gls_delivered": SensorEntityDescription(
name="GLS Packages Delivered",
name="Mail GLS Delivered",
native_unit_of_measurement="package(s)",
icon="mdi:package-variant",
key="dpdcompl_delivered",
key="dpd_com_pl_delivered",
),
"gls_packages": SensorEntityDescription(
name="GLS Packages",
name="Mail GLS Packages",
native_unit_of_measurement="package(s)",
icon="mdi:package-variant-closed",
key="gls_packages",
Expand Down Expand Up @@ -649,7 +668,8 @@
"hermes",
"royal",
"auspost",
"inpostpl",
"dpdcompl",
"poczta_polska",
"inpost_pl",
"dpd_com_pl",
"gls",
]
Loading

0 comments on commit c361dd6

Please sign in to comment.