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

Support newer versions of pychromecast #32

Merged
merged 2 commits into from Dec 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions mkchromecast/cast.py
Expand Up @@ -88,14 +88,29 @@ def netifaces_ip(self):
if self.debug == True:
print(':::cast::: netifaces method', self.discovered_ip)

def _get_chromecasts(self):
# compatibility
try:
return list(pychromecast.get_chromecasts_as_dict().keys())
except AttributeError:
self._chromecasts_by_name = {c.name: c for c in pychromecast.get_chromecasts()}
return list(self._chromecasts_by_name.keys())

def _get_chromecast(self, name):
# compatibility
try:
return pychromecast.get_chromecast(friendly_name=self.castto)
except AttributeError:
return self._chromecasts_by_name[name]

"""
Cast processes
"""
def initialize_cast(self):
import mkchromecast.__init__ # This is to verify against some needed variables.
from pychromecast import socket_client # This fixes the `No handlers could be found for logger "pychromecast.socket_client` warning"`.
# See commit 18005ebd4c96faccd69757bf3d126eb145687e0d.
self.cclist = list(pychromecast.get_chromecasts_as_dict().keys())
self.cclist = self._get_chromecasts()
if self.debug == True:
print('self.cclist', self.cclist)

Expand Down Expand Up @@ -234,7 +249,7 @@ def get_cc(self):
try:
if self.ccname != None:
self.castto = self.ccname
self.cast = pychromecast.get_chromecast(friendly_name=self.castto)
self.cast = self._get_chromecast(self.castto)
# Wait for cast device to be ready
self.cast.wait()
print(' ')
Expand Down