Skip to content

Commit 69d3049

Browse files
committed
Improve exception handling.
1 parent 631551f commit 69d3049

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

myDevices/plugins/digital.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ def __init__(self, plugin_id):
1818

1919
def value_to_tuple(self, value):
2020
"""Converts value to tuple with the appropriate Cayenne data type."""
21-
return (int(value), self.data_type)
21+
try:
22+
return (int(value), self.data_type)
23+
except:
24+
return InputOutput.value_to_tuple(self, value)
2225

2326

2427
class DigitalOutput(DigitalInput):

myDevices/plugins/io.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def read_value(self, channel, value_type=None):
7373
if value_type:
7474
read_args['value_type'] = value_type
7575
result = getattr(self.plugin['instance'], self.plugin['read'])(channel, **read_args)
76-
except:
77-
error('Error reading value from plugin {}, channel {}'.format(self.plugin_id, channel))
76+
except Exception as e:
77+
error('Error reading value from plugin {}, channel {}: {}'.format(self.plugin_id, channel, e))
7878
return result
7979

8080
def write(self, value, channel, value_type=None):
@@ -86,16 +86,16 @@ def write_value(self, value, channel, value_type=None):
8686
result = None
8787
self.set_plugin()
8888
if not self.plugin:
89-
error('Plugin {} not loaded'.format(self.plugin_id))
89+
error('Plugin {} is not loaded'.format(self.plugin_id))
9090
return result
9191
self.set_function(channel)
9292
try:
9393
write_args = self.write_args
9494
if value_type:
9595
write_args['value_type'] = value_type
9696
result = getattr(self.plugin['instance'], self.plugin['write'])(channel, value, **write_args)
97-
except:
98-
error('Error writing value to plugin {}, channel {}'.format(self.plugin_id, channel))
97+
except Exception as e:
98+
error('Error writing value to plugin {}, channel {}: {}'.format(self.plugin_id, channel, e))
9999
return result
100100

101101
def register_callback(self, callback):

0 commit comments

Comments
 (0)