sms_functions: added unlock_and_enable_modem
This commit is contained in:
parent
fa27b99970
commit
e7e855049a
@ -68,12 +68,8 @@ def unlock_sim(modem):
|
||||
remaining_attempts = modem.UnlockRetries
|
||||
raise SIMError('Failed to unlock PIN, remaining attempts: {}'.format(remaining_attempts)) from exc
|
||||
|
||||
def unlock_and_enable_modem():
|
||||
|
||||
def send_sms(recipients, smsstring):
|
||||
|
||||
# Assemble SMS
|
||||
logger.info("Sending SMS: %s", smsstring)
|
||||
|
||||
retries = 0
|
||||
# Retry the whole block, because once pydbus fetches the properties
|
||||
# it does not really refresh them, including modems
|
||||
@ -82,18 +78,31 @@ def send_sms(recipients, smsstring):
|
||||
# enable the modem
|
||||
# Get modem, unlock SIM
|
||||
modem = get_modem()
|
||||
|
||||
logger.debug("Unlocking SIM (if needed)")
|
||||
unlock_sim(modem)
|
||||
|
||||
logger.debug("Enabling modem")
|
||||
modem.Enable(True)
|
||||
break
|
||||
return modem
|
||||
|
||||
except SIMError:
|
||||
# cannot continue with this one (could be a wrong PIN
|
||||
# and then we waste our attempts)
|
||||
raise
|
||||
|
||||
except:
|
||||
retries += 1
|
||||
time.sleep(1)
|
||||
if retries > 15:
|
||||
raise
|
||||
|
||||
def send_sms(recipients, smsstring):
|
||||
|
||||
# Assemble SMS
|
||||
logger.info("Sending SMS: %s", smsstring)
|
||||
|
||||
unlock_and_enable_modem()
|
||||
|
||||
# test sending SMS
|
||||
modem_msg = modem['org.freedesktop.ModemManager1.Modem.Messaging']
|
||||
|
Loading…
Reference in New Issue
Block a user