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

KeyError: 'bluetoothStates' #293

Closed
eifinger opened this issue Aug 21, 2019 · 10 comments · Fixed by #296
Closed

KeyError: 'bluetoothStates' #293

eifinger opened this issue Aug 21, 2019 · 10 comments · Fixed by #296

Comments

@eifinger
Copy link

Describe the bug
Error messages show up in log and no alexa devices are registered in homeassistant.

To Reproduce

  1. Start homeassistant with alexa_media added

Expected behavior
Alexa Devices should show in homeassistant

Screenshots
N/A

System details

  • Home-assistant (version): 0.96.5
  • Hassio (Yes/No): No
  • alexa_media (version from const.py or HA startup): 1.4.1 (HACS)
  • alexapy (version from pip show alexapy or HA startup): 0.7.1

Additional context

Configuration:

alexa_media:
  accounts:
    - email: !secret amazon_email
      password: !secret amazon_password
      url: amazon.de

notify:
  - platform: alexa_media
    name: alexa_media

Error messages:

Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/alexa_media/__init__.py", line 639, in setup_alexa
    update_devices()
  File "/usr/src/app/homeassistant/util/__init__.py", line 224, in wrapper
    result = method(*args, **kwargs)
  File "/usr/src/app/homeassistant/util/__init__.py", line 224, in wrapper
    result = method(*args, **kwargs)
  File "/config/custom_components/alexa_media/__init__.py", line 346, in update_devices
    for b_state in bluetooth['bluetoothStates']:
KeyError: 'bluetoothStates'
error from callback <bound method WebsocketEchoClient.on_message of <WebsocketEchoClient(Thread-3, started daemon 140100893669120)>>: 'bluetoothStates'
@wendlm
Copy link

wendlm commented Aug 21, 2019

I encounter the same problem - Alexa TTS not working anymore

@brama1966
Copy link

yeap its broken
and i was just enjoying the 27 different voices telling my wife the washing machine has finished.
although if you want the WAF forget all the male ones, seems that no woman likes to be told by a man that her washing has finished.

@alandtse
Copy link
Owner

Does renaming the .pickle file and relogging in help?

@noahajac
Copy link

@alandtse I'm having the same issue. I've removed the pickle file and restarted HA multiple times. Logging in seems to be an issue as well. I go to send either a captcha, 2FA code, etc and sometimes it will fail with the error above.

@brama1966
Copy link

Well i just fixed mine for now

I had to comment out all bluetooth and b_state sections in init.py and media_player.py

i did also delete the pickle file and reconfirm the login
don't know if i need to do that.

But for now its working all my mini_media_players are back.

The only echo i have connected to bluetooth speakers is in the shower and you have to turn those speakers on since they run on batteries (Sony SRS--XB10). so i'm never going to select local speaker or bluetooth as an output in HA.

Now Han's go and tell my wife the washing machine has finished quick smart!

media_player.py
lines 181 -188
 #      elif 'bluetooth_change' in event.data:
  #          if (event.data['bluetooth_change']['deviceSerialNumber'] ==
  #                  self.device_serial_number):
  #              self._bluetooth_state = event.data['bluetooth_change']
 #               self._source = self._get_source()
 #               self._source_list = self._get_source_list()
 #               if (self.hass and self.schedule_update_ha_state):
  #                  self.schedule_update_ha_state()

line 277
         #   self._bluetooth_state = device['bluetooth_state']
line 362 - 369
    def select_source(self, source):
        """Select input source."""
        #if source == 'Local Speaker':
        #    self.alexa_api.disconnect_bluetooth()
        self._source = 'Local Speaker'                       move indent back Line 364 
      #  elif self._bluetooth_state['pairedDeviceList'] is not None:
       #     for devices in self._bluetooth_state['pairedDeviceList']:
      #          if devices['friendlyName'] == source:
       #             self.alexa_api.set_bluetooth(devices['address'])
       #             self._source = source 

 line 381 - 385
    def _get_source(self):
        source = 'Local Speaker'
    #    if self._bluetooth_state['pairedDeviceList'] is not None:
     #       for device in self._bluetooth_state['pairedDeviceList']:
      #          if device['connected'] is True:
       #             return device['friendlyName']
        return source

    def _get_source_list(self):
        sources = []
    #    if self._bluetooth_state['pairedDeviceList'] is not None:
     #       for devices in self._bluetooth_state['pairedDeviceList']:
      #          if (devices['profiles'] and
       #                 'A2DP-SOURCE' in devices['profiles']):
        #            sources.append(devices['friendlyName'])


__init__.py
lines 346 - 348
        #    for b_state in bluetooth['bluetoothStates']:
         #       if device['serialNumber'] == b_state['deviceSerialNumber']:
        #            device['bluetooth_state'] = b_state

Lines 420 -434
 #  def update_bluetooth_state(login_obj, device_serial):
  #      """Update the bluetooth state on ws bluetooth event."""
  #      from alexapy import AlexaAPI
  #      bluetooth = AlexaAPI.get_bluetooth(login_obj)
#        device = (hass.data[DATA_ALEXAMEDIA]
 #                 ['accounts']
  #                [email]
   #               ['devices']
    #              ['media_player']
     #             [device_serial])

Lines 540- 549
#        for b_state in bluetooth['bluetoothStates']:
#            if device_serial == b_state['deviceSerialNumber']:
 #               device['bluetooth_state'] = b_state
 #       return device['bluetooth_state']

      #      elif command == 'PUSH_BLUETOOTH_STATE_CHANGE':
                # Player bluetooth update
      #          serial = (json_payload['dopplerId']['deviceSerialNumber'])
      #          if (serial and serial in existing_serials):
      #              _LOGGER.debug("Updating media_player bluetooth %s",
      #                            json_payload)
      #              bluetooth_state = update_bluetooth_state(login_obj, serial)
      #              hass.bus.fire(('{}_{}'.format(DOMAIN,
      #                                           hide_email(email)))[0:32],
       #                           {'bluetooth_change': bluetooth_state})

@brama1966
Copy link

Well I remove what i did and restared HA and there all still there
so maybe it was the pickle file and i need to reconfirm the login

@glassbase
Copy link

glassbase commented Aug 22, 2019

I wonder if other issues. I don’t get the Bluetooth error message / log but my announcements aren’t working tonight. Think it worked fine yesterday.

Did the usual delete pickle file and restart, took many attempts to solve captcha before it went away. Did the pickle file delete and setup multiple times. Still no announcements here (all Echo devices, no third party). No changes for me in awhile.

@matteos1
Copy link

also for me. no echo media player till yesterday

@noahajac
Copy link

noahajac commented Aug 22, 2019

Just tried @brama1966's solution and it worked. Thanks!

Of course it's still a bug but at least now there is a workaround.

@matteos1
Copy link

without deleting the file, the echo devices now work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants