Skip to content

Commit ad7485b

Browse files
committed
Modify AnalogInput initialization, add exception handling.
1 parent 2435bf0 commit ad7485b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

myDevices/plugins/analog.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
"""
44
import json
55
from myDevices.plugins.manager import PluginManager
6-
from myDevices.utils.logger import info
6+
from myDevices.utils.logger import info, debug
77

88

99
class AnalogInput():
1010
"""Reads data from an analog input."""
1111

12-
def __init__(self, adc_name):
12+
def __init__(self, adc):
1313
"""Initializes the analog input.
1414
1515
Arguments:
16-
adc_name: Name of analog-to-digital converter plugin in the format 'plugin_name:section'
16+
adc: Analog-to-digital converter plugin ID in the format 'plugin_name:section', e.g. 'cayenne-mcp3xxx:MCP'
1717
"""
18-
self.adc_name = adc_name
18+
self.adc_name = adc
1919
self.adc = None
2020
self.read_args = {}
2121
self.pluginManager = PluginManager()
@@ -30,7 +30,11 @@ def set_adc(self):
3030
def read_value(self, channel, data_type=None):
3131
"""Read the data value on the specified channel."""
3232
self.set_adc()
33-
value = getattr(self.adc['instance'], self.adc['read'])(channel, data_type=data_type, **self.read_args)
33+
try:
34+
value = getattr(self.adc['instance'], self.adc['read'])(channel, data_type=data_type, **self.read_args)
35+
except ValueError as e:
36+
debug(e)
37+
value = None
3438
return value
3539

3640
def read_float(self, channel):

0 commit comments

Comments
 (0)