1
0
Fork 0
mirror of https://github.com/maziggy/bambuddy.git synced 2026-05-09 08:25:54 +02:00

[PR #476] [CLOSED] feat(smart-plug): Add REST API plug type (Option 2 from #472) #1056

Closed
opened 2026-05-07 00:15:45 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/maziggy/bambuddy/pull/476
Author: @Percy2Live
Created: 2/20/2026
Status: Closed

Base: 0.2.1Head: patch-1


📝 Commits (10+)

  • 1d0875e build(deps): bump aquasecurity/trivy-action
  • 5bcfadb Merge pull request #437 from maziggy/dependabot/github_actions/dot-github/workflows/github_actions-9bddd90c58
  • 10cae70 Updated CI
  • 971aa96 build(deps): bump aquasecurity/trivy-action
  • 0a725c0 Merge pull request #440 from maziggy/dependabot/github_actions/dot-github/workflows/github_actions-9bddd90c58
  • a361671 Updated CI
  • 036ae16 Updated CI
  • 2c0d1c2 Updated CI
  • 5d48ab8 Updated CI
  • 802bfe3 Updated CI

📊 Changes

10 files changed (+494 additions, -1985 deletions)

View changed files

📝 .github/workflows/ci.yml (+13 -6)
📝 .github/workflows/security.yml (+150 -33)
📝 backend/app/api/routes/smart_plugs.py (+30 -0)
📝 backend/app/core/database.py (+26 -0)
📝 backend/app/models/smart_plug.py (+11 -2)
📝 backend/app/schemas/smart_plug.py (+22 -2)
backend/app/services/rest_plug.py (+203 -0)
📝 backend/app/services/smart_plug_manager.py (+39 -0)
📝 frontend/package-lock.json (+0 -1940)
📝 frontend/package.json (+0 -2)

📄 Description

Description

Implements Option 2 from issue #472: a new plug_type = "rest" that allows users to connect any smart plug via custom REST API URLs.

How it works

The user configures up to four URLs for their smart plug:

  • On URL – called to turn the plug on
    • Off URL – called to turn the plug off
    • Toggle URL – called to toggle the state (optional; falls back to on/off based on current state)
    • Status URL – called to query the current state (optional)
      The HTTP method (GET or POST) is configurable per plug. For state detection, users can optionally specify a substring (rest_state_on_value) that, when present in the status response body, indicates the plug is ON.

Example use cases

  • Shelly plug Gen1 (HTTP API): http://192.168.1.50/relay/0?turn=on
    • TP-Link Tapo (via local API bridge): http://192.168.1.51/api/on
    • Any home automation webhook

Changed files

File Change
backend/app/services/rest_plug.py NewRestPlugService with turn_on, turn_off, toggle, get_status, get_energy, test_connection
backend/app/models/smart_plug.py Added rest_on_url, rest_off_url, rest_toggle_url, rest_status_url, rest_method, rest_state_on_value columns
backend/app/schemas/smart_plug.py Added REST fields + validation to SmartPlugBase and SmartPlugUpdate; updated plug_type Literal
backend/app/services/smart_plug_manager.py Routes plug_type == "rest" to rest_plug_service
backend/app/api/routes/smart_plugs.py Imports rest_plug_service; routes REST in _get_service_for_plug; adds POST /smart-plugs/rest/test-connection endpoint

Fixes #472

Type of Change

  • New feature (non-breaking change that adds functionality)

Checklist

  • Code follows existing patterns (mirrors TasmotaService / HomeAssistantService)
  • - [x] URL validation blocks dangerous destinations (169.254.x.x, link-local)
  • - [x] Backward compatible – existing plug types are unaffected
  • - [x] Database migration needed: new nullable columns with defaults added to smart_plugs table

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/maziggy/bambuddy/pull/476 **Author:** [@Percy2Live](https://github.com/Percy2Live) **Created:** 2/20/2026 **Status:** ❌ Closed **Base:** `0.2.1` ← **Head:** `patch-1` --- ### 📝 Commits (10+) - [`1d0875e`](https://github.com/maziggy/bambuddy/commit/1d0875ee83992e2b1e22afac06639717e384211d) build(deps): bump aquasecurity/trivy-action - [`5bcfadb`](https://github.com/maziggy/bambuddy/commit/5bcfadbd8d6457d9b12bceb0ec1c127aae8286eb) Merge pull request #437 from maziggy/dependabot/github_actions/dot-github/workflows/github_actions-9bddd90c58 - [`10cae70`](https://github.com/maziggy/bambuddy/commit/10cae700f4702a6660baf66bdf8f673dc06f766d) Updated CI - [`971aa96`](https://github.com/maziggy/bambuddy/commit/971aa960a8280b414aac2077e91881f19fde40b0) build(deps): bump aquasecurity/trivy-action - [`0a725c0`](https://github.com/maziggy/bambuddy/commit/0a725c0ccc5744e1c1bd6fb14ea8a1dc2fcdace6) Merge pull request #440 from maziggy/dependabot/github_actions/dot-github/workflows/github_actions-9bddd90c58 - [`a361671`](https://github.com/maziggy/bambuddy/commit/a3616719526e6f9455742dcd59b6c1898ef50233) Updated CI - [`036ae16`](https://github.com/maziggy/bambuddy/commit/036ae16ad5511369bac94ab2a4f85169c817ec8f) Updated CI - [`2c0d1c2`](https://github.com/maziggy/bambuddy/commit/2c0d1c2fe6c77b13ee53d116831623f425257dac) Updated CI - [`5d48ab8`](https://github.com/maziggy/bambuddy/commit/5d48ab88f00f58cc472a72003a8cd246fa4b04e7) Updated CI - [`802bfe3`](https://github.com/maziggy/bambuddy/commit/802bfe330a568b1c434c527b29bc1a40612adb93) Updated CI ### 📊 Changes **10 files changed** (+494 additions, -1985 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/ci.yml` (+13 -6) 📝 `.github/workflows/security.yml` (+150 -33) 📝 `backend/app/api/routes/smart_plugs.py` (+30 -0) 📝 `backend/app/core/database.py` (+26 -0) 📝 `backend/app/models/smart_plug.py` (+11 -2) 📝 `backend/app/schemas/smart_plug.py` (+22 -2) ➕ `backend/app/services/rest_plug.py` (+203 -0) 📝 `backend/app/services/smart_plug_manager.py` (+39 -0) 📝 `frontend/package-lock.json` (+0 -1940) 📝 `frontend/package.json` (+0 -2) </details> ### 📄 Description ## Description Implements **Option 2** from issue #472: a new `plug_type = "rest"` that allows users to connect any smart plug via custom REST API URLs. ### How it works The user configures up to four URLs for their smart plug: - **On URL** – called to turn the plug on - - **Off URL** – called to turn the plug off - - **Toggle URL** – called to toggle the state (optional; falls back to on/off based on current state) - - **Status URL** – called to query the current state (optional) The HTTP method (GET or POST) is configurable per plug. For state detection, users can optionally specify a substring (`rest_state_on_value`) that, when present in the status response body, indicates the plug is ON. ### Example use cases - Shelly plug Gen1 (HTTP API): `http://192.168.1.50/relay/0?turn=on` - - TP-Link Tapo (via local API bridge): `http://192.168.1.51/api/on` - - Any home automation webhook ### Changed files | File | Change | |------|--------| | `backend/app/services/rest_plug.py` | **New** – `RestPlugService` with `turn_on`, `turn_off`, `toggle`, `get_status`, `get_energy`, `test_connection` | | `backend/app/models/smart_plug.py` | Added `rest_on_url`, `rest_off_url`, `rest_toggle_url`, `rest_status_url`, `rest_method`, `rest_state_on_value` columns | | `backend/app/schemas/smart_plug.py` | Added REST fields + validation to `SmartPlugBase` and `SmartPlugUpdate`; updated `plug_type` Literal | | `backend/app/services/smart_plug_manager.py` | Routes `plug_type == "rest"` to `rest_plug_service` | | `backend/app/api/routes/smart_plugs.py` | Imports `rest_plug_service`; routes REST in `_get_service_for_plug`; adds `POST /smart-plugs/rest/test-connection` endpoint | ### Related Issue Fixes #472 ## Type of Change - [x] New feature (non-breaking change that adds functionality) ## Checklist - [x] Code follows existing patterns (mirrors `TasmotaService` / `HomeAssistantService`) - [ ] - [x] URL validation blocks dangerous destinations (169.254.x.x, link-local) - [ ] - [x] Backward compatible – existing plug types are unaffected - [ ] - [x] Database migration needed: new nullable columns with defaults added to `smart_plugs` table --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-07 00:15:45 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/bambuddy-maziggy-1#1056
No description provided.