Skip to content

Commit

Permalink
fix(bluetooth): check for valid response from get_bluetooth
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Aug 30, 2019
1 parent 9032c00 commit b1422c4
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions custom_components/alexa_media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,12 @@ async def update_bluetooth_state(login_obj, device_serial):
['media_player']
[device_serial])

for b_state in bluetooth['bluetoothStates']:
if device_serial == b_state['deviceSerialNumber']:
device['bluetooth_state'] = b_state
return device['bluetooth_state']
if 'bluetoothStates' in bluetooth:
for b_state in bluetooth['bluetoothStates']:
if device_serial == b_state['deviceSerialNumber']:
device['bluetooth_state'] = b_state
return device['bluetooth_state']
return None

async def last_call_handler(call):
"""Handle last call service request.
Expand Down Expand Up @@ -588,10 +590,11 @@ async def ws_handler(message_obj):
json_payload)
bluetooth_state = await update_bluetooth_state(login_obj,
serial)
hass.bus.async_fire(
('{}_{}'.format(DOMAIN,
hide_email(email)))[0:32],
{'bluetooth_change': bluetooth_state})
if bluetooth_state:
hass.bus.async_fire(
('{}_{}'.format(DOMAIN,
hide_email(email)))[0:32],
{'bluetooth_change': bluetooth_state})
elif command == 'PUSH_MEDIA_QUEUE_CHANGE':
# Player availability update
serial = (json_payload['dopplerId']['deviceSerialNumber'])
Expand Down

0 comments on commit b1422c4

Please sign in to comment.