import os
from tenda4g09 import Tenda4G09

tenda = Tenda4G09(os.environ['TENDA_HOST'])
success = False

# Try as may times as necessary
while not success:
    success = tenda.login(os.environ['TENDA_PASSWORD'])
    if success:
        success = tenda.reboot()
        print("Reboot OK" if success else "Reboot ERROR! Retrying...")
    else:
        print("Login error! Retrying...")