Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing classes and methods #37

Merged
merged 31 commits into from
Dec 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 0 additions & 64 deletions googledevices/api/cast/alarm.py

This file was deleted.

124 changes: 124 additions & 0 deletions googledevices/api/cast/assistant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
"""Controll Assistant settings on the unit."""
from googledevices.utils.const import CASTPORT, HEADERS
from googledevices.helpers import gdh_request
import googledevices.utils.log as log


class Assistant(object):
"""A class for Assistant settings."""

def __init__(self, host, loop, session):
"""Initialize the class."""
self.host = host
self.loop = loop
self.session = session
self._alarms = []
self._alarmvolume = None

async def set_night_mode_params(self, data):
"""Set night mode options."""
endpoint = 'setup/assistant/set_night_mode_params'
result = await gdh_request(host=self.host, port=CASTPORT,
endpoint=endpoint, method='post',
loop=self.loop, session=self.session,
json_data=data, headers=HEADERS)
return result

async def notifications_enabled(self, mode=True):
"""Set notifications_enabled True/False."""
endpoint = 'setup/assistant/notifications'
data = {"notifications_enabled": mode}
result = await gdh_request(host=self.host, port=CASTPORT,
endpoint=endpoint, method='post',
loop=self.loop, session=self.session,
json_data=data, headers=HEADERS)
return result

async def set_accessibility(self, start=True, end=False):
"""Set accessibility True/False."""
endpoint = 'setup/assistant/a11y_mode'
data = {"endpoint_enabled": end, "hotword_enabled": start}
result = await gdh_request(host=self.host, port=CASTPORT,
endpoint=endpoint, method='post',
loop=self.loop, session=self.session,
json_data=data, headers=HEADERS)
return result

async def delete_alarms(self, data):
"""Delete active alarms and timers."""
endpoint = 'setup/assistant/alarms/delete'
result = await gdh_request(host=self.host, port=CASTPORT,
endpoint=endpoint, method='post',
loop=self.loop, session=self.session,
json_data=data, headers=HEADERS)
return result

async def set_equalizer(self, low_gain=0, high_gain=0):
"""Set equalizer db gain."""
endpoint = 'setup/user_eq/set_equalizer'
returnvalue = False
data = {
"low_shelf": {"gain_db": low_gain},
"high_shelf": {"gain_db": high_gain}
}
result = await gdh_request(host=self.host, port=CASTPORT,
endpoint=endpoint, method='post',
loop=self.loop, session=self.session,
json_data=data, headers=HEADERS,
json=False)
try:
if result.status == 200:
returnvalue = True
except AttributeError:
msg = "Error connecting to - {}".format(self.host)
log.error(msg)
return returnvalue

async def get_alarms(self):
"""Get the alarms from the device."""
endpoint = 'setup/assistant/alarms'
response = await gdh_request(host=self.host, port=CASTPORT,
loop=self.loop, session=self.session,
endpoint=endpoint, headers=HEADERS)
self._alarms = response
log.debug(self._alarms)
return self._alarms

async def get_alarm_volume(self):
"""Get the alarm volume for the device."""
endpoint = 'setup/assistant/alarms/volume'
response = await gdh_request(host=self.host, port=CASTPORT,
loop=self.loop, session=self.session,
endpoint=endpoint, headers=HEADERS,
method='post')
self._alarmvolume = response
log.debug(self._alarmvolume)
return self._alarmvolume

async def set_alarm_volume(self, volume):
"""Set the alarm volume for the device."""
data = {'volume': volume}
endpoint = 'setup/assistant/alarms/volume'
returnvalue = False
result = await gdh_request(host=self.host, port=CASTPORT,
endpoint=endpoint, method='post',
loop=self.loop, session=self.session,
json_data=data, headers=HEADERS,
json=False)
try:
if result.status == 200:
returnvalue = True
except AttributeError:
msg = "Error connecting to - {}".format(self.host)
log.error(msg)
return returnvalue

@property
def alarms(self):
"""Return the alarms."""
return self._alarms

@property
def alarm_volume(self):
"""Return the alarm volume."""
return self._alarmvolume
58 changes: 55 additions & 3 deletions googledevices/api/cast/bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,47 @@ def __init__(self, host, loop, session):
self.host = host
self.session = session
self._devices = []
self._paired_devices = []
self._status = {}

async def get_bluetooth_status(self):
"""Get the bluetooth status of the device."""
endpoint = 'setup/bluetooth/status'
response = await gdh_request(host=self.host, port=CASTPORT,
loop=self.loop, session=self.session,
endpoint=endpoint)
endpoint=endpoint, headers=HEADERS)
self._status = response
log.debug(self._status)
return self._status

async def get_paired_devices(self):
"""Get paired devices."""
endpoint = 'setup/bluetooth/get_bonded'
response = await gdh_request(host=self.host, port=CASTPORT,
loop=self.loop, session=self.session,
endpoint=endpoint, headers=HEADERS)
self._status = response
log.debug(self._status)
return self._status

async def forget_paired_device(self, mac_address):
"""Forget a paired device."""
endpoint = 'setup/bluetooth/bond'
data = {"bond": False, "mac_address": mac_address}
returnvalue = False
result = await gdh_request(host=self.host, port=CASTPORT,
endpoint=endpoint, method='post',
loop=self.loop, session=self.session,
json_data=data, headers=HEADERS,
json=False)
try:
if result.status == 200:
returnvalue = True
except AttributeError:
msg = "Error connecting to - {}".format(self.host)
log.error(msg)
return returnvalue

async def set_discovery_enabled(self):
"""Enable bluetooth discoverablility."""
endpoint = 'setup/bluetooth/discovery'
Expand All @@ -43,6 +72,24 @@ async def set_discovery_enabled(self):
log.error(msg)
return returnvalue

async def pair_with_mac(self, mac_address):
"""Pair with bluetooth device."""
endpoint = 'setup/bluetooth/scan'
data = {"connect": True, "mac_address": mac_address, "profile": 2}
returnvalue = False
result = await gdh_request(host=self.host, port=CASTPORT,
endpoint=endpoint, method='post',
loop=self.loop, session=self.session,
json_data=data, headers=HEADERS,
json=False)
try:
if result.status == 200:
returnvalue = True
except AttributeError:
msg = "Error connecting to - {}".format(self.host)
log.error(msg)
return returnvalue

async def scan_for_devices(self):
"""Scan for bluetooth devices."""
endpoint = 'setup/bluetooth/scan'
Expand All @@ -66,7 +113,7 @@ async def get_scan_result(self):
endpoint = 'setup/bluetooth/scan_results'
response = await gdh_request(host=self.host, port=CASTPORT,
loop=self.loop, session=self.session,
endpoint=endpoint)
endpoint=endpoint, headers=HEADERS)
self._devices = response
log.debug(self._devices)
return self._devices
Expand All @@ -78,5 +125,10 @@ def status(self):

@property
def devices(self):
"""Return the device info if any."""
"""Return the devices if any."""
return self._devices

@property
def paired_devices(self):
"""Return paired devices if any."""
return self._paired_devices
84 changes: 80 additions & 4 deletions googledevices/api/cast/info.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Get device information for the unit."""
from googledevices.utils.const import DEFAULT_DEVICE_NAME, CASTPORT
from googledevices.utils.const import DEFAULT_DEVICE_NAME, CASTPORT, HEADERS
import googledevices.utils.log as log
from googledevices.helpers import gdh_request


class Info(object):
class Info(object): # pylint: disable=R0902
"""A class for device info."""

def __init__(self, host, loop, session):
Expand All @@ -14,20 +14,96 @@ def __init__(self, host, loop, session):
self.session = session
self._name = 'GoogleDevice'
self._device_info = {}
self._offer = {}
self._timezones = []
self._locales = []
self._app_device_id = {}

async def get_device_info(self):
"""Get device information for the unit.."""
"""Get device information for the unit."""
endpoint = 'setup/eureka_info'
params = ("params=version,audio,name,build_info,detail,device_info,"
"net,wifi,setup,settings,opt_in,opencast,multizone,proxy,"
"night_mode_params,user_eq,room_equalizer&options=detail")
response = await gdh_request(host=self.host, port=CASTPORT,
loop=self.loop, session=self.session,
endpoint=endpoint, params=params)
endpoint=endpoint, params=params,
headers=HEADERS)
self._device_info = response
log.debug(self._device_info)
return self._device_info

async def get_offer(self):
"""Get offer token."""
endpoint = 'setup/offer'
response = await gdh_request(host=self.host, port=CASTPORT,
loop=self.loop, session=self.session,
endpoint=endpoint, headers=HEADERS)
self._offer = response
log.debug(self._offer)
return self._offer

async def get_timezones(self):
"""Get supported timezones."""
endpoint = 'setup/supported_timezones'
response = await gdh_request(host=self.host, port=CASTPORT,
loop=self.loop, session=self.session,
endpoint=endpoint, headers=HEADERS)
self._timezones = response
log.debug(self._timezones)
return self._timezones

async def get_locales(self):
"""Get supported locales."""
endpoint = 'setup/supported_locales'
response = await gdh_request(host=self.host, port=CASTPORT,
loop=self.loop, session=self.session,
endpoint=endpoint, headers=HEADERS)
self._locales = response
log.debug(self._locales)
return self._locales

async def speedtest(self):
"""Run speedtest."""
endpoint = 'setup/test_internet_download_speed'
url = "https://storage.googleapis.com/reliability-speedtest/random.txt"
data = {"url": url}
result = await gdh_request(host=self.host, port=CASTPORT,
endpoint=endpoint, method='post',
loop=self.loop, session=self.session,
json_data=data, headers=HEADERS)
return result

async def get_app_device_id(self):
"""Run speedtest."""
endpoint = 'setup/get_app_device_id'
data = {"app_id": "E8C28D3C"}
result = await gdh_request(host=self.host, port=CASTPORT,
endpoint=endpoint, method='post',
loop=self.loop, session=self.session,
json_data=data, headers=HEADERS)
return result

@property
def offer(self):
"""Return the offer token."""
return self._offer

@property
def timezones(self):
"""Return supported timezones."""
return self._timezones

@property
def locales(self):
"""Return supported timezones."""
return self._locales

@property
def app_device_id(self):
"""Return app_device_id."""
return self._app_device_id

@property
def device_info(self):
"""Return the device info if any."""
Expand Down
Loading