Merge pull request #46823 from rallytime/fix-42312

Improve __virtual__ checks in sensehat module
This commit is contained in:
Nicole Thomas 2018-04-03 12:56:08 -04:00 committed by GitHub
commit e544254e7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,7 +25,6 @@ import logging
try:
from sense_hat import SenseHat
_sensehat = SenseHat()
has_sense_hat = True
except (ImportError, NameError):
_sensehat = None
@ -39,14 +38,19 @@ def __virtual__():
Only load the module if SenseHat is available
'''
if has_sense_hat:
try:
_sensehat = SenseHat()
except OSError:
return False, 'This module can only be used on a Raspberry Pi with a SenseHat.'
rotation = __salt__['pillar.get']('sensehat:rotation', 0)
if rotation in [0, 90, 180, 270]:
_sensehat.set_rotation(rotation, False)
else:
log.error("{0} is not a valid rotation. Using default rotation.".format(rotation))
log.error('{0} is not a valid rotation. Using default rotation.'.format(rotation))
return True
else:
return False, "The SenseHat excecution module can not be loaded: SenseHat unavailable.\nThis module can only be used on a Raspberry Pi with a SenseHat. Also make sure that the sense_hat python library is installed!"
return False, 'The SenseHat execution module cannot be loaded: \'sense_hat\' python library unavailable.'
def set_pixels(pixels):