mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #46823 from rallytime/fix-42312
Improve __virtual__ checks in sensehat module
This commit is contained in:
commit
e544254e7b
1 changed files with 8 additions and 4 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Reference in a new issue