IndigoDomotics / adapters

A very flexible plugin for the Indigo Home Automation platform that can generate "adapter" devices in front of sensors to transform the readings however you may prefer.
Apache License 2.0
0 stars 1 forks source link

KeyError on Server Spool #2

Closed DaveL17 closed 2 years ago

DaveL17 commented 5 years ago

Hello - when starting the Indigo server, I get a KeyError traceback:

2019-03-03 13:21:17.074 Adapters Error  Error in plugin execution ServerReplacedElem:

Traceback (most recent call last):
  File "plugin.py", line 130, in deviceUpdated
  File "/Library/Application Support/Perceptive Automation/Indigo 7.3/Plugins/Adapters.indigoPlugin/Contents/Server Plugin/sensor_adapter.py", line 37, in go
KeyError: key owd_EDS2040_Humidity not found in dict

2019-03-03 13:21:17.077 Adapters Error  Error in plugin execution ServerReplacedElem:

Traceback (most recent call last):
  File "plugin.py", line 130, in deviceUpdated
  File "/Library/Application Support/Perceptive Automation/Indigo 7.3/Plugins/Adapters.indigoPlugin/Contents/Server Plugin/sensor_adapter.py", line 37, in go
KeyError: key owd_EDS2040_Humidity not found in dict

2019-03-03 13:21:17.083 Adapters Error  Error in plugin execution ServerReplacedElem:

Traceback (most recent call last):
  File "plugin.py", line 130, in deviceUpdated
  File "/Library/Application Support/Perceptive Automation/Indigo 7.3/Plugins/Adapters.indigoPlugin/Contents/Server Plugin/sensor_adapter.py", line 37, in go
KeyError: key owd_EDS2040_Humidity not found in dict

This is presumably because the subject device is a plugin custom device and, since that plugin hasn't spooled up yet, the device isn't ready to be processed.

I have found that wrapping the go() method in a try/except block with a simple pass on KeyError solves the problem.

def go(self):
    try:
        native_value = indigo.devices[self.native_device_id].states[self.native_device_state_name]

        converted_txt = self.desired_scale.format(native_value)
        converted_value = self.desired_scale.convert(native_value)

        self.dev.updateStateOnServer(key="sensorValue", value=converted_value, decimalPlaces=self.precision, uiValue=converted_txt)
        self.log.debug("%s: %s" % (self.name(), converted_txt))
    except KeyError:
        pass

Cheers, Dave

DaveL17 commented 2 years ago

Will be addressed in v2022.1.8