chore: organize protocol bug development process

Signed-off-by: bullshit <coding@ow-software.pl>
This commit is contained in:
bullshit committed 2025-09-02 23:12:50 +02:00
1 parent 1b585ff746
commit 61c70d6489
4 files changed
+522 -1

No files matched your search

@@ -0,0 +1,205 @@
name: Protocol Implementation Bug Report
description: Report incorrect behavior or issues with existing UPS protocol support
title: "[Bug] <Protocol/Model>: <Brief description>"
labels: ["bug", "protocol"]
body:
- type: markdown
attributes:
value: |
## Thank you for reporting this issue!
Please provide detailed information to help us diagnose and fix the problem.
- type: dropdown
id: protocol
attributes:
label: Affected Protocol
description: Which UPS protocol has the issue?
options:
- APC HID Protocol
- CyberPower Protocol
- Generic HID Protocol
- Unknown/Not Sure
validations:
required: true
- type: input
id: device_info
attributes:
label: Device Information
description: "Format: Manufacturer Model (VID:PID)"
placeholder: "e.g., APC Back-UPS ES 700 (0x051d:0x0002)"
validations:
required: true
- type: input
id: esphome_version
attributes:
label: ESPHome Version
placeholder: "e.g., 2024.12.0"
validations:
required: true
- type: textarea
id: description
attributes:
label: Bug Description
description: Clear and concise description of what's wrong
placeholder: |
What happens: Battery level shows 255% instead of actual percentage
Expected: Battery level between 0-100%
When: Always after switching from battery to AC power
validations:
required: true
- type: checkboxes
id: occurrence
attributes:
label: When does the issue occur?
description: Check all situations where you've observed the issue
options:
- label: During normal operation (on AC power)
- label: When switching to battery power
- label: When returning to AC power (charging)
- label: During low battery condition
- label: After USB disconnect/reconnect
- label: After ESP32 restart
- label: At random times
- label: Immediately on startup
- type: textarea
id: esphome_config
attributes:
label: ESPHome Configuration
description: Your ups_hid component configuration
render: yaml
placeholder: |
ups_hid:
- id: my_ups
auto_restart: true
sensor:
- platform: ups_hid
ups_id: my_ups
battery_level:
name: "UPS Battery"
validations:
required: true
- type: textarea
id: debug_logs
attributes:
label: Debug Logs
description: |
ESPHome logs when the issue occurs.
Enable debug logging by adding to your config:
```yaml
logger:
level: DEBUG
logs:
ups_hid: DEBUG
```
render: text
placeholder: |
[D][ups_hid:123]: Reading report 0x0C
[W][ups_hid:456]: Unexpected value in battery report: 0xFF
[E][ups_hid:789]: Failed to parse status report
validations:
required: true
- type: textarea
id: sensor_values
attributes:
label: Sensor Values During Issue
description: What do the sensors show when the problem occurs?
placeholder: |
Battery Level: 255%
Runtime: -1 seconds
Load: 0%
Input Voltage: 0V
Online: true
Status: "Unknown"
- type: dropdown
id: frequency
attributes:
label: How often does this occur?
options:
- Always (100% reproducible)
- Frequently (>50% of the time)
- Sometimes (10-50% of the time)
- Rarely (<10% of the time)
- Only happened once
validations:
required: true
- type: textarea
id: reproduce_steps
attributes:
label: Steps to Reproduce
description: How can we reproduce this issue?
placeholder: |
1. Start with UPS on AC power
2. Unplug UPS from wall outlet
3. Wait 30 seconds
4. Plug UPS back in
5. Observe battery sensor showing 255%
- type: textarea
id: nut_comparison
attributes:
label: Comparison with NUT (optional)
description: If you have NUT working with this UPS, how do the values compare?
placeholder: |
NUT battery.charge: 100
ESPHome battery_level: 255
NUT ups.status: OL
ESPHome status: "Unknown"
- type: checkboxes
id: workarounds
attributes:
label: Workarounds Attempted
description: What have you tried to fix or work around the issue?
options:
- label: Restarted ESP32
- label: Unplugged/replugged USB cable
- label: Used different USB cable
- label: Power cycled the UPS
- label: Changed ESPHome configuration
- label: Downgraded ESPHome version
- label: Added delays/timeouts in config
- type: textarea
id: workaround_results
attributes:
label: Workaround Results
description: Did any workarounds help? What was the effect?
placeholder: "Restarting ESP32 temporarily fixes it for about 10 minutes"
- type: textarea
id: additional_info
attributes:
label: Additional Information
description: |
Any other relevant details:
- Previous working version (if this is a regression)
- USB cable length or type
- Power setup (UPS load, battery age, etc.)
- Related issues or discussions
placeholder: "This started after updating from ESPHome 2024.11.0 to 2024.12.0"
- type: checkboxes
id: checklist
attributes:
label: Confirmation
description: Please confirm you've provided the necessary information
options:
- label: I've included debug-level logs showing the issue
required: true
- label: I've included my ESPHome configuration
required: true
- label: I've described when and how often the issue occurs
required: true
- label: I've checked for similar existing issues
required: true
+17 -1
View File
@@ -8,7 +8,23 @@ Thank you for your interest in contributing to this project! This guide will hel
If you have a UPS device that isn't currently supported, please use our **New UPS Protocol Request** issue template. This template guides you through collecting all necessary debug information. If you have a UPS device that isn't currently supported, please use our **New UPS Protocol Request** issue template. This template guides you through collecting all necessary debug information.
#### Quick Start: Automated Debug Collection ### Protocol Implementation Bugs
For issues with existing protocol support, use the **Protocol Implementation Bug Report** template. This helps us quickly identify and fix problems with supported devices.
#### Quick Start: Bug Debug Collection
For existing protocol issues, use our debug tool:
```bash
# Collect debug data from running ESP32
./tools/debug-protocol-issue.sh 192.168.1.100 my_ups
# Follow interactive prompts to test different states
# Tool will create a complete bug report
```
#### Quick Start: New Protocol Debug Collection
We provide a tool to automatically collect all required debug information: We provide a tool to automatically collect all required debug information:
+30
View File
@@ -33,6 +33,36 @@ Creates a timestamped directory containing:
- Complete UPS variable listings - Complete UPS variable listings
- Summary report for issue creation - Summary report for issue creation
### debug-protocol-issue.sh
Automated debug collection for existing protocol implementation issues. Captures real-time data from running ESP32 devices.
**Usage:**
```bash
./tools/debug-protocol-issue.sh <esp32_ip> [ups_name]
```
**Features:**
- Tests ESP32 connectivity and ESPHome API
- Captures real-time sensor values via web API
- Interactive state testing (normal, battery, charging)
- Collects logs during issue reproduction
- Analyzes logs for common problems (USB errors, HID issues, memory)
- Creates structured bug report with all debug data
**Requirements:**
- ESP32 running ESPHome with UPS HID component
- Network access to ESP32 device
- ESPHome CLI tool (optional, for log capture)
- Web API enabled in ESPHome config (recommended)
**Output:**
Creates timestamped directory with:
- JSON sensor states for each test condition
- ESPHome logs (if available)
- Structured bug report ready for GitHub
- Analysis summary with quick diagnostics
## USB Device Management ## USB Device Management
### scan-usb.sh ### scan-usb.sh
+270
View File
@@ -0,0 +1,270 @@
#!/bin/bash
# Script to collect debug information for protocol implementation bug reports
# Usage: ./debug-protocol-issue.sh <esp32_ip> [ups_name]
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Check arguments
if [ $# -eq 0 ]; then
echo -e "${RED}Error: ESP32 IP address required${NC}"
echo "Usage: $0 <esp32_ip> [ups_name]"
echo "Example: $0 192.168.1.100"
echo " $0 192.168.1.100 my_ups"
exit 1
fi
ESP32_IP=$1
UPS_NAME=${2:-"ups"} # Default to "ups" if not provided
OUTPUT_DIR="protocol-bug-$(date +%Y%m%d-%H%M%S)"
OUTPUT_FILE="$OUTPUT_DIR/bug-report.md"
# Create output directory
mkdir -p "$OUTPUT_DIR"
echo -e "${GREEN}=== UPS Protocol Bug Debug Collection ===${NC}"
echo -e "ESP32 IP: ${YELLOW}$ESP32_IP${NC}"
echo -e "UPS Name: ${YELLOW}$UPS_NAME${NC}"
echo "Output directory: $OUTPUT_DIR"
echo ""
# Function to capture with timeout and error handling
capture_with_retry() {
local description=$1
local command=$2
local output_file=$3
local retry_count=3
echo -e "${YELLOW}Capturing: $description${NC}"
for i in $(seq 1 $retry_count); do
if timeout 10 bash -c "$command" > "$output_file" 2>&1; then
echo -e "${GREEN}✓ Success${NC}"
return 0
else
if [ $i -lt $retry_count ]; then
echo -e "${YELLOW} Retry $i/$retry_count...${NC}"
sleep 2
else
echo -e "${RED}✗ Failed after $retry_count attempts${NC}"
echo "Failed to capture" > "$output_file"
return 1
fi
fi
done
}
# Start report
echo "# UPS Protocol Bug Report" > "$OUTPUT_FILE"
echo "Date: $(date)" >> "$OUTPUT_FILE"
echo "ESP32 IP: $ESP32_IP" >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
# 1. Test ESP32 connectivity
echo -e "\n${GREEN}Step 1: Testing ESP32 Connectivity${NC}"
if ping -c 1 -W 2 $ESP32_IP > /dev/null 2>&1; then
echo -e "${GREEN}✓ ESP32 is reachable${NC}"
echo "## ESP32 Status" >> "$OUTPUT_FILE"
echo "ESP32 is reachable at $ESP32_IP" >> "$OUTPUT_FILE"
else
echo -e "${RED}✗ Cannot reach ESP32 at $ESP32_IP${NC}"
echo "Cannot reach ESP32 - check IP address and network connection" >> "$OUTPUT_FILE"
exit 1
fi
# 2. Capture ESPHome Web API Status
echo -e "\n${GREEN}Step 2: Fetching Device Information${NC}"
echo "## Device Information" >> "$OUTPUT_FILE"
echo '```json' >> "$OUTPUT_FILE"
# Try to get device info via curl (ESPHome native API is on port 6053)
if curl -s "http://$ESP32_IP" | grep -q "ESPHome"; then
echo -e "${GREEN}✓ ESPHome Web Server detected${NC}"
# Get basic device info from web interface
curl -s "http://$ESP32_IP/json/state" > "$OUTPUT_DIR/device_state.json" 2>/dev/null || true
if [ -f "$OUTPUT_DIR/device_state.json" ] && [ -s "$OUTPUT_DIR/device_state.json" ]; then
cat "$OUTPUT_DIR/device_state.json" >> "$OUTPUT_FILE"
fi
else
echo "ESPHome web server not detected or not enabled" >> "$OUTPUT_FILE"
fi
echo '```' >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
# 3. Monitor real-time logs
echo -e "\n${GREEN}Step 3: Capturing Real-time Logs${NC}"
echo -e "${YELLOW}Attempting to capture ESPHome logs...${NC}"
echo -e "${BLUE}Note: This requires 'esphome' CLI tool and API enabled in your config${NC}"
echo ""
echo "## ESPHome Logs" >> "$OUTPUT_FILE"
echo '```' >> "$OUTPUT_FILE"
# Try to capture logs using esphome CLI if available
if command -v esphome &> /dev/null; then
echo "Attempting to connect to ESPHome logs..." >> "$OUTPUT_FILE"
timeout 30 esphome logs --device $ESP32_IP 2>&1 | tee "$OUTPUT_DIR/esphome_logs.txt" | tail -100 >> "$OUTPUT_FILE" || true
else
echo "ESPHome CLI not installed - cannot capture logs automatically" >> "$OUTPUT_FILE"
echo -e "${YELLOW}Install with: pip install esphome${NC}"
fi
echo '```' >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
# 4. Interactive state testing
echo -e "\n${GREEN}Step 4: Interactive State Testing${NC}"
echo -e "${YELLOW}We'll now test different UPS states interactively${NC}"
echo ""
test_state() {
local state_name=$1
local instruction=$2
echo -e "${YELLOW}$instruction${NC}"
echo -n "Press ENTER when ready to capture $state_name state: "
read
echo "## State: $state_name" >> "$OUTPUT_FILE"
echo "Timestamp: $(date)" >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
# Capture current sensor values if web API is available
if curl -s "http://$ESP32_IP/json/state" > "$OUTPUT_DIR/${state_name}_state.json" 2>/dev/null; then
echo "### Sensor Values" >> "$OUTPUT_FILE"
echo '```json' >> "$OUTPUT_FILE"
# Extract UPS-related sensors
cat "$OUTPUT_DIR/${state_name}_state.json" | python3 -m json.tool 2>/dev/null | grep -A2 -B2 -i "ups\|battery\|power\|voltage\|runtime\|load" >> "$OUTPUT_FILE" 2>/dev/null || echo "Could not parse sensor data" >> "$OUTPUT_FILE"
echo '```' >> "$OUTPUT_FILE"
fi
echo "" >> "$OUTPUT_FILE"
echo -e "${GREEN}✓ $state_name state captured${NC}"
}
# Test different states
echo -e "${GREEN}Testing UPS states...${NC}"
test_state "normal" "Ensure UPS is in NORMAL state (plugged in, battery charged)"
test_state "battery" "Now UNPLUG the UPS from AC power (running on battery)"
test_state "charging" "Now PLUG the UPS back into AC power (charging)"
# 5. Problem reproduction
echo -e "\n${GREEN}Step 5: Problem Reproduction${NC}"
echo -e "${YELLOW}Now reproduce the specific issue you're experiencing${NC}"
echo -n "Press ENTER when you're ready to start reproducing the issue: "
read
echo "## Problem Reproduction" >> "$OUTPUT_FILE"
echo "Timestamp: $(date)" >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
echo -e "${YELLOW}Reproduce the issue now. Press ENTER when the issue has occurred: ${NC}"
read
# Capture state during issue
if curl -s "http://$ESP32_IP/json/state" > "$OUTPUT_DIR/issue_state.json" 2>/dev/null; then
echo "### Sensor Values During Issue" >> "$OUTPUT_FILE"
echo '```json' >> "$OUTPUT_FILE"
cat "$OUTPUT_DIR/issue_state.json" | python3 -m json.tool 2>/dev/null >> "$OUTPUT_FILE" || cat "$OUTPUT_DIR/issue_state.json" >> "$OUTPUT_FILE"
echo '```' >> "$OUTPUT_FILE"
fi
# 6. Ask for issue description
echo -e "\n${GREEN}Step 6: Issue Description${NC}"
echo "Please describe what went wrong (press Ctrl+D when done):"
echo "### Issue Description" >> "$OUTPUT_FILE"
echo '```' >> "$OUTPUT_FILE"
cat >> "$OUTPUT_FILE"
echo '```' >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
# 7. Generate analysis
echo -e "\n${GREEN}Step 7: Analyzing Collected Data${NC}"
echo "## Analysis Summary" >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
# Check for common issues in logs
if [ -f "$OUTPUT_DIR/esphome_logs.txt" ]; then
echo "### Log Analysis" >> "$OUTPUT_FILE"
# Check for USB errors
if grep -q "USB.*error\|timeout\|disconnect" "$OUTPUT_DIR/esphome_logs.txt"; then
echo "- ⚠️ USB communication errors detected" >> "$OUTPUT_FILE"
fi
# Check for HID errors
if grep -q "HID.*error\|Report.*fail\|parse.*error" "$OUTPUT_DIR/esphome_logs.txt"; then
echo "- ⚠️ HID protocol errors detected" >> "$OUTPUT_FILE"
fi
# Check for memory issues
if grep -q "heap\|stack\|memory\|allocation" "$OUTPUT_DIR/esphome_logs.txt"; then
echo "- ⚠️ Potential memory issues detected" >> "$OUTPUT_FILE"
fi
echo "" >> "$OUTPUT_FILE"
fi
# Compare states if JSON files exist
if [ -f "$OUTPUT_DIR/normal_state.json" ] && [ -f "$OUTPUT_DIR/battery_state.json" ]; then
echo "### State Comparison" >> "$OUTPUT_FILE"
echo "Differences between normal and battery states detected" >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
fi
# 8. Create summary
echo -e "\n${GREEN}Creating Summary Report${NC}"
cat > "$OUTPUT_DIR/SUMMARY.md" << EOF
# Protocol Bug Report Summary
## Device Information
- ESP32 IP: $ESP32_IP
- Date: $(date)
- UPS Component: $UPS_NAME
## Files Collected
$(ls -1 $OUTPUT_DIR/*.json $OUTPUT_DIR/*.txt 2>/dev/null | xargs -I {} basename {} | sed 's/^/- /')
## States Tested
- Normal operation (AC power)
- Battery operation
- Charging state
- Issue reproduction state
## Next Steps
1. Review the bug report at: $OUTPUT_FILE
2. Check collected JSON states for anomalies
3. Create an issue at: https://github.com/oleander/esphome-components/issues
4. Use the "Protocol Implementation Bug Report" template
5. Attach relevant files from $OUTPUT_DIR/
## Quick Diagnostics
- ESP32 Reachable: $(ping -c 1 -W 2 $ESP32_IP > /dev/null 2>&1 && echo "✓ Yes" || echo "✗ No")
- Web API Available: $(curl -s "http://$ESP32_IP" | grep -q "ESPHome" && echo "✓ Yes" || echo "✗ No")
- Logs Captured: $([ -f "$OUTPUT_DIR/esphome_logs.txt" ] && echo "✓ Yes" || echo "✗ No")
EOF
echo -e "\n${GREEN}=== Debug Collection Complete ===${NC}"
echo ""
echo "Output directory: $OUTPUT_DIR/"
echo "Main report: $OUTPUT_FILE"
echo "Summary: $OUTPUT_DIR/SUMMARY.md"
echo ""
echo -e "${YELLOW}Next steps:${NC}"
echo "1. Review the collected data in $OUTPUT_DIR/"
echo "2. Create an issue at: https://github.com/oleander/esphome-components/issues"
echo "3. Use the 'Protocol Implementation Bug Report' template"
echo "4. Attach the bug report and relevant JSON files"
echo ""
echo -e "${GREEN}Thank you for helping improve the UPS HID component!${NC}"
exit 0