Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9db7cde179 | |||
| 3140f65527 | |||
| 5727053951 |
16
CHANGELOG.md
16
CHANGELOG.md
@@ -1,5 +1,21 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.7.8 - 2026-06-15
|
||||||
|
- Home-Assistant-WebSocket-Listener deaktiviert den clientseitigen Keepalive-
|
||||||
|
Ping, damit stabile HA-Verbindungen nicht durch Ping-Timeouts ständig neu
|
||||||
|
aufgebaut werden
|
||||||
|
- Fallback-Auswertung läuft bei getrenntem WebSocket kurzfristig alle 5 Sekunden,
|
||||||
|
damit übernommene Aktoren nicht ohne Steuerung bleiben
|
||||||
|
|
||||||
|
## 0.7.7 - 2026-06-15
|
||||||
|
- WebSocket-State-Changes lesen jetzt das echte Home-Assistant-Eventformat
|
||||||
|
(`event.data.entity_id`), damit Kontextwechsel wie Türsensoren sofort
|
||||||
|
Vorhersagen und Schaltungen auslösen statt erst beim nächsten Statusabruf
|
||||||
|
|
||||||
|
## 0.7.6 - 2026-06-14
|
||||||
|
- Kontextvorschläge blenden zusätzlich Batterie-, Status-, Node-, Last-Seen-
|
||||||
|
und Basic-Entities aus, sofern sie nicht bewusst manuell ausgewählt wurden
|
||||||
|
|
||||||
## 0.7.5 - 2026-06-14
|
## 0.7.5 - 2026-06-14
|
||||||
- Kontextvorschläge weiter geschärft: Standardliste zeigt nur gleiche Räume,
|
- Kontextvorschläge weiter geschärft: Standardliste zeigt nur gleiche Räume,
|
||||||
gemeinsame Geräte/Tokens oder echte globale Außenwerte
|
gemeinsame Geräte/Tokens oder echte globale Außenwerte
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: SillyHome Next
|
name: SillyHome Next
|
||||||
version: "0.7.5"
|
version: "0.7.8"
|
||||||
slug: sillyhome_next
|
slug: sillyhome_next
|
||||||
description: Lernt automatisch aus deinem Verhalten und steuert freigegebene Aktoren
|
description: Lernt automatisch aus deinem Verhalten und steuert freigegebene Aktoren
|
||||||
url: http://192.168.6.31:3000/pino/sillyhome-next
|
url: http://192.168.6.31:3000/pino/sillyhome-next
|
||||||
|
|||||||
@@ -81,20 +81,28 @@ _MANUAL_CONTEXT_DOMAINS = frozenset({
|
|||||||
_CONTEXT_SUGGESTION_LIMIT = 120
|
_CONTEXT_SUGGESTION_LIMIT = 120
|
||||||
_OUTDOOR_TOKENS = frozenset({"aussen", "außen", "outdoor", "garten", "terrasse", "balkon"})
|
_OUTDOOR_TOKENS = frozenset({"aussen", "außen", "outdoor", "garten", "terrasse", "balkon"})
|
||||||
_DIAGNOSTIC_TOKENS = frozenset({
|
_DIAGNOSTIC_TOKENS = frozenset({
|
||||||
|
"basic",
|
||||||
|
"battery",
|
||||||
"connect",
|
"connect",
|
||||||
"count",
|
"count",
|
||||||
"diagnostic",
|
"diagnostic",
|
||||||
"firmware",
|
"firmware",
|
||||||
|
"gesehen",
|
||||||
"last",
|
"last",
|
||||||
"linkquality",
|
"linkquality",
|
||||||
|
"knoten",
|
||||||
|
"knotens",
|
||||||
"mqtt",
|
"mqtt",
|
||||||
|
"node",
|
||||||
"reason",
|
"reason",
|
||||||
"restart",
|
"restart",
|
||||||
"rssi",
|
"rssi",
|
||||||
"signal",
|
"signal",
|
||||||
"ssid",
|
"ssid",
|
||||||
|
"status",
|
||||||
"uptime",
|
"uptime",
|
||||||
"wifi",
|
"wifi",
|
||||||
|
"zuletzt",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
24
app/main.py
24
app/main.py
@@ -100,7 +100,7 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
|||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
title="SillyHome Next API",
|
title="SillyHome Next API",
|
||||||
description="Lokales Smart-Home-Intelligenzsystem für Home Assistant.",
|
description="Lokales Smart-Home-Intelligenzsystem für Home Assistant.",
|
||||||
version="0.7.5",
|
version="0.7.8",
|
||||||
lifespan=lifespan,
|
lifespan=lifespan,
|
||||||
)
|
)
|
||||||
app.state.settings = load_settings()
|
app.state.settings = load_settings()
|
||||||
@@ -171,7 +171,7 @@ async def _ha_event_listener(app: FastAPI, client: HaClient) -> None:
|
|||||||
if ws_status is not None:
|
if ws_status is not None:
|
||||||
ws_status.status = "connecting"
|
ws_status.status = "connecting"
|
||||||
try:
|
try:
|
||||||
async with websockets.connect(ws_url) as websocket:
|
async with websockets.connect(ws_url, ping_interval=None) as websocket:
|
||||||
auth_required_msg = await websocket.recv()
|
auth_required_msg = await websocket.recv()
|
||||||
auth_required_data = json.loads(auth_required_msg)
|
auth_required_data = json.loads(auth_required_msg)
|
||||||
if auth_required_data.get("type") != "auth_required":
|
if auth_required_data.get("type") != "auth_required":
|
||||||
@@ -213,12 +213,20 @@ async def _ha_event_listener(app: FastAPI, client: HaClient) -> None:
|
|||||||
event = data.get("event", {})
|
event = data.get("event", {})
|
||||||
if event.get("event_type") != "state_changed":
|
if event.get("event_type") != "state_changed":
|
||||||
continue
|
continue
|
||||||
entity_id = event.get("entity_id")
|
event_data = event.get("data", {})
|
||||||
|
if not isinstance(event_data, dict):
|
||||||
|
logger.warning("State-Changed-Event ohne gültige Daten empfangen")
|
||||||
|
continue
|
||||||
|
entity_id = event_data.get("entity_id")
|
||||||
if not entity_id:
|
if not entity_id:
|
||||||
continue
|
continue
|
||||||
# Prüfe, ob Entity ein Aktor oder relevanter Kontext ist
|
# Prüfe, ob Entity ein Aktor oder relevanter Kontext ist
|
||||||
# Sofortige Vorhersage für betroffene Aktoren auslösen
|
# Sofortige Vorhersage für betroffene Aktoren auslösen
|
||||||
await asyncio.to_thread(engine.handle_state_change, entity_id, event.get("new_state"))
|
await asyncio.to_thread(
|
||||||
|
engine.handle_state_change,
|
||||||
|
entity_id,
|
||||||
|
event_data.get("new_state"),
|
||||||
|
)
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
logger.warning("Ungültige JSON-Nachricht von HA-WebSocket")
|
logger.warning("Ungültige JSON-Nachricht von HA-WebSocket")
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
@@ -244,7 +252,13 @@ async def _fallback_prediction(app: FastAPI) -> None:
|
|||||||
Dies verhindert kompletten Ausfall der Vorhersagen bei Netzwerkproblemen.
|
Dies verhindert kompletten Ausfall der Vorhersagen bei Netzwerkproblemen.
|
||||||
"""
|
"""
|
||||||
while True:
|
while True:
|
||||||
await asyncio.sleep(app.state.settings.prediction_interval_seconds)
|
ws_status = getattr(app.state, "ws_status", None)
|
||||||
|
websocket_connected = ws_status is not None and ws_status.status == "connected"
|
||||||
|
await asyncio.sleep(
|
||||||
|
app.state.settings.prediction_interval_seconds
|
||||||
|
if websocket_connected
|
||||||
|
else min(5, app.state.settings.prediction_interval_seconds)
|
||||||
|
)
|
||||||
# Nur ausführen, wenn WebSocket nicht verbunden ist
|
# Nur ausführen, wenn WebSocket nicht verbunden ist
|
||||||
ws_status = getattr(app.state, "ws_status", None)
|
ws_status = getattr(app.state, "ws_status", None)
|
||||||
if ws_status is None or ws_status.status != "connected":
|
if ws_status is None or ws_status.status != "connected":
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "sillyhome-next"
|
name = "sillyhome-next"
|
||||||
version = "0.7.5"
|
version = "0.7.8"
|
||||||
description = "Lokales Smart-Home-Intelligenzsystem für Home Assistant"
|
description = "Lokales Smart-Home-Intelligenzsystem für Home Assistant"
|
||||||
requires-python = ">=3.11"
|
requires-python = ">=3.11"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ def _service(
|
|||||||
model_store=str(tmp_path / "models"),
|
model_store=str(tmp_path / "models"),
|
||||||
automation_store=str(tmp_path / "automations"),
|
automation_store=str(tmp_path / "automations"),
|
||||||
actuator_store=str(tmp_path / "actuators"),
|
actuator_store=str(tmp_path / "actuators"),
|
||||||
history_days=14,
|
history_days=31,
|
||||||
min_training_points=5,
|
min_training_points=5,
|
||||||
retrain_stale_hours=24,
|
retrain_stale_hours=24,
|
||||||
reconcile_interval_seconds=900,
|
reconcile_interval_seconds=900,
|
||||||
|
|||||||
@@ -55,18 +55,22 @@ def test_ha_event_listener_processes_state_change(tmp_path: Path) -> None:
|
|||||||
'{"type":"auth_ok"}',
|
'{"type":"auth_ok"}',
|
||||||
(
|
(
|
||||||
'{"type":"event","event":{"event_type":"state_changed",'
|
'{"type":"event","event":{"event_type":"state_changed",'
|
||||||
'"entity_id":"light.test","new_state":{"state":"on"}}}'
|
'"data":{"entity_id":"light.test","new_state":{"state":"on"}}}}'
|
||||||
),
|
),
|
||||||
asyncio.CancelledError(),
|
asyncio.CancelledError(),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch("websockets.connect", return_value=fake_ws):
|
with patch("websockets.connect", return_value=fake_ws) as connect:
|
||||||
try:
|
try:
|
||||||
await _ha_event_listener(mock_app, mock_client)
|
await _ha_event_listener(mock_app, mock_client)
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
connect.assert_called_once_with(
|
||||||
|
"ws://homeassistant:8123/api/websocket",
|
||||||
|
ping_interval=None,
|
||||||
|
)
|
||||||
assert fake_ws.sent == [
|
assert fake_ws.sent == [
|
||||||
{"type": "auth", "access_token": "test-token"},
|
{"type": "auth", "access_token": "test-token"},
|
||||||
{"id": 1, "type": "subscribe_events", "event_type": "state_changed"},
|
{"id": 1, "type": "subscribe_events", "event_type": "state_changed"},
|
||||||
|
|||||||
Reference in New Issue
Block a user