From e0618176bd271e09e8c1236bb234f678d8738be8 Mon Sep 17 00:00:00 2001 From: bullshit Date: Wed, 6 Aug 2025 14:46:22 +0200 Subject: [PATCH] feat(build): devcontainer setup Signed-off-by: bullshit --- .devcontainer/devcontainer.json | 80 +++++++++++++++++++++++++++++++++ .devcontainer/setup.sh | 57 +++++++++++++++++++++++ tools/scan-usb.sh | 14 ++++++ 3 files changed, 151 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100755 .devcontainer/setup.sh create mode 100755 tools/scan-usb.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..972d66d --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,80 @@ +{ + "name": "ESPHome NUT UPS Development", + "image": "ghcr.io/esphome/esphome:latest", + "features": { + "ghcr.io/devcontainers/features/git:1": {}, + "ghcr.io/devcontainers/features/github-cli:1": {}, + "ghcr.io/devcontainers/features/python:1": { + "version": "3.11", + "installTools": true + }, + "ghcr.io/anthropics/devcontainer-features/claude-code:1.0.5": {} + }, + "mounts": [ + "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached", + "source=/dev,target=/dev,type=bind" + ], + "privileged": true, + "runArgs": [ + "--device-cgroup-rule=c 188:* rmw", + "--device-cgroup-rule=c 189:* rmw", + "--device=/dev/bus/usb:/dev/bus/usb:rwm" + ], + "workspaceFolder": "/workspace", + "postCreateCommand": "bash .devcontainer/setup.sh", + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python", + "ms-python.flake8", + "ms-python.black-formatter", + "redhat.vscode-yaml", + "ms-vscode.cpptools", + "ms-vscode.cmake-tools", + "esphome.esphome-vscode", + "platformio.platformio-ide", + "ms-vscode.hexeditor" + ], + "settings": { + "python.defaultInterpreterPath": "/usr/local/bin/python", + "python.formatting.provider": "black", + "python.linting.enabled": true, + "python.linting.flake8Enabled": true, + "files.associations": { + "*.yaml": "yaml", + "*.yml": "yaml" + }, + "terminal.integrated.defaultProfile.linux": "bash", + "editor.formatOnSave": true, + "editor.tabSize": 2, + "[yaml]": { + "editor.tabSize": 2 + }, + "[python]": { + "editor.tabSize": 4 + }, + "[cpp]": { + "editor.tabSize": 2 + } + } + } + }, + "forwardPorts": [ + 6052, + 6123, + 80, + 443, + 8080, + 3232 + ], + "containerEnv": { + "ESPHOME_DASHBOARD_USE_PING": "true", + "PLATFORMIO_CORE_DIR": "/workspace/.platformio" + }, + "init": true, + "remoteUser": "root", + "capAdd": [ + "SYS_RAWIO", + "SYS_ADMIN" + ] +} \ No newline at end of file diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh new file mode 100755 index 0000000..af1f345 --- /dev/null +++ b/.devcontainer/setup.sh @@ -0,0 +1,57 @@ +#!/bin/bash +set -e + +echo "🚀 Setting up ESPHome NUT UPS Development Environment..." + +# Update and install packages +apt-get update +apt-get install -y \ + usbutils libusb-1.0-0-dev libudev-dev build-essential cmake ninja-build \ + git wget curl tree vim nano htop tmux screen jq socat minicom picocom udev + +# Install Python tools +pip install --upgrade pip black flake8 pylint mypy pytest jupyter ipython platformio + +# Update ESPHome +pip install --upgrade esphome + +# Set up USB permissions +cat > /etc/udev/rules.d/99-esphome-usb.rules << 'UDEV_EOF' +SUBSYSTEM=="usb", ATTR{idVendor}=="303a", MODE="0666" +SUBSYSTEM=="usb", ATTR{idVendor}=="10c4", MODE="0666" +SUBSYSTEM=="usb", ATTR{idVendor}=="1a86", MODE="0666" +SUBSYSTEM=="usb", ATTR{idVendor}=="051d", MODE="0666" +SUBSYSTEM=="usb", ATTR{idVendor}=="0764", MODE="0666" +SUBSYSTEM=="usb", ATTR{idVendor}=="0403", MODE="0666" +UDEV_EOF + +# Create aliases +cat >> ~/.bashrc << 'BASH_EOF' +alias esphome-config='esphome config' +alias esphome-compile='esphome compile' +alias esphome-upload='esphome upload' +alias esphome-logs='esphome logs' +alias esphome-dashboard='esphome dashboard /workspace' +alias lsusb='lsusb -v' +alias serialports='ls -la /dev/tty{USB,ACM}* 2>/dev/null || echo "No serial ports found"' +alias build-component='cd /workspace && esphome compile configs/test-config.yaml' +alias flash-test='cd /workspace && esphome upload configs/test-config.yaml' +alias monitor='cd /workspace && esphome logs configs/test-config.yaml' +BASH_EOF + +# Welcome message +cat > /tmp/WELCOME.md << 'WELCOME_EOF' +# 🎉 ESPHome NUT UPS Development Environment Ready! + +## Quick Commands +- `esphome-dashboard` - Start web dashboard +- `./tools/scan-usb.sh` - Check USB devices +- `build-component` - Build test config +- `flash-test` - Flash to device +- `monitor` - View logs + +Happy coding! 🚀 +WELCOME_EOF + +echo "✅ Development environment setup complete!" +cat /tmp/WELCOME.md diff --git a/tools/scan-usb.sh b/tools/scan-usb.sh new file mode 100755 index 0000000..6a2f4d0 --- /dev/null +++ b/tools/scan-usb.sh @@ -0,0 +1,14 @@ +#!/bin/bash +echo "🔍 Scanning USB devices..." +echo "=========================" +echo "All USB devices:" +lsusb +echo "" +echo "ESP32 boards:" +lsusb | grep -E "(303a|10c4|1a86)" || echo "No ESP32 boards found" +echo "" +echo "UPS devices:" +lsusb | grep -E "(051d|0764)" || echo "No UPS devices found" +echo "" +echo "Serial ports:" +ls -la /dev/tty{USB,ACM}* 2>/dev/null || echo "No serial ports found"