|
5 | 5 | from six.moves.urllib_parse import urlparse |
6 | 6 |
|
7 | 7 | from . import discovery |
8 | | -from .util import deserialize_apps |
| 8 | +from .util import deserialize_apps, deserialize_channels |
9 | 9 |
|
10 | 10 | try: |
11 | 11 | from urllib.parse import quote_plus |
@@ -103,6 +103,27 @@ def store(self): |
103 | 103 | self.roku.store(self) |
104 | 104 |
|
105 | 105 |
|
| 106 | +class Channel(object): |
| 107 | + |
| 108 | + def __init__(self, number, name, roku=None): |
| 109 | + self.number = str(number) |
| 110 | + self.name = name |
| 111 | + self.roku = roku |
| 112 | + |
| 113 | + def __eq__(self, other): |
| 114 | + return isinstance(other, Channel) and \ |
| 115 | + (self.number, self.name) == (other.number, other.name) |
| 116 | + |
| 117 | + def __repr__(self): |
| 118 | + return ('<Channel: [%s] %s>' % |
| 119 | + (self.number, self.name)) |
| 120 | + |
| 121 | + def launch(self): |
| 122 | + if self.roku: |
| 123 | + tv_app = Application(id= 'tvinput.dtv', version=None, name='TV', roku=self.roku) |
| 124 | + self.roku.launch(tv_app, {'ch': self.number}) |
| 125 | + |
| 126 | + |
106 | 127 | class DeviceInfo(object): |
107 | 128 |
|
108 | 129 | def __init__(self, model_name, model_num, software_version, serial_num, user_device_name, roku_type): |
@@ -226,6 +247,14 @@ def active_app(self): |
226 | 247 | else: |
227 | 248 | return None |
228 | 249 |
|
| 250 | + @property |
| 251 | + def tv_channels(self): |
| 252 | + resp = self._get('/query/tv-channels') |
| 253 | + channels = deserialize_channels(resp) |
| 254 | + for c in channels: |
| 255 | + c.roku = self |
| 256 | + return channels |
| 257 | + |
229 | 258 | @property |
230 | 259 | def device_info(self): |
231 | 260 | resp = self._get('/query/device-info') |
@@ -269,10 +298,11 @@ def power_state(self): |
269 | 298 | def icon(self, app): |
270 | 299 | return self._get('/query/icon/%s' % app.id) |
271 | 300 |
|
272 | | - def launch(self, app): |
| 301 | + def launch(self, app, params={}): |
273 | 302 | if app.roku and app.roku != self: |
274 | 303 | raise RokuException('this app belongs to another Roku') |
275 | | - return self._post('/launch/%s' % app.id, params={'contentID': app.id}) |
| 304 | + params['contentID'] = app.id |
| 305 | + return self._post('/launch/%s' % app.id, params=params) |
276 | 306 |
|
277 | 307 | def store(self, app): |
278 | 308 | return self._post('/launch/11', params={'contentID': app.id}) |
|
0 commit comments