Skip to content

Commit

Permalink
Check if attribute setPointTemperature before use
Browse files Browse the repository at this point in the history
Make use of hasattr to see if the attribute setPointTemperature really
exists before using its value. This should fix  auhlig#4
  • Loading branch information
Hans Lohmann committed Jan 6, 2021
1 parent a1003fd commit a31ef18
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit a31ef18

Please sign in to comment.