#!/usr/bin/env python3
#

import logging
import os
import sys
import time
import pprint

# for examples add pyaarlo install path
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
import pyaarlo

# set these from the environment to log in
USERNAME = os.environ.get('ARLO_USERNAME', 'test.login@gmail.com')
PASSWORD = os.environ.get('ARLO_PASSWORD', 'test-password')

# set up logging, change INFO to DEBUG for a *lot* more information
logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
_LOGGER = logging.getLogger('pyaarlo')

# log in
# add `verbose_debug=True` to enable even more debugging
# add `dump=True` to enable event stream packet dumps
arlo = pyaarlo.PyArlo(username=USERNAME, password=PASSWORD,
                      tfa_type='EMAIL', tfa_source='console', synchronous_mode=True,
                      save_session=True,
                      save_state=False, dump=True, storage_dir='aarlo', verbose_debug=True)
if not arlo.is_connected:
    print("failed to login({})".format(arlo._last_error))
    sys.exit(-1)

print('list bases')
for base in arlo.base_stations:
    print("base: name={},device_id={},state={}".format(base.name, base.device_id, base.state))
    pprint.pprint(base.available_modes)
    pprint.pprint(base.available_modes_with_ids)

print('list cameras')
for camera in arlo.cameras:
    print("camera: name={},device_id={},state={}".format(camera.name, camera.device_id, camera.state))
    for video in camera.last_n_videos(5):
        print("url {} ".format(video.video_url))

print('list doorbells')
for doorbell in arlo.doorbells:
    print("doorbell: name={},device_id={},state={}".format(doorbell.name, doorbell.device_id, doorbell.state))

print('list lights')
for light in arlo.lights:
    print("light: name={},device_id={},state={}".format(light.name, light.device_id, light.state))

time.sleep(15)
