Skip to content

Commit 686f35c

Browse files
committed
Handle errors in attrbute getter; fix unit __str__
1 parent b59dd40 commit 686f35c

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

‎ev3dev2/__init__.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,14 @@ def _attribute_file_open(self, name):
216216

217217
def _get_attribute(self, attribute, name):
218218
"""Device attribute getter"""
219-
if attribute is None:
220-
attribute = self._attribute_file_open( name )
221-
else:
222-
attribute.seek(0)
223-
return attribute, attribute.read().strip().decode()
219+
try:
220+
if attribute is None:
221+
attribute = self._attribute_file_open( name )
222+
else:
223+
attribute.seek(0)
224+
return attribute, attribute.read().strip().decode()
225+
except Exception as ex:
226+
self._raise_friendly_access_error(ex, name)
224227

225228
def _set_attribute(self, attribute, name, value):
226229
"""Device attribute setter"""

‎ev3dev2/motor.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def __init__(self, rotations_per_minute):
141141
self.rotations_per_minute = rotations_per_minute
142142

143143
def __str__(self):
144-
return str(self) + " rot/min"
144+
return str(self.rotations_per_minute) + " rot/min"
145145

146146
def to_native_units(self, motor):
147147
"""
@@ -160,7 +160,7 @@ def __init__(self, degrees_per_second):
160160
self.degrees_per_second = degrees_per_second
161161

162162
def __str__(self):
163-
return str(self) + " deg/sec"
163+
return str(self.degrees_per_second) + " deg/sec"
164164

165165
def to_native_units(self, motor):
166166
"""
@@ -179,7 +179,7 @@ def __init__(self, degrees_per_minute):
179179
self.degrees_per_minute = degrees_per_minute
180180

181181
def __str__(self):
182-
return int.__str__(self) + " deg/min"
182+
return str(self.degrees_per_minute) + " deg/min"
183183

184184
def to_native_units(self, motor):
185185
"""

0 commit comments

Comments
 (0)