Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 47 additions & 15 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,52 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.177.0/containers/python-3/.devcontainer/base.Dockerfile
FROM mcr.microsoft.com/devcontainers/python:1-3.12

FROM mcr.microsoft.com/vscode/devcontainers/python:0-3.11
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# [Option] Install Node.js
ARG INSTALL_NODE="true"
ARG NODE_VERSION="lts/*"
RUN if [ "${INSTALL_NODE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
# Uninstall pre-installed formatting and linting tools
# They would conflict with our pinned versions
RUN \
pipx uninstall pydocstyle \
&& pipx uninstall pycodestyle \
&& pipx uninstall mypy \
&& pipx uninstall pylint

# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image.
# COPY requirements.txt /tmp/pip-tmp/
# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
# && rm -rf /tmp/pip-tmp
RUN \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
# Additional library needed by some tests and accordingly by VScode Tests Discovery
bluez \
ffmpeg \
libudev-dev \
libavformat-dev \
libavcodec-dev \
libavdevice-dev \
libavutil-dev \
libgammu-dev \
libswscale-dev \
libswresample-dev \
libavfilter-dev \
libpcap-dev \
libturbojpeg0 \
libyaml-dev \
libxml2 \
git \
cmake \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
# Install uv
RUN pip3 install uv

# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
WORKDIR /usr/src

USER vscode
ENV VIRTUAL_ENV="/home/vscode/.local/ic-venv"
RUN uv venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

WORKDIR /workspaces/ha-elro-connects

# Set the default shell to bash instead of sh
ENV SHELL /bin/bash
RUN source $VIRTUAL_ENV/bin/activate
125 changes: 57 additions & 68 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,73 +1,62 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.177.0/containers/python-3
{
"name": "ha-elro-connects",
"build": {
"dockerfile": "Dockerfile",
"context": "..",
"args": {
// Update 'VARIANT' to pick a Python version: 3, 3.6, 3.7, 3.8, 3.9
"VARIANT": "3.11",
// Options
"INSTALL_NODE": "false",
"NODE_VERSION": "lts/*"
}
"context": "..",
"postCreateCommand": "script/setup",
"dockerFile": "./Dockerfile",
"containerEnv": {
"PYTHONASYNCIODEBUG": "1"
},

// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.profiles.linux": {
"zsh (login)": {
"path": "zsh",
"args": ["-l"]
}
},
"python.pythonPath": "/usr/local/bin/python",
"python.languageServer": "Pylance",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.provider": "black",
"python.testing.pytestArgs": [],
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"files.trimTrailingWhitespace": true,
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {}
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"visualstudioexptteam.vscodeintellicode",
"redhat.vscode-yaml",
"esbenp.prettier-vscode",
"GitHub.vscode-pull-request-github"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pip3 install --user -r requirements_dev.txt && pre-commit install",

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",

// Advertize container environment
"containerEnv": { "DEVCONTAINER": "1" },

// Setup appdaemon environment
"runArgs": [
"--env-file",
"${localWorkspaceFolder}/.devcontainer/devcontainer.env"
]
"appPort": [],
"runArgs": ["-e", "GIT_EDITOR=code --wait"],
"customizations": {
"vscode": {
"extensions": [
"charliermarsh.ruff",
"ms-python.python",
"ms-python.pylint",
"ms-python.vscode-pylance",
"visualstudioexptteam.vscodeintellicode",
"redhat.vscode-yaml",
"esbenp.prettier-vscode",
"GitHub.vscode-pull-request-github"
],
// Please keep this file in sync with settings in .vscode/settings.default.json
"settings": {
"python.experiments.optOutFrom": ["pythonTestAdapter"],
"python.defaultInterpreterPath": "/home/vscode/.local/ic-venv/bin/python",
"python.pythonPath": "/home/vscode/.local/ic-venv/bin/python",
"python.terminal.activateEnvInCurrentTerminal": true,
"python.testing.pytestArgs": ["--no-cov"],
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"files.trimTrailingWhitespace": true,
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/usr/bin/zsh"
}
},
"terminal.integrated.defaultProfile.linux": "zsh",
"yaml.customTags": [
"!input scalar",
"!secret scalar",
"!include_dir_named scalar",
"!include_dir_list scalar",
"!include_dir_merge_list scalar",
"!include_dir_merge_named scalar"
],
"[python]": {
"editor.defaultFormatter": null,
"editor.formatOnSave": true,
"python.formatting.provider": "black",
"python.formatting.blackArgs": ["-l 120"],
"editor.formatOnType": true,
"python.formatting.blackPath": "/usr/local/py-utils/bin/black"
}
}
}
}
}
1 change: 1 addition & 0 deletions custom_components/elro_connects/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The Elro Connects integration."""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions custom_components/elro_connects/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Config flow for Elro Connects integration."""

from __future__ import annotations

import logging
Expand Down
17 changes: 11 additions & 6 deletions custom_components/elro_connects/device.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Elro Connects K1 device communication."""

from __future__ import annotations

import asyncio
Expand Down Expand Up @@ -155,9 +156,11 @@ async def _async_device_updated(self, event: Event) -> None:
await self.async_command(
SET_DEVICE_NAME,
device_ID=device_id,
device_name=device_entry.name_by_user[:15]
if len(device_entry.name_by_user) > 15
else device_entry.name_by_user,
device_name=(
device_entry.name_by_user[:15]
if len(device_entry.name_by_user) > 15
else device_entry.name_by_user
),
)

async def _async_fetch_connector_data(self) -> None:
Expand Down Expand Up @@ -261,9 +264,11 @@ def device_info(self) -> DeviceInfo:
device_info = DeviceInfo(
identifiers={(DOMAIN, f"{self._connector_id}_{self._device_id}")},
manufacturer="Elro",
model=DEVICE_MODELS[device_type]
if device_type in DEVICE_MODELS
else device_type,
model=(
DEVICE_MODELS[device_type]
if device_type in DEVICE_MODELS
else device_type
),
name=self.data.get(ATTR_NAME, None),
# Link to K1 connector
via_device=(dr.CONNECTION_NETWORK_MAC, mac_address),
Expand Down
1 change: 1 addition & 0 deletions custom_components/elro_connects/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Helper functions for Elro Connects."""

from __future__ import annotations

from elro.device import ATTR_DEVICE_TYPE
Expand Down
1 change: 1 addition & 0 deletions custom_components/elro_connects/sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The Elro Connects sensor platform."""

from __future__ import annotations

from dataclasses import dataclass
Expand Down
1 change: 1 addition & 0 deletions custom_components/elro_connects/siren.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The Elro Connects siren platform."""

from __future__ import annotations

from dataclasses import dataclass
Expand Down
1 change: 1 addition & 0 deletions custom_components/elro_connects/switch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The Elro Connects switch platform."""

from __future__ import annotations

from dataclasses import dataclass
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Elro Connects",
"hacs": "1.0.0",
"homeassistant": "2023.7.2"
"homeassistant": "2024.4.7"
}
4 changes: 4 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ The `device_state` sensor can have of the following states:
- `normal`
- `unknown`
- `offline`
- `open`
- `closed`
- `low_battery`
- `temperature_alarm`

Note that the sensors are polled about every 15 seconds. So it might take some time before an alarm state will be propagated. If an unknown state is found that is not supported yet, the hexadecimal code will be assigned as state. Please open an issue [here](https://github.com/jbouwh/lib-elro-connects/issues/new) if a new state needs to be supported.

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ forced_separate = [
combine_as_imports = true

[tool.pylint.MAIN]
py-version = "3.9"
py-version = "3.12"
ignore = [
"tests",
]
Expand Down
37 changes: 33 additions & 4 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
pre-commit==3.3.1
lib-elro-connects==0.6.0.1
homeassistant==2023.7.2
pytest-homeassistant-custom-component==0.13.44
lib-elro-connects>=0.6.2.0
homeassistant>=2024.4.7
pytest-homeassistant-custom-component>=0.13.148

aioresponses>=0.7.8

setuptools>=80.9.0
setuptools-scm>=8.1.0
wheel>=0.45.1

black>=25.1.0
debugpy>=1.8.15
pre-commit>=4.2.0
#
isort>=6.0.1
pycodestyle>=2.14.0
pydocstyle>=6.3.0
pyflakes>=3.4.0
#
poetry>=2.1.4
#
pytest-asyncio>=0.23.6
pytest-aiohttp>=1.0.5
pytest-cov>=5.0.0
pytest-freezer>=0.4.8
pytest-github-actions-annotate-failures>=0.2.0
pytest-socket>=0.7.0
pytest-sugar>=1.0.0
pytest-timeout>=2.3.1
pytest-unordered>=0.6.0
pytest-picked>=0.5.0
pytest-xdist>=3.6.1
pytest>=8.2.0
10 changes: 10 additions & 0 deletions script/bootstrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
# Resolve all dependencies that the application requires to run.

# Stop on errors
set -e

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

echo "Installing development dependencies..."
uv pip install -r requirements_dev.txt
39 changes: 39 additions & 0 deletions script/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
# Setups the repository.

# Stop on errors
set -e

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

# Add default vscode settings if not existing
SETTINGS_FILE=./.vscode/settings.json
SETTINGS_TEMPLATE_FILE=./.vscode/settings.default.json
if [ ! -f "$SETTINGS_FILE" ]; then
echo "Copy $SETTINGS_TEMPLATE_FILE to $SETTINGS_FILE."
cp "$SETTINGS_TEMPLATE_FILE" "$SETTINGS_FILE"
fi

if [ ! -n "$VIRTUAL_ENV" ]; then
if [ -x "$(command -v uv)" ]; then
uv venv venv
else
python3 -m venv venv
fi
source venv/bin/activate
fi

if ! [ -x "$(command -v uv)" ]; then
python3 -m pip install uv
fi

source $VIRTUAL_ENV/bin/activate

script/bootstrap

pre-commit install

echo "Setup done!"
echo "Activate the python venv: ic-venv by installing the Python extension (and debugger) in the dev container."
echo "To activate the venv manually in a shell, run:"
echo "source \$VIRTUAL_ENV/bin/activate"
Loading
Loading