async def main_energy(email, password, token): client = TeslaApiClient(email, password, token, on_new_token=save_token) energy_sites = await client.list_energy_sites() print("Number of energy sites = %d" % (len(energy_sites))) assert (len(energy_sites) == 1) reserve = await energy_sites[0].get_backup_reserve_percent() print("Backup reserve percent = %d" % (reserve)) print("Increment backup reserve percent") await energy_sites[0].set_backup_reserve_percent(reserve + 1) client.close()
async def get_tesla(): tesla_client = None my_tesla = None charge_port = True tesla_client = TeslaApiClient(auth.TESLAUSERNAME, auth.TESLAPASSWORD) vehicles = await tesla_client.list_vehicles() try: if None is my_tesla: if tesla_client is not None: tesla_client.close() tesla_client = TeslaApiClient(auth.TESLAUSERNAME, auth.TESLAPASSWORD) vehicles = await tesla_client.list_vehicles() for v in vehicles: if v.vin == '5YJYGDEE9LF035958': my_tesla = v if my_tesla.state == 'online': try: charge = await my_tesla.charge.get_state() except Exception as e: print("Exception A: " + str(e)) await tesla_client.close() my_tesla = None tesla_client = None else: await tesla_client.close() my_tesla = None tesla_client = None except AttributeError as error: await tesla_client.close() tesla_client = None print(error)