Add optional temperature support to SNMP checker

- New temperature_oid config parameter
- Temperature published as integer via MQTT
- Auto-creates Home Assistant temperature sensor via MQTT Discovery

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-26 17:47:01 +01:00
parent c72117e6e1
commit 10fad0d9f3
3 changed files with 47 additions and 3 deletions

View File

@@ -121,6 +121,29 @@ class LanChecker:
retain=True
)
# Sensor for temperature (SNMP only, if temperature_oid configured)
if check.get("type") == "snmp" and check.get("temperature_oid"):
temp_config = {
"name": f"{device_name} Temperature",
"unique_id": f"lan_checker_{device_id}_temperature",
"state_topic": f"lan_checker/{device_id}/state",
"value_template": "{{ value_json.temperature | default('unavailable') }}",
"unit_of_measurement": "°C",
"device_class": "temperature",
"state_class": "measurement",
"device": {
"identifiers": [f"lan_checker_{device_id}"],
"name": device_name,
"manufacturer": "LAN Checker",
},
}
self.mqtt_client.publish(
f"homeassistant/sensor/lan_checker_{device_id}_temperature/config",
json.dumps(temp_config),
retain=True
)
logger.info(f"Published discovery for: {device_name}")
def _setup_checks(self):
@@ -155,6 +178,9 @@ class LanChecker:
if result.details:
payload["details"] = result.details
# Extract temperature for SNMP checks
if "temperature" in result.details:
payload["temperature"] = result.details["temperature"]
topic = f"lan_checker/{check['id']}/state"
self.mqtt_client.publish(topic, json.dumps(payload), retain=True)