implemented alarm and network device methods
This commit is contained in:
parent
b95ca24f28
commit
08a07800dc
9
alarm.py
Normal file
9
alarm.py
Normal file
@ -0,0 +1,9 @@
|
||||
import spotframework.net.user as userclass
|
||||
import spotframework.net.network as networkclass
|
||||
|
||||
import os
|
||||
|
||||
if __name__ == '__main__':
|
||||
network = networkclass.network(userclass.User())
|
||||
|
||||
network.play(os.environ['SPOTALARMURI'], network.getDeviceID(os.environ['SPOTALARMDEVICENAME']))
|
@ -93,18 +93,44 @@ class network:
|
||||
else:
|
||||
raise ValueError("Couldn't Pull Playlist " + str(playlistid) + ' ' + str(req.status_code))
|
||||
|
||||
def getAvailableDevices(self):
|
||||
|
||||
headers = {'Authorization': 'Bearer ' + self.user.access_token}
|
||||
|
||||
req = requests.get(const.api_url + 'me/player/devices', headers=headers)
|
||||
|
||||
if req.status_code == 200:
|
||||
return req.json()
|
||||
else:
|
||||
return None
|
||||
|
||||
def getPlayer(self):
|
||||
|
||||
headers = {'Authorization': 'Bearer ' + self.user.access_token}
|
||||
|
||||
req = requests.get(const.api_url + 'me/player', headers=headers)
|
||||
|
||||
print(req.status_code)
|
||||
print(req.text)
|
||||
if req.status_code == 200:
|
||||
return req.json()
|
||||
else:
|
||||
return None
|
||||
|
||||
def play(self, context, contexttype, deviceid=None):
|
||||
def getDeviceID(self, devicename):
|
||||
|
||||
return next((i for i in self.getAvailableDevices()['devices'] if i['name'] == devicename), None)['id']
|
||||
|
||||
def play(self, uri, deviceid=None):
|
||||
|
||||
headers = {'Authorization': 'Bearer ' + self.user.access_token}
|
||||
|
||||
params = {'limit': limit}
|
||||
req = requests.put(const.api_url + 'me/player/play', params=params, headers=headers)
|
||||
if deviceid is not None:
|
||||
params = {'device_id': deviceid}
|
||||
else:
|
||||
params = None
|
||||
|
||||
payload = {'context_uri': uri}
|
||||
|
||||
req = requests.put(const.api_url + 'me/player/play', params=params, json=payload, headers=headers)
|
||||
|
||||
print(req.status_code)
|
||||
print(req.text)
|
||||
|
Loading…
Reference in New Issue
Block a user