Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

AttributeError: 'Chromecast' object has no attribute 'cast_info' #18

Open
kenhys opened this issue Mar 9, 2022 · 0 comments
Open

AttributeError: 'Chromecast' object has no attribute 'cast_info' #18

kenhys opened this issue Mar 9, 2022 · 0 comments

Comments

@kenhys
Copy link

kenhys commented Mar 9, 2022

Problem

When try to launch main.py, it causes AttributeError: 'Chromecast' object has no attribute 'cast_info'

Actual

Startup fails.

INFO:root:Starting up chromecasts
INFO:pychromecast:Querying device status
INFO:root:Searching for ghm
Traceback (most recent call last):
  File "/home/gh-notifier/google-home-notifier-python/main.py", line 19, in <module>
    cast = next(cc for cc in chromecasts if cc.cast_info.friendly_name == chromecast_name)
  File "/home/gh-notifier/google-home-notifier-python/main.py", line 19, in <genexpr>
    cast = next(cc for cc in chromecasts if cc.cast_info.friendly_name == chromecast_name)
AttributeError: 'Chromecast' object has no attribute 'cast_info'

Expected

python main.py launches successfully.

Additional information

I'm using it with Google Home Mini.

$ pip list
Package            Version
------------------ ---------
casttube           0.2.1
certifi            2021.5.30
charset-normalizer 2.0.4
click              8.0.1
Flask              2.0.1
gTTS               2.2.3
idna               3.2
ifaddr             0.1.7
itsdangerous       2.0.1
Jinja2             3.0.1
MarkupSafe         2.0.1
pathlib            1.0.1
pip                21.1.3
protobuf           3.17.3
PyChromecast       9.2.0
requests           2.26.0
setuptools         56.0.0
six                1.16.0
unicode-slugify    0.1.3
Unidecode          1.2.0
urllib3            1.26.6
Werkzeug           2.0.1
zeroconf           0.36.0
WARNING: You are using pip version 21.1.3; however, version 22.0.4 is available

With debugging, it seems there is a case that cast_info property can not be accessible.

>>> print(chromecasts)
[Chromecast(None, port=8009, device=DeviceStatus(friendly_name='ghm', model_name='Google Home Mini', manufacturer='Google Inc.', uuid=UUID('...'), cast_type='audio'))]
>>> cast = chromecasts[0]
>>> cast
Chromecast(None, port=8009, device=DeviceStatus(friendly_name='ghm', model_name='Google Home Mini', manufacturer='Google Inc.', uuid=UUID('...'), cast_type='audio'))

cast. doesn't show cast_info.

>>> cast.
cast.app_display_name                 cast.model_name                       cast.socket_client
cast.app_id                           cast.name                             cast.start(
cast.cast_type                        cast.new_cast_status(                 cast.start_app(
cast.connect(                         cast.play_media(                      cast.status
cast.device                           cast.quit_app(                        cast.status_event
cast.disconnect(                      cast.register_connection_listener(    cast.uri
cast.ignore_cec                       cast.register_handler(                cast.uuid
cast.is_idle                          cast.register_launch_error_listener(  cast.volume_down(
cast.join(                            cast.register_status_listener(        cast.volume_up(
cast.logger                           cast.set_volume(                      cast.wait(
cast.media_controller                 cast.set_volume_muted(                

I've used cast.name as a workaround.

$ git diff
diff --git a/main.py b/main.py
index 3fde0a2..2e55441 100644
--- a/main.py
+++ b/main.py
@@ -16,7 +16,7 @@ app = Flask(__name__)
 logging.info("Starting up chromecasts")
 chromecasts, _ = pychromecast.get_chromecasts()
 logging.info("Searching for {}".format(chromecast_name))
-cast = next(cc for cc in chromecasts if cc.cast_info.friendly_name == chromecast_name)
+cast = next(cc for cc in chromecasts if cc.name == chromecast_name)
 
 def play_tts(text, lang='en', slow=False):
     tts = gTTS(text=text, lang=lang, slow=slow)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant