Ejemplo n.º 1
0
def main():
    global api
    api = TuyaApi()
    config.module.get_token(api)
    if not config.DEVICE_ID:
        print(api.get_all_devices())
        sys.exit(0)

    global socket
    socket = api.get_device_by_id(config.DEVICE_ID)
Ejemplo n.º 2
0

def stop_charging(socket, api):
    try:
        logger.info("Stoping the charge")
        socket.turn_off()  # maybe add reconnecting if needed
    except:
        get_token(api)


if __name__ == "__main__":
    api = TuyaApi()
    get_token(api)
    if not DEVICE_ID:
        print(api.get_all_devices())
        sys.exit(0)

    socket = api.get_device_by_id(DEVICE_ID)
    while True:
        if battery_percentage(
        ) > STOP_CHARGING_PERCENTAGE and battery_charging():
            stop_charging(socket, api)
        elif battery_percentage(
        ) < START_CHARGING_PERCENTAGE and not battery_charging():
            start_charging(socket, api)
        logger.debug("Battery percentage at " + str(battery_percentage()))
        sleep(SLEEP_TIME)

    #plugged = "Plugged In" if plugged else "Not Plugged In"
    #print(percent+'% | '+plugged)
        DEBUG = True
    elif opt == '-c':
        confFile = arg

conf = ConfigurationReader.Read(confFile)

username = conf["username"]
password = conf["password"]
countryCode = conf["country_code"]
deviceId = conf["device_id"]

api = TuyaApi()

api.init(username, password, countryCode)

device = api.get_device_by_id(deviceId)

device.set_brightness(10)
device.set_color_temp(2700)

delay = 5
step = 1

if DEBUG == True:
    delay = 1
    step = 20

for brightness in range(11, 255, step):
    device.set_brightness(brightness)
    sleep(delay)