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

No camera show's up #90

Closed
dgomes opened this issue Oct 10, 2018 · 17 comments · Fixed by #97
Closed

No camera show's up #90

dgomes opened this issue Oct 10, 2018 · 17 comments · Fixed by #97
Labels
bug There is an issue causing unexpected results help-wanted Assistance required due to lack of resources for testing or complexity

Comments

@dgomes
Copy link

dgomes commented Oct 10, 2018

from blinkpy import blinkpy

blink = blinkpy.Blink(username='XXXX@gmail.com', password='XXXX')
blink.start()

for name, camera in blink.sync.cameras.items():
    print(name)                   # Name of the camera
    print(camera.attributes)      # Print available attributes of camera

This code doesn't show up any camera.

Cameras do show up in the app

@dgomes
Copy link
Author

dgomes commented Oct 10, 2018

This is a follow up of home-assistant/core#17316 (comment)

@dgomes
Copy link
Author

dgomes commented Oct 10, 2018

The cameras are linked, else the app wouldn't work. right ?

@fronzbot
Copy link
Owner

fronzbot commented Oct 10, 2018

Yeah, if you see them in the app, you should see them with the API. I cannot reproduce this issue, and I know of a few people who have tested the recent version and have not run into this issue, which is why I'm perplexed.

A few questions:

  1. How many sync modules do you have?

  2. What is the output of blink.region_id

  3. What is the output of blink.sync.online

  4. Does blink.events return anything (it should be a big ass dictionary of info)?

EDIT:

Also, does the output of blink._auth_header look like {'Host': 'xxxx.immedia-semi.com', 'TOKEN_AUTH': 'bunchoflettersandnumbers'}?

@dgomes
Copy link
Author

dgomes commented Oct 10, 2018

  1. Only one sync module with 3 cameras

  2. prde

  3. ERROR
    File "/Users/dgomes/Projects/home-assistant/lib/python3.6/site-packages/blinkpy/sync_module.py", line 79, in online
    return ONLINE[self._status_request()['syncmodule']['status']]
    TypeError: list indices must be integers or slices, not str

  4. {'event': []}

@fronzbot
Copy link
Owner

So there's a communication error with the Blink servers then. To see if it's persisting, run blink.refresh(force_cache=True) and then check the output of blink.events again. If it's empty, something weird is happening.

@fronzbot
Copy link
Owner

Hmm, real quick, try the following:
blink.sync.get_cameras()
and see if they show up.

If they don't... my only guess is Blink has changed how non-US based cameras access their servers. You could try accessing the US servers to see if it works (though it's a bit of a manual process):

import json
headers = {'Host': blinkpy.DEFAULT_URL, 'Content-Type': 'application/json'}
data = json.dumps({"email": blink._username, "password": blink._password, "client_specifier": "iPhone 9.2 | 2.2 | 222"})
blink.region_id = 'prod'
blink._host = 'prod' + blinkpy.BLINK_URL
resp = blinkpy.http_req(blink, url=blinkpy.LOGIN_URL, headers=headers, data=data, reqtype='post')
blink._token = resp['authtoken']['authtoken']
blink._auth_header = {'Host': blink._host, 'TOKEN_AUTH': blink._token}
blink.urls = blinkpy.BlinkURLHandler(blink.region_id)
blink.get_ids()
blink.sync = blinkpy.BlinkSyncModule(blink, blink._auth_header)
blink.sync.get_videos()
blink.sync.get_cameras()
blink.sync.set_links()
blink._events = blink.events_request()

@dgomes
Copy link
Author

dgomes commented Oct 10, 2018

refresh() and get_cameras() had no effect

did get something on resp:

{'authtoken': {'authtoken': 'REDACTED', 'message': 'auth'}, 'networks': {'31911': {'name': 'Entrada', 'onboarded': True}, '46389': {'name': 'Home', 'onboarded': False}}, 'region': {'prde': 'Europe'}}

also possibly relevant:

blink.urls.__dict__
{'base_url': 'https://rest.prod.immedia-semi.com', 'home_url': 'https://rest.prod.immedia-semi.com/homescreen', 'event_url': 'https://rest.prod.immedia-semi.com/events/network', 'network_url': 'https://rest.prod.immedia-semi.com/network', 'networks_url': 'https://rest.prod.immedia-semi.com/networks', 'video_url': 'https://rest.prod.immedia-semi.com/api/v2/videos'}

Also relevant ?

blinkpy.BlinkSyncModule(blink, blink._auth_header).__dict__
{'blink': <blinkpy.blinkpy.Blink object at 0x10c341198>, '_auth_header': {'Host': 'prde.immedia-semi.com', 'TOKEN_AUTH': 'REDACTED'}, 'sync_id': None, 'region': None, 'region_id': None, '_host': None, '_events': [], 'cameras': {}, '_idlookup': {}, '_video_count': 0, '_all_videos': {}, '_summary': None, 'record_dates': {}, 'first_init': True}

@dgomes
Copy link
Author

dgomes commented Oct 10, 2018

resp = blinkpy.http_req(blink, url="https://rest.prde.immedia-semi.com/network/31911/syncmodules", headers=headers)

does retrieve my sync_module info

@dgomes
Copy link
Author

dgomes commented Oct 10, 2018

resp = blinkpy.http_req(blink, url="https://rest.prde.immedia-semi.com/network/31911/cameras", headers=headers)

does show my camera :)

If you tell me were I need to look into your code I probably can come up with a PR :)

@fronzbot
Copy link
Owner

Ok, it seems like the urls are actually being set to the US version (prod) rather than Europe (prde). The urls are initialized in the get_auth_token() function within the blinkpy.py module (line 137). I'm not sure if this is where the problem is, but it may be a good starting point.

Those urls should be initialized with the blink.region_id which for you correctly returns prde but are not being set correctly based on the output of blink.urls.__dict__

@dgomes
Copy link
Author

dgomes commented Oct 10, 2018

the urls look OK:

blink.urls.__dict__
{'base_url': 'https://rest.prde.immedia-semi.com', 'home_url': 'https://rest.prde.immedia-semi.com/homescreen', 'event_url': 'https://rest.prde.immedia-semi.com/events/network', 'network_url': 'https://rest.prde.immedia-semi.com/network', 'networks_url': 'https://rest.prde.immedia-semi.com/networks', 'video_url': 'https://rest.prde.immedia-semi.com/api/v2/videos'}

@fronzbot
Copy link
Owner

Hmm. Maybe the way I'm grabbing cameras is in the process of being deprecated. I'm thinking it would be better to use the cameras link you posted and use that to find the cameras and update the camera properties that way (rather than looking at the events list).

@dgomes
Copy link
Author

dgomes commented Oct 10, 2018

I got that url from https://github.com/MattTW/BlinkMonitorProtocol

@dgomes
Copy link
Author

dgomes commented Oct 10, 2018

Analysing your code, one problem is you assume 1 network_id.
(I have 2 different networks)

@fronzbot
Copy link
Owner

Interesting- maybe that's the root cause here, then? If you could come up with a solution to fix that, that would be awesome (since I'm unable to test that locally).

@fronzbot fronzbot added bug There is an issue causing unexpected results help-wanted Assistance required due to lack of resources for testing or complexity labels Oct 10, 2018
@dgomes
Copy link
Author

dgomes commented Oct 10, 2018

blinkpy.http_req(blink, url="https://rest.prde.immedia-semi.com/homescreen", headers=headers)
{'account': {'notifications': 1}, 'network': {'name': 'Home', 'wifi_strength': 1, 'status': 'no_sm', 'armed': False, 'notifications': 1, 'warning': 0, 'enable_temp_alerts': False, 'error_msg': ''}, 'devices': []}

This is the culprit

devices shouldn't be []

@fronzbot
Copy link
Owner

So I opened #97 which I think should work as a cleaner fix. @dgomes let me know if it works. For anyone else that wants to test, I left more detailed instructions here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug There is an issue causing unexpected results help-wanted Assistance required due to lack of resources for testing or complexity
Projects
None yet
2 participants