81 lines
2.6 KiB
Python
81 lines
2.6 KiB
Python
class DiagnosisEngine:
|
|
def __init__(self):
|
|
self.signals = {}
|
|
|
|
def add(self, key, value):
|
|
self.signals[key] = value
|
|
|
|
def evaluate(self):
|
|
results = []
|
|
|
|
lms = self.signals.get("lms")
|
|
ha_logs_client_error = self.signals.get("ha_logs_client_connector_error")
|
|
ha_container = self.signals.get("ha_container")
|
|
ha_dependency_failure = (
|
|
lms == "000"
|
|
and ha_logs_client_error
|
|
and ha_container == "running"
|
|
)
|
|
|
|
# LMS
|
|
if lms == "000" and not ha_dependency_failure:
|
|
results.append("[info] LMS is not reachable")
|
|
elif lms == "200":
|
|
results.append("[info] LMS: OK")
|
|
|
|
# Dependency failures
|
|
if ha_dependency_failure:
|
|
results.append("[warning] HA dependency failure: LMS unreachable")
|
|
|
|
# HA local
|
|
ha_local = self.signals.get("ha_local")
|
|
if ha_local == "000":
|
|
options = [
|
|
{
|
|
"label": "Restart HA",
|
|
"command": "restart_ha",
|
|
"confidence": 0.85,
|
|
},
|
|
{
|
|
"label": "Check network",
|
|
"command": "check_network",
|
|
"confidence": 0.6,
|
|
}
|
|
]
|
|
ignore_option = {
|
|
"label": "Ignore",
|
|
"command": "ignore",
|
|
"is_ignore": True,
|
|
}
|
|
results.append("[error] HA is not working locally")
|
|
results.append(
|
|
{
|
|
"type": "proposal",
|
|
"message": "Home Assistant is not working",
|
|
"confidence": 0.85,
|
|
"options": sorted(
|
|
options,
|
|
key=lambda option: option["confidence"],
|
|
reverse=True,
|
|
) + [ignore_option],
|
|
}
|
|
)
|
|
elif ha_local == "200":
|
|
results.append("[info] HA local: OK")
|
|
|
|
# HA proxy
|
|
ha_proxy = self.signals.get("ha_proxy")
|
|
if ha_proxy == "dns_error":
|
|
results.append("[error] HA proxy: DNS failure")
|
|
results.append("[error] external access issue: DNS or routing failure")
|
|
elif ha_proxy == "000":
|
|
results.append("[error] HA proxy: not reachable")
|
|
elif ha_proxy == "200":
|
|
results.append("[info] HA proxy: OK")
|
|
|
|
diagnosis_count = sum(1 for result in results if isinstance(result, str))
|
|
if diagnosis_count > 1:
|
|
results.append("[info] multiple issues detected")
|
|
|
|
return results
|