Skip to content

Commit 28cae10

Browse files
committed
Check if device is connected before trying to access attributes
1 parent e627510 commit 28cae10

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

ev3dev/core.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,17 @@ def _matches(self, attribute, pattern):
197197

198198
def _get_attribute(self, attribute):
199199
"""Device attribute getter"""
200-
return self._attribute_cache.read(abspath(self._path + '/' + attribute))
200+
if self.connected:
201+
return self._attribute_cache.read(abspath(self._path + '/' + attribute))
202+
else:
203+
raise Exception('Device is not connected')
201204

202205
def _set_attribute(self, attribute, value):
203206
"""Device attribute setter"""
204-
self._attribute_cache.write(abspath(self._path + '/' + attribute), value)
207+
if self.connected:
208+
self._attribute_cache.write(abspath(self._path + '/' + attribute), value)
209+
else:
210+
raise Exception('Device is not connected')
205211

206212
def get_attr_int(self, attribute):
207213
return int(self._get_attribute(attribute))

0 commit comments

Comments
 (0)