Fix temperature duplication in MQTT payload
Temperature now only appears at root level, not in details. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -54,17 +54,15 @@ class SnmpChecker(BaseChecker):
|
|||||||
response_time=None
|
response_time=None
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
details = {str(oid): str(val) for oid, val in var_binds}
|
# Only include main OID in details, not temperature
|
||||||
|
details = {str(var_binds[0][0]): str(var_binds[0][1])}
|
||||||
|
|
||||||
# Extract temperature if configured
|
# Extract temperature if configured (second OID in response)
|
||||||
if temperature_oid:
|
if temperature_oid and len(var_binds) >= 2:
|
||||||
for oid_key, val in var_binds:
|
try:
|
||||||
if str(oid_key) == temperature_oid:
|
details["temperature"] = int(var_binds[1][1])
|
||||||
try:
|
except (ValueError, TypeError):
|
||||||
details["temperature"] = int(val)
|
pass # Ignore if not a valid integer
|
||||||
except (ValueError, TypeError):
|
|
||||||
pass # Ignore if not a valid integer
|
|
||||||
break
|
|
||||||
|
|
||||||
return CheckResult(
|
return CheckResult(
|
||||||
success=True,
|
success=True,
|
||||||
|
|||||||
@@ -177,10 +177,11 @@ class LanChecker:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if result.details:
|
if result.details:
|
||||||
payload["details"] = result.details
|
|
||||||
# Extract temperature for SNMP checks
|
# Extract temperature for SNMP checks
|
||||||
if "temperature" in result.details:
|
if "temperature" in result.details:
|
||||||
payload["temperature"] = result.details["temperature"]
|
payload["temperature"] = result.details.pop("temperature")
|
||||||
|
if result.details:
|
||||||
|
payload["details"] = result.details
|
||||||
|
|
||||||
topic = f"lan_checker/{check['id']}/state"
|
topic = f"lan_checker/{check['id']}/state"
|
||||||
self.mqtt_client.publish(topic, json.dumps(payload), retain=True)
|
self.mqtt_client.publish(topic, json.dumps(payload), retain=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user