Skip to content
This repository has been archived by the owner on Mar 6, 2025. It is now read-only.

Commit

Permalink
Fix issue where the session got closed when using multiple methods in…
Browse files Browse the repository at this point in the history
… the same session (#41)

* test

* version bump

* test

* indents

* linting
  • Loading branch information
ludeeus authored Dec 25, 2018
1 parent 57c2e6e commit 8394772
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 50 deletions.
14 changes: 6 additions & 8 deletions googledevices/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,13 @@ async def gdh_request(host, port=None, endpoint=None, json=True,
try:
async with async_timeout.timeout(8, loop=loop):
if method == 'post':
async with session as session:
webrequest = await session.post(url, json=json_data,
data=data, params=params,
headers=headers)
webrequest = await session.post(url, json=json_data,
data=data, params=params,
headers=headers)
else:
async with session as session:
webrequest = await session.get(url, json=json_data,
data=data, params=params,
headers=headers)
webrequest = await session.get(url, json=json_data,
data=data, params=params,
headers=headers)
if json:
result = await webrequest.json()
else:
Expand Down
2 changes: 1 addition & 1 deletion googledevices/utils/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
###############################################################################
# Setup information
###############################################################################
VERSION = '1.0.0'
VERSION = '1.0.1'
NAME = 'googledevices'
DESCRIPTION = 'Get information from, and control various Google devices.'
URLS = {
Expand Down
76 changes: 35 additions & 41 deletions googledevices/utils/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,188 +20,182 @@ async def test_all(): # pylint: disable=R0915
test_class = await Cast(TEST_HOST_CAST, LOOP, session).assistant()
test = await test_class.get_alarms()
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Assistant - set_alarm_volume")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).assistant()
test = await test_class.set_alarm_volume(0.6)
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Assistant - get_alarm_volume")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).assistant()
test = await test_class.get_alarm_volume()
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Assistant - set_night_mode_params")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).assistant()
data = {}
test = await test_class.set_night_mode_params(data)
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Assistant - notifications_enabled")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).assistant()
test = await test_class.notifications_enabled()
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Assistant - set_accessibility")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).assistant()
test = await test_class.set_accessibility()
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Assistant - delete_alarms")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).assistant()
data = []
test = await test_class.delete_alarms(data)
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Assistant - set_equalizer")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).assistant()
test = await test_class.set_equalizer()
print(format_json(test))

print("Testing Cast - Bluetooth.")
print("Testing Cast - Bluetooth.")

async with gdh_session() as session:
print("Testing Cast - Bluetooth - get_bluetooth_status")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).bluetooth()
test = await test_class.get_bluetooth_status()
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Bluetooth - set_discovery_enabled")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).bluetooth()
test = await test_class.set_discovery_enabled()
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Bluetooth - scan_for_devices")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).bluetooth()
test = await test_class.scan_for_devices()
print(format_json(test))
async with gdh_session():

await gdh_sleep(2)
async with gdh_session() as session:

print("Testing Cast - Bluetooth - get_scan_result")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).bluetooth()
test = await test_class.get_scan_result()
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Bluetooth - get_paired_devices")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).bluetooth()
test = await test_class.get_paired_devices()
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Bluetooth - pair_with_mac")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).bluetooth()
test = await test_class.pair_with_mac("AA:BB:CC:DD:EE:FF")
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Bluetooth - forget_paired_device")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).bluetooth()
test = await test_class.forget_paired_device("AA:BB:CC:DD:EE:FF")
print(format_json(test))

print("Testing Cast - Info.")
print("Testing Cast - Info.")

async with gdh_session() as session:
print("Testing Cast - Info - get_device_info")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).info()
test = await test_class.get_device_info()
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Info - get_offer")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).info()
test = await test_class.get_offer()
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Info - get_timezones")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).info()
test = await test_class.get_timezones()
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Info - get_locales")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).info()
test = await test_class.get_locales()
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Info - speedtest")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).info()
test = await test_class.speedtest()
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Info - get_app_device_id")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).info()
test = await test_class.get_app_device_id()
print(format_json(test))

print("Testing Cast - Wifi.")
print("Testing Cast - Wifi.")

async with gdh_session() as session:
print("Testing Cast - Wifi - get_configured_networks")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).wifi()
test = await test_class.get_configured_networks()
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Wifi - scan_for_wifi")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).wifi()
test = await test_class.scan_for_wifi()
print(format_json(test))
async with gdh_session():

await gdh_sleep(2)
async with gdh_session() as session:

print("Testing Cast - Wifi - get_wifi_scan_result")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).wifi()
test = await test_class.get_wifi_scan_result()
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Wifi - forget_network")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).wifi()
test = await test_class.forget_network(9)
print(format_json(test))

print("Testing Cast - Settings.")
print("Testing Cast - Settings.")

async with gdh_session() as session:
print("Testing Cast - Settings - control_notifications")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).settings()
test = await test_class.control_notifications(True)
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Settings - set_eureka_info")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).settings()
data = {"settings": {"control_notifications": 2}}
test = await test_class.set_eureka_info(data)
print(format_json(test))
async with gdh_session() as session:

print("Testing Cast - Settings - reboot")
test_class = await Cast(TEST_HOST_CAST, LOOP, session).settings()
test = await test_class.reboot()
print(format_json(test))

print("Testing WiFi.")
print("Testing WiFi.")

print("Testing WiFi - Info.")
print("Testing WiFi - Info.")

async with gdh_session() as session:
print("Testing WiFi - Info - get_host")
test_class = await Wifi(TEST_HOST_WIFI, LOOP, session).info()
test = await test_class.get_host()
print(format_json(test))
async with gdh_session() as session:

print("Testing WiFi - Info - get_host - with host not defined.")
test_class = await Wifi(loop=LOOP, session=session).info()
test = await test_class.get_host()
print(format_json(test))
async with gdh_session() as session:

print("Testing WiFi - Info - get_wifi_info")
test_class = await Wifi(TEST_HOST_WIFI, LOOP, session).info()
test = await test_class.get_wifi_info()
print(format_json(test))

print("Testing WiFi - Clients.")
print("Testing WiFi - Clients.")

async with gdh_session() as session:
print("Testing WiFi - Clients - get_clients")
test_class = await Wifi(TEST_HOST_WIFI, LOOP, session).clients()
test = await test_class.get_clients()
print(format_json(test))

print("TESTS COMPLETE.")
print("TESTS COMPLETE.")
LOOP.run_until_complete(test_all())

0 comments on commit 8394772

Please sign in to comment.