Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions ev3dev/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def _attribute_file_open( self, name ):
def _get_attribute(self, attribute, name):
"""Device attribute getter"""
if self.connected:
if None == attribute:
if attribute is None:
attribute = self._attribute_file_open( name )
else:
attribute.seek(0)
Expand All @@ -235,12 +235,12 @@ def _get_attribute(self, attribute, name):
def _set_attribute(self, attribute, name, value):
"""Device attribute setter"""
if self.connected:
if None == attribute:
attribute = self._attribute_file_open( name )
else:
attribute.seek(0)

try:
if attribute is None:
attribute = self._attribute_file_open( name )
else:
attribute.seek(0)

attribute.write(value.encode())
attribute.flush()
except Exception as ex:
Expand All @@ -263,6 +263,11 @@ def _raise_friendly_access_error(self, driver_error, attribute):
else:
raise ValueError("The given speed value was out of range. Max speed: +/-" + str(max_speed)) from driver_error
raise ValueError("One or more arguments were out of range or invalid") from driver_error
elif driver_error.errno == errno.ENODEV or driver_error.errno == errno.ENOENT:
# We will assume that a file-not-found error is the result of a disconnected device
# rather than a library error. If that isn't the case, at a minimum the underlying
# error info will be printed for debugging.
raise Exception("%s is no longer connected" % self) from driver_error
raise driver_error

def get_attr_int(self, attribute, name):
Expand Down