feat: initial commit
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
# Local Notes
|
||||||
|
|
||||||
|
- This project folder stores user-facing instructions for Home Assistant usage.
|
||||||
|
- Keep artifacts concise and share-ready (e.g. Viber-ready text).
|
||||||
|
- Do not store secrets in plain text unless explicitly requested by the user.
|
||||||
|
- Guest portal and helper API live here and are deployed to mini-PC under `/srv/site-controller/`.
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# Checkpoint (2026-04-08)
|
||||||
|
|
||||||
|
## Gde smo stali
|
||||||
|
- Home Assistant radi na mini PC-u.
|
||||||
|
- TV i svetla su dodati i rade.
|
||||||
|
- Cilj sledeće faze: glasovne komande na srpskom za TV/svetla/bojler.
|
||||||
|
- Usisivač još nije kupljen; plan je da ostavimo spreman "plug-in" put kad stigne.
|
||||||
|
|
||||||
|
## Sledeći konkretan korak kad se vratimo
|
||||||
|
- Definisati srpske intents/sinonime i mapiranje na postojeće entitete.
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
Zdravo Bojana, ja sam Codex.
|
||||||
|
Napravio sam ti kratko i jasno uputstvo da na telefonu dobiješ jedno dugme za veliko svetlo u dnevnoj sobi.
|
||||||
|
|
||||||
|
1. Otvori `Play Store`.
|
||||||
|
Ako zapne: proveri internet i da li radi Google nalog na telefonu.
|
||||||
|
|
||||||
|
2. U pretrazi upiši `Home Assistant`.
|
||||||
|
Ako zapne: traži pun naziv `Home Assistant Companion`.
|
||||||
|
|
||||||
|
3. Klikni `Install` i sačekaj da se instalacija završi.
|
||||||
|
Ako zapne: oslobodi malo memorije na telefonu i probaj ponovo.
|
||||||
|
|
||||||
|
4. Otvori aplikaciju `Home Assistant`.
|
||||||
|
Ako zapne: restartuj telefon pa ponovo otvori app.
|
||||||
|
|
||||||
|
5. Na pitanju za server unesi: `http://192.168.0.26:8123`
|
||||||
|
Ako zapne: proveri da li je telefon na kućnom Wi-Fi (ne mobilni internet).
|
||||||
|
|
||||||
|
6. Prijava:
|
||||||
|
- Username: `dzoni2`
|
||||||
|
- Password: `Dzoni2026`
|
||||||
|
Ako zapne: pažljivo unesi ručno, bez copy/paste, i proveri velika/mala slova.
|
||||||
|
|
||||||
|
7. Posle ulaska, daj dozvole koje app traži (notifikacije i rad u pozadini možeš da odobriš).
|
||||||
|
Ako zapne: uđi u `Settings > Apps > Home Assistant > Permissions` i dozvoli traženo.
|
||||||
|
|
||||||
|
8. Izađi na početni ekran telefona, drži prst na praznom delu ekrana i izaberi `Widgets`.
|
||||||
|
Ako zapne: na Samsungu je nekad putanja `Long press > Widgets`.
|
||||||
|
|
||||||
|
9. Nađi `Home Assistant` widget i izaberi widget za kontrolu entiteta (toggle/switch).
|
||||||
|
Ako zapne: dodaj bilo koji HA widget, pa u sledećem koraku promeni entitet na svetlo.
|
||||||
|
|
||||||
|
10. Kada traži koji entitet, izaberi veliko svetlo dnevne sobe (entity koji počinje sa `light.` i zove se za veliko svetlo).
|
||||||
|
Ako zapne: u HA app otvori uređaje i proveri tačan naziv svetla pa se vrati na widget.
|
||||||
|
|
||||||
|
11. Nazovi widget: `Dnevna veliko svetlo`.
|
||||||
|
Ako zapne: naziv nije obavezan, može i bez preimenovanja.
|
||||||
|
|
||||||
|
12. Test:
|
||||||
|
- tap 1: svetlo ON
|
||||||
|
- tap 2: svetlo OFF
|
||||||
|
Ako zapne: proveri da li je telefon i dalje na kućnom Wi-Fi i javi Nikoli tačan tekst greške.
|
||||||
|
|
||||||
|
13. (Preporučeno) Isključi štednju baterije za Home Assistant app:
|
||||||
|
`Settings > Apps > Home Assistant > Battery > Unrestricted` (ili dozvoli rad u pozadini).
|
||||||
|
Ako zapne: ostavi kako jeste, ali može nekad sporije reagovati.
|
||||||
|
|
||||||
|
To je sve. Posle ovoga koristiš samo jedno dugme na početnom ekranu, bez ulaska u aplikaciju.
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
(() => {
|
||||||
|
const status = document.getElementById("copy-status");
|
||||||
|
const buttons = document.querySelectorAll("[data-copy]");
|
||||||
|
|
||||||
|
buttons.forEach((btn) => {
|
||||||
|
btn.addEventListener("click", async () => {
|
||||||
|
const selector = btn.getAttribute("data-copy");
|
||||||
|
const el = document.querySelector(selector);
|
||||||
|
if (!el) return;
|
||||||
|
|
||||||
|
const value = (el.textContent || "").trim();
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(value);
|
||||||
|
if (status) status.textContent = "Kopirano.";
|
||||||
|
} catch (_) {
|
||||||
|
if (status) status.textContent = "Ne mogu da kopiram automatski. Oznaci i copy rucno.";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const wifiQrIds = ["wifi-qr-sr", "wifi-qr-en"];
|
||||||
|
const portalQrIds = ["portal-qr-sr", "portal-qr-en"];
|
||||||
|
wifiQrIds.forEach((id) => {
|
||||||
|
const img = document.getElementById(id);
|
||||||
|
if (img) img.src = "/qr/wifi.svg";
|
||||||
|
});
|
||||||
|
portalQrIds.forEach((id) => {
|
||||||
|
const img = document.getElementById(id);
|
||||||
|
if (img) img.src = "/qr/portal.svg";
|
||||||
|
});
|
||||||
|
const bojanaQr = document.getElementById("bojana-qr");
|
||||||
|
if (bojanaQr) bojanaQr.src = "/qr/bojana.svg";
|
||||||
|
})();
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="sr">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Bojana | Home Core</title>
|
||||||
|
<link rel="stylesheet" href="./style.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main class="container">
|
||||||
|
<header class="hero">
|
||||||
|
<p class="eyebrow">Samo za tebe</p>
|
||||||
|
<h1>Bojana, dobrodosla kuci</h1>
|
||||||
|
<p class="lead">
|
||||||
|
Ako ovo citas, znaci da je Nikola uspeo da automatizuje makar nesto.
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<section class="card">
|
||||||
|
<h2>Brzo uputstvo</h2>
|
||||||
|
<ol class="list ordered">
|
||||||
|
<li>Na telefonu drzi prst na praznom delu Home ekrana.</li>
|
||||||
|
<li>Izaberi <code>Widgets</code>.</li>
|
||||||
|
<li>Nadji <code>Home Assistant</code> widget.</li>
|
||||||
|
<li>Izaberi veliko svetlo iz dnevne sobe.</li>
|
||||||
|
<li>Gotovo: jedan tap = ON/OFF.</li>
|
||||||
|
</ol>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="card love-note">
|
||||||
|
<h2>Poruka</h2>
|
||||||
|
<p>
|
||||||
|
Volim te. Hvala ti sto imas strpljenja za sve moje servere, kablove i
|
||||||
|
ideje. Ovaj klik je mali podsetnik da mi je dom najleps i kada je
|
||||||
|
haotican, jer smo zajedno.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<a class="btn secondary" href="./index.html">Nazad na Guest Portal</a>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Welcome | Home Core</title>
|
||||||
|
<link rel="stylesheet" href="./style.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main class="container">
|
||||||
|
<header class="hero">
|
||||||
|
<p class="eyebrow">Home Core Guest Portal</p>
|
||||||
|
<h1>Welcome to our apartment</h1>
|
||||||
|
<p class="lead">
|
||||||
|
Everything in one place: Wi-Fi, stay notes, and one-tap control for
|
||||||
|
the main living-room light.
|
||||||
|
</p>
|
||||||
|
<p class="lead">
|
||||||
|
Serbian version:
|
||||||
|
<a href="./index.html">Open SR page</a>
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<section class="card">
|
||||||
|
<h2>1) Wi-Fi connection</h2>
|
||||||
|
<p class="muted">Use this network:</p>
|
||||||
|
<div class="row">
|
||||||
|
<div>
|
||||||
|
<label>SSID</label>
|
||||||
|
<code id="wifi-ssid-en">Zapadna</code>
|
||||||
|
</div>
|
||||||
|
<button data-copy="#wifi-ssid-en" class="btn secondary">Copy SSID</button>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div>
|
||||||
|
<label>Password</label>
|
||||||
|
<code id="wifi-pass-en">Ask host</code>
|
||||||
|
</div>
|
||||||
|
<button data-copy="#wifi-pass-en" class="btn secondary">
|
||||||
|
Copy Password
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p class="hint" id="copy-status">Tap Copy to copy text.</p>
|
||||||
|
<div class="qr-grid">
|
||||||
|
<div class="qr-card">
|
||||||
|
<h3>Wi-Fi QR (Android)</h3>
|
||||||
|
<img id="wifi-qr-en" alt="Wi-Fi QR" />
|
||||||
|
<p class="hint">Use camera scanner or Samsung QR scanner.</p>
|
||||||
|
</div>
|
||||||
|
<div class="qr-card">
|
||||||
|
<h3>Portal QR</h3>
|
||||||
|
<img id="portal-qr-en" alt="Portal QR" />
|
||||||
|
<p class="hint">Open this page quickly.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="card">
|
||||||
|
<h2>2) Main light (guest control)</h2>
|
||||||
|
<p class="muted">Buttons below call local Home Assistant webhooks.</p>
|
||||||
|
<div class="controls">
|
||||||
|
<form
|
||||||
|
action="/api/light/on"
|
||||||
|
method="post"
|
||||||
|
target="silent-submit"
|
||||||
|
>
|
||||||
|
<button type="submit" class="btn on">Turn ON</button>
|
||||||
|
</form>
|
||||||
|
<form
|
||||||
|
action="/api/light/off"
|
||||||
|
method="post"
|
||||||
|
target="silent-submit"
|
||||||
|
>
|
||||||
|
<button type="submit" class="btn off">Turn OFF</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<p class="hint">If needed, wait 1-2 seconds and tap again.</p>
|
||||||
|
<iframe name="silent-submit" title="silent-submit" hidden></iframe>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<script src="./app.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="sr">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Dobrodosli | Home Core</title>
|
||||||
|
<link rel="stylesheet" href="./style.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main class="container">
|
||||||
|
<header class="hero">
|
||||||
|
<p class="eyebrow">Home Core Guest Portal</p>
|
||||||
|
<h1>Dobrodosli u nas stan</h1>
|
||||||
|
<p class="lead">
|
||||||
|
Sve bitno na jednom mestu: Wi-Fi, pravila boravka i brzo dugme za
|
||||||
|
veliko svetlo u dnevnoj sobi.
|
||||||
|
</p>
|
||||||
|
<p class="lead">
|
||||||
|
English version:
|
||||||
|
<a href="./en.html">Open EN page</a>
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<section class="card">
|
||||||
|
<h2>1) Wi-Fi povezivanje</h2>
|
||||||
|
<p class="muted">Ako ste gost, koristite ovu mrezu:</p>
|
||||||
|
<div class="row">
|
||||||
|
<div>
|
||||||
|
<label>SSID</label>
|
||||||
|
<code id="wifi-ssid">Zapadna</code>
|
||||||
|
</div>
|
||||||
|
<button data-copy="#wifi-ssid" class="btn secondary">Copy SSID</button>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div>
|
||||||
|
<label>Password</label>
|
||||||
|
<code id="wifi-pass">Pitaj domacina</code>
|
||||||
|
</div>
|
||||||
|
<button data-copy="#wifi-pass" class="btn secondary">
|
||||||
|
Copy Password
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p class="hint" id="copy-status">Klik na Copy da prekopiras.</p>
|
||||||
|
<div class="qr-grid">
|
||||||
|
<div class="qr-card">
|
||||||
|
<h3>QR za Wi-Fi (Android)</h3>
|
||||||
|
<img id="wifi-qr-sr" alt="Wi-Fi QR" />
|
||||||
|
<p class="hint">Skener kamere ili Samsung QR scanner.</p>
|
||||||
|
</div>
|
||||||
|
<div class="qr-card">
|
||||||
|
<h3>QR za Guest Portal</h3>
|
||||||
|
<img id="portal-qr-sr" alt="Portal QR" />
|
||||||
|
<p class="hint">Brz ulaz na ovu stranu.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="card">
|
||||||
|
<h2>2) Korisne informacije</h2>
|
||||||
|
<ul class="list">
|
||||||
|
<li>Molimo bez buke posle 23:00.</li>
|
||||||
|
<li>Pusenje je dozvoljeno samo na terasi.</li>
|
||||||
|
<li>Ako nesto nije jasno, pitajte domacina.</li>
|
||||||
|
<li>Izlazak iz stana: proverite vrata i svetla.</li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="card">
|
||||||
|
<h2>3) Veliko svetlo (gosti)</h2>
|
||||||
|
<p class="muted">
|
||||||
|
Dugmad ispod rade lokalno kroz Home Assistant webhook.
|
||||||
|
</p>
|
||||||
|
<div class="controls">
|
||||||
|
<form
|
||||||
|
action="/api/light/on"
|
||||||
|
method="post"
|
||||||
|
target="silent-submit"
|
||||||
|
>
|
||||||
|
<button type="submit" class="btn on">Ukljuci svetlo</button>
|
||||||
|
</form>
|
||||||
|
<form
|
||||||
|
action="/api/light/off"
|
||||||
|
method="post"
|
||||||
|
target="silent-submit"
|
||||||
|
>
|
||||||
|
<button type="submit" class="btn off">Iskljuci svetlo</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<p class="hint">Ako ne reaguje odmah, sacekajte 1-2 sekunde i ponovite.</p>
|
||||||
|
<iframe name="silent-submit" title="silent-submit" hidden></iframe>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="card bojana">
|
||||||
|
<h2>Za Bojanu</h2>
|
||||||
|
<p>
|
||||||
|
Posebna strana sa kratkim uputstvom i malim iznenadjenjem je ovde:
|
||||||
|
</p>
|
||||||
|
<a class="btn love" href="./bojana.html">Otvori Bojaninu stranu</a>
|
||||||
|
<div class="qr-grid single">
|
||||||
|
<div class="qr-card">
|
||||||
|
<h3>QR za Bojanu</h3>
|
||||||
|
<img id="bojana-qr" alt="Bojana QR" />
|
||||||
|
<p class="hint">Direktno otvara Bojaninu stranu.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<script src="./app.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name _;
|
||||||
|
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ =404;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /api/ {
|
||||||
|
proxy_pass http://guest-portal-api:8081/;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /qr/ {
|
||||||
|
proxy_pass http://guest-portal-api:8081/qr/;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,186 @@
|
|||||||
|
:root {
|
||||||
|
--bg: #f6f5f1;
|
||||||
|
--card: #ffffff;
|
||||||
|
--text: #1d2129;
|
||||||
|
--muted: #5b6470;
|
||||||
|
--line: #e4e7ec;
|
||||||
|
--on: #0a7a3d;
|
||||||
|
--off: #8f1d1d;
|
||||||
|
--accent: #1f5ad2;
|
||||||
|
--love: #b0216a;
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
font-family: "Segoe UI", Roboto, sans-serif;
|
||||||
|
background: radial-gradient(circle at top right, #fff6fb 0%, var(--bg) 45%);
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
max-width: 820px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 24px 16px 48px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero {
|
||||||
|
margin-bottom: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.eyebrow {
|
||||||
|
margin: 0 0 6px;
|
||||||
|
color: var(--muted);
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.08em;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
margin: 0 0 10px;
|
||||||
|
line-height: 1.2;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lead {
|
||||||
|
margin: 0;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
background: var(--card);
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: 14px;
|
||||||
|
padding: 18px;
|
||||||
|
margin-top: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.muted {
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
margin: 12px 0;
|
||||||
|
padding: 10px;
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
display: block;
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 12px;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list {
|
||||||
|
margin: 0;
|
||||||
|
padding-left: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list li {
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controls {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
border: 0;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 11px 14px;
|
||||||
|
cursor: pointer;
|
||||||
|
color: #fff;
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 14px;
|
||||||
|
text-decoration: none;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn.secondary {
|
||||||
|
background: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn.on {
|
||||||
|
background: var(--on);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn.off {
|
||||||
|
background: var(--off);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn.love {
|
||||||
|
background: var(--love);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hint {
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 13px;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.love-note {
|
||||||
|
background: linear-gradient(135deg, #fff4fa, #fff);
|
||||||
|
}
|
||||||
|
|
||||||
|
.qr-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||||
|
gap: 10px;
|
||||||
|
margin-top: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.qr-grid.single {
|
||||||
|
grid-template-columns: minmax(220px, 280px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.qr-card {
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 10px;
|
||||||
|
background: #fcfcff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.qr-card h3 {
|
||||||
|
margin: 0 0 8px;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.qr-card img {
|
||||||
|
width: 170px;
|
||||||
|
height: 170px;
|
||||||
|
object-fit: contain;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 640px) {
|
||||||
|
.row {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
FROM python:3.12-alpine
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN pip install --no-cache-dir segno==1.6.6
|
||||||
|
|
||||||
|
COPY app.py /app/app.py
|
||||||
|
|
||||||
|
EXPOSE 8081
|
||||||
|
|
||||||
|
CMD ["python", "/app/app.py"]
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
import io
|
||||||
|
import os
|
||||||
|
import urllib.request
|
||||||
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||||
|
|
||||||
|
import segno
|
||||||
|
|
||||||
|
|
||||||
|
HOST = "0.0.0.0"
|
||||||
|
PORT = 8081
|
||||||
|
|
||||||
|
HA_BASE = os.getenv("HA_BASE_URL", "http://192.168.0.26:8123").rstrip("/")
|
||||||
|
WEBHOOK_ON = os.getenv("HA_WEBHOOK_ON", "guest_light_on_hc_2026_a9f")
|
||||||
|
WEBHOOK_OFF = os.getenv("HA_WEBHOOK_OFF", "guest_light_off_hc_2026_b4d")
|
||||||
|
|
||||||
|
WIFI_SSID = os.getenv("WIFI_SSID", "Zapadna")
|
||||||
|
WIFI_PASS = os.getenv("WIFI_PASS", "CHANGE_ME")
|
||||||
|
PORTAL_BASE_URL = os.getenv("PORTAL_BASE_URL", "http://192.168.0.26:8090").rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _svg_bytes(payload: str) -> bytes:
|
||||||
|
qr = segno.make(payload)
|
||||||
|
buff = io.BytesIO()
|
||||||
|
qr.save(buff, kind="svg", scale=6)
|
||||||
|
return buff.getvalue()
|
||||||
|
|
||||||
|
|
||||||
|
def _call_webhook(webhook_id: str) -> bool:
|
||||||
|
req = urllib.request.Request(
|
||||||
|
f"{HA_BASE}/api/webhook/{webhook_id}",
|
||||||
|
method="POST",
|
||||||
|
data=b"",
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(req, timeout=4) as res:
|
||||||
|
return 200 <= res.status < 300
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
class Handler(BaseHTTPRequestHandler):
|
||||||
|
def do_GET(self):
|
||||||
|
if self.path == "/qr/wifi.svg":
|
||||||
|
payload = f"WIFI:T:WPA;S:{WIFI_SSID};P:{WIFI_PASS};;"
|
||||||
|
data = _svg_bytes(payload)
|
||||||
|
self.send_response(200)
|
||||||
|
self.send_header("Content-Type", "image/svg+xml")
|
||||||
|
self.send_header("Cache-Control", "public, max-age=300")
|
||||||
|
self.end_headers()
|
||||||
|
self.wfile.write(data)
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.path == "/qr/portal.svg":
|
||||||
|
data = _svg_bytes(f"{PORTAL_BASE_URL}/index.html")
|
||||||
|
self.send_response(200)
|
||||||
|
self.send_header("Content-Type", "image/svg+xml")
|
||||||
|
self.send_header("Cache-Control", "public, max-age=300")
|
||||||
|
self.end_headers()
|
||||||
|
self.wfile.write(data)
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.path == "/qr/bojana.svg":
|
||||||
|
data = _svg_bytes(f"{PORTAL_BASE_URL}/bojana.html")
|
||||||
|
self.send_response(200)
|
||||||
|
self.send_header("Content-Type", "image/svg+xml")
|
||||||
|
self.send_header("Cache-Control", "public, max-age=300")
|
||||||
|
self.end_headers()
|
||||||
|
self.wfile.write(data)
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.path == "/healthz":
|
||||||
|
self.send_response(200)
|
||||||
|
self.send_header("Content-Type", "text/plain; charset=utf-8")
|
||||||
|
self.end_headers()
|
||||||
|
self.wfile.write(b"ok")
|
||||||
|
return
|
||||||
|
|
||||||
|
self.send_response(404)
|
||||||
|
self.end_headers()
|
||||||
|
|
||||||
|
def do_POST(self):
|
||||||
|
if self.path in ("/api/light/on", "/light/on"):
|
||||||
|
ok = _call_webhook(WEBHOOK_ON)
|
||||||
|
self.send_response(204 if ok else 502)
|
||||||
|
self.end_headers()
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.path in ("/api/light/off", "/light/off"):
|
||||||
|
ok = _call_webhook(WEBHOOK_OFF)
|
||||||
|
self.send_response(204 if ok else 502)
|
||||||
|
self.end_headers()
|
||||||
|
return
|
||||||
|
|
||||||
|
self.send_response(404)
|
||||||
|
self.end_headers()
|
||||||
|
|
||||||
|
def log_message(self, *_):
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
HTTPServer((HOST, PORT), Handler).serve_forever()
|
||||||
Reference in New Issue
Block a user