From a31ef18ad1fb7796d9105ab613f89e53c43f5688 Mon Sep 17 00:00:00 2001 From: Hans Lohmann Date: Wed, 6 Jan 2021 06:29:09 +0100 Subject: [PATCH] Check if attribute setPointTemperature before use Make use of hasattr to see if the attribute setPointTemperature really exists before using its value. This should fix #4 --- exporter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exporter.py b/exporter.py index 91452f9..955d9da 100755 --- a/exporter.py +++ b/exporter.py @@ -167,14 +167,14 @@ def __collect_thermostat_metrics(self, room, device): if device.actualTemperature: self.metric_temperature_actual.labels(room=room, device_label=device.label).set(device.actualTemperature) - if device.setPointTemperature: + if hasattr(device, 'setPointTemperature'): self.metric_temperature_setpoint.labels(room=room, device_label=device.label).set(device.setPointTemperature) if device.humidity: self.metric_humidity_actual.labels(room=room, device_label=device.label).set(device.humidity) logging.info( - "room: {}, label: {}, temperature_actual: {}, temperature_setpoint: {}, humidity_actual: {}" - .format(room, device.label, device.actualTemperature, device.setPointTemperature, device.humidity) + "found device: room: {}, label: {}, temperature_actual: {}, temperature_setpoint: {}, humidity_actual: {}" + .format(room, device.label, device.actualTemperature, device.setPointTemperature if hasattr(device, 'setPointTemperature') else "n/a", device.humidity) ) def __collect_heating_metrics(self, room, device):