Code Monkey home page Code Monkey logo

blinkpy's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blinkpy's Issues

Test cleanup

The tests are pretty messy and some are kludgy. All are poorly documented. Would like to clean these up and make sure each test serves a useful purpose.

Update speed of camera image within Home assistant.

Looking to speed up the process to update the cameras image when requesting and viewing in hass. Currently it takes around 60 or so seconds while the blink app itself is around 10. When looking at the home assistant blink.py it looks like the timedelta setting would change this. Except as included component I have not control. Thoughts?

Only log an error if re-authorization failed

Describe the bug
When a re-authorization attempt happens, an error is logged saying.

ERROR Cannot connect to server with url <some url>

However, this section of the code should ALWAYS be hit when a token expires, so there really is no error.

To Reproduce
Steps to reproduce the behavior:

  1. Login to blink
  2. Token expires
  3. Make an API call

Expected behavior
An error should only be logged if re-authorization hasn't even occurred yet. We should either change the log entry to INFO or remove it and modify the actual error message with more detail. The offending line is line 62 of blinkpy.helpers.util

blinkpy version: 0.10.2

Cannot retrieve motion thumb

Attempting to view thumbnail of motion (replace .mp4 with .Jpg) is not working and returns code 700 (media not found). Normally this is accessed with

blink.cameras[name].motion['image']

Maybe a method needs to be added to convert the mp4 (which IS valid media) to a jpg (grab last frame)? Maybe there's a more appropriate way to request the image?

Issues with too many events

First of all: thanks a lot for the library! :)

Now my problem:

It seems like I had an issue where my camera was stuck in a reboot loop.
That seems to have created a good amount of events.
While in the ios app, I can see the videos recorded prior to that just fine.
When trying to access the events as such, I end up with 73 events:

for event in blink.events:
    print(event)

But none of them actually include a video_url:

{'type': 'heartbeat', 'siren': None, 'id': 499313547, 'sync_module_id': yyyyyyy, 'camera': None, 'network_id': None, 'account_id': xxxxxxx, 'command_id': None, 'siren_id': None, 'camera_id': None, 'syncmodule': yyyyyyy, 'status': None, 'created_at': '2017-06-30T09:28:05+00:00', 'notified': False, 'account': xxxxxxx, 'duration': None, 'updated_at': '2017-06-30T09:28:05+00:00'}
{'type': 'first_boot', 'siren': None, 'id': 499313222, 'sync_module_id': yyyyyyy, 'camera': None, 'network_id': None, 'account_id': xxxxxxx, 'command_id': None, 'siren_id': None, 'camera_id': None, 'syncmodule': yyyyyyy, 'status': None, 'created_at': '2017-06-30T09:28:05+00:00', 'notified': False, 'account': xxxxxxx, 'duration': None, 'updated_at': '2017-06-30T09:28:05+00:00'}
{'type': 'heartbeat', 'siren': None, 'id': 499170781, 'sync_module_id': yyyyyyy, 'camera': None, 'network_id': None, 'account_id': xxxxxxx, 'command_id': None, 'siren_id': None, 'camera_id': None, 'syncmodule': yyyyyyy, 'status': None, 'created_at': '2017-06-30T09:24:40+00:00', 'notified': False, 'account': xxxxxxx, 'duration': None, 'updated_at': '2017-06-30T09:24:40+00:00'}
{'type': 'first_boot', 'siren': None, 'id': 499170389, 'sync_module_id': yyyyyyy, 'camera': None, 'network_id': None, 'account_id': xxxxxxx, 'command_id': None, 'siren_id': None, 'camera_id': None, 'syncmodule': yyyyyyy, 'status': None, 'created_at': '2017-06-30T09:24:40+00:00', 'notified': False, 'account': xxxxxxx, 'duration': None, 'updated_at': '2017-06-30T09:24:40+00:00'}
{'type': 'heartbeat', 'siren': None, 'id': 498834490, 'sync_module_id': yyyyyyy, 'camera': None, 'network_id': None, 'account_id': xxxxxxx, 'command_id': None, 'siren_id': None, 'camera_id': None, 'syncmodule': yyyyyyy, 'status': None, 'created_at': '2017-06-30T09:16:59+00:00', 'notified': False, 'account': xxxxxxx, 'duration': None, 'updated_at': '2017-06-30T09:16:59+00:00'}
{'type': 'first_boot', 'siren': None, 'id': 498834079, 'sync_module_id': yyyyyyy, 'camera': None, 'network_id': None, 'account_id': xxxxxxx, 'command_id': None, 'siren_id': None, 'camera_id': None, 'syncmodule': yyyyyyy, 'status': None, 'created_at': '2017-06-30T09:16:59+00:00', 'notified': False, 'account': xxxxxxx, 'duration': None, 'updated_at': '2017-06-30T09:16:59+00:00'}
{'type': 'heartbeat', 'siren': None, 'id': 498663526, 'sync_module_id': yyyyyyy, 'camera': None, 'network_id': None, 'account_id': xxxxxxx, 'command_id': None, 'siren_id': None, 'camera_id': None, 'syncmodule': yyyyyyy, 'status': None, 'created_at': '2017-06-30T09:15:14+00:00', 'notified': False, 'account': xxxxxxx, 'duration': None, 'updated_at': '2017-06-30T09:15:14+00:00'}
{'type': 'first_boot', 'siren': None, 'id': 498663414, 'sync_module_id': yyyyyyy, 'camera': None, 'network_id': None, 'account_id': xxxxxxx, 'command_id': None, 'siren_id': None, 'camera_id': None, 'syncmodule': yyyyyyy, 'status': None, 'created_at': '2017-06-30T09:15:14+00:00', 'notified': False, 'account': xxxxxxx, 'duration': None, 'updated_at': '2017-06-30T09:15:14+00:00'}
{'type': 'heartbeat', 'siren': None, 'id': 498568310, 'sync_module_id': yyyyyyy, 'camera': None, 'network_id': None, 'account_id': xxxxxxx, 'command_id': None, 'siren_id': None, 'camera_id': None, 'syncmodule': yyyyyyy, 'status': None, 'created_at': '2017-06-30T09:14:27+00:00', 'notified': False, 'account': xxxxxxx, 'duration': None, 'updated_at': '2017-06-30T09:14:27+00:00'}
{'type': 'first_boot', 'siren': None, 'id': 498568178, 'sync_module_id': yyyyyyy, 'camera': None, 'network_id': None, 'account_id': xxxxxxx, 'command_id': None, 'siren_id': None, 'camera_id': None, 'syncmodule': yyyyyyy, 'status': None, 'created_at': '2017-06-30T09:14:27+00:00', 'notified': False, 'account': xxxxxxx, 'duration': None, 'updated_at': '2017-06-30T09:14:27+00:00'}
{'type': 'heartbeat', 'siren': None, 'id': 498518072, 'sync_module_id': yyyyyyy, 'camera': None, 'network_id': None, 'account_id': xxxxxxx, 'command_id': None, 'siren_id': None, 'camera_id': None, 'syncmodule': yyyyyyy, 'status': None, 'created_at': '2017-06-30T09:13:50+00:00', 'notified': False, 'account': xxxxxxx, 'duration': None, 'updated_at': '2017-06-30T09:13:50+00:00'}
{'type': 'first_boot', 'siren': None, 'id': 498460369, 'sync_module_id': yyyyyyy, 'camera': None, 'network_id': None, 'account_id': xxxxxxx, 'command_id': None, 'siren_id': None, 'camera_id': None, 'syncmodule': yyyyyyy, 'status': None, 'created_at': '2017-06-30T08:15:16+00:00', 'notified': False, 'account': xxxxxxx, 'duration': None, 'updated_at': '2017-06-30T08:15:16+00:00'}

Is there an inherent limit to the events call? some sort of pagination that isn't handled?

Motion sensing issue in Home Assistant

Hey there,

As you probably know (edit: just read your readme and realised you built it for this! :) ) Home Assistant uses the blinkpy library for its blink integration.

The motion sensing (I.e notification count) seems to have stopped working - people think it might be because HA is using 0.6 instead of 0.8 on blinkpy.

Any chance you can shed some light on this? Would love to get it working again! :)

When no cameras on server, issue 'info' rather than 'warning' in log

Describe the bug
When a camera has no saved videos on the server, we print a 'Warning' to the log. This really should be an 'Info' statement instead (line 165 of blinkpy.cameras)

blinkpy version: 0.10.0

Log Output/Additional Information
If using home-assistant, please paste the output of the log showing your error below. If not, please include any additional useful information.

2018-10-18 15:04:24 WARNING (SyncWorker_7) [blinkpy.camera] Could not extract clip info from camera Blink 3

Blink doesn't upgrade temperature correctly when calibrated within the app

Describe the bug
Blink camera temperatures are not accurately reflected in HA when you use the blink app to calibrate the temperature settings to the proper temperature.

To Reproduce

  1. Open the blink app
  2. Go to camera settings
  3. temperature
  4. Calibrate (adjust it up by a few degrees or down by a few degrees)
  5. Go back to the previous page to save the calibration setttings
  6. In HA, call blink.blink_update
  7. Observe the temperature in blink vs HA; they should be different

Expected behavior
When calibrating the temperature, they should be the same in HA vs Blink App

Home Assistant version (if applicable): 84.6

blinkpy version (not needed if filling out Home Assistant version):

Log Output/Additional Information
No errors for blink are showing.

PASTE LOG OUTPUT HERE

Can't get latest video using blink.save_video in HA

Calling the service 'blink.save_video' does not result in a video being saved.

Here is the automation:

  • alias: office camera video
    trigger:
    • platform: state
      entity_id: binary_sensor.blink_office_motion_detected
      from: 'off'
      to: 'on'
      action:
    • service: blink.save_video
      data:
      name: camera.blink_office
      filename: '/Users/joe/.homeassistant/snapshots/office-blink.mp4'

The automation triggers, but doesn't result in an mp4 video file in that directory. The directory is whitelisted and used for images from other cameras already.

The logbook states:
1:39 AM
office camera video has been triggered

But no video file appears, and no blink errors show up in the log file.

Is this working for anyone else?

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

Expected behavior
A clear and concise description of what you expected to happen.

Home Assistant version (if applicable):

blinkpy version (not needed if filling out Home Assistant version):

Log Output/Additional Information
If using home-assistant, please paste the output of the log showing your error below. If not, please include any additional useful information.

PASTE LOG OUTPUT HERE

Multiple systems improperly handled

When a user has multiple systems on their account, the blinkpy module only grabs the last implemented system. This should be handled more intelligently.

Failing to login

I'm geting URL errors whenever I try to login with either the 8.0 or the dev branch of blinkpy. Has there possibly been an API change?

Handle internet outage gracefully

Describe the solution you'd like
If an API request fails, we should only log that error ONCE rather than every single time. This means we should have a variable for each sync module and camera called available which is set to False upon a failure. Maybe it's sufficient to only handle this once in the blink module itself? My only concern there is that we don't want to mark the whole system as unavailable if a single camera loses connection or something.

Camera motion status not updating

When arming and disarming the system, the sensor updates in home assistant. But when toggling the motion for a camera on and off it stays on. The only way to toggle the motion sensor off in the HASS ui is to disarm the system entirely. Where both are then disabled.

1 out of 2 Blinks not showing up post 0.80

I updated to HASS 0.80 and everything seemed to work fine. A few restarts later and the camera refuses to function. I stripped down the config to just username and password and it still is unresponsive. Within HASS, the battery status is for the camera is displayed as -100.

The HASS log shows this:
Unexpected exception Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/homeassistant/components/websocket_api/decorators.py", line 16, in _handle_async_response await func(hass, connection, msg) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/camera/__init__.py", line 462, in websocket_camera_thumbnail image = await async_get_image(hass, msg['entity_id']) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/camera/__init__.py", line 93, in async_get_image image = await camera.async_camera_image() File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(*self.args, **self.kwargs) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/camera/blink.py", line 76, in camera_image return self._camera.image_from_cache.content AttributeError: 'NoneType' object has no attribute 'content'

and

Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 390, in start resp = await self._request_handler(request) File "/usr/local/lib/python3.6/site-packages/aiohttp/web_app.py", line 366, in _handle resp = await handler(request) File "/usr/local/lib/python3.6/site-packages/aiohttp/web_middlewares.py", line 106, in impl return await handler(request) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/http/static.py", line 66, in staticresource_middleware return await handler(request) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/http/real_ip.py", line 34, in real_ip_middleware return await handler(request) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/http/ban.py", line 66, in ban_middleware return await handler(request) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/http/auth.py", line 68, in auth_middleware return await handler(request) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/http/real_ip.py", line 34, in real_ip_middleware return await handler(request) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/http/ban.py", line 66, in ban_middleware return await handler(request) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/http/auth.py", line 68, in auth_middleware return await handler(request) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/http/view.py", line 113, in handle result = await result File "/usr/local/lib/python3.6/site-packages/homeassistant/components/camera/__init__.py", line 406, in get return await self.handle(request, camera) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/camera/__init__.py", line 423, in handle image = await camera.async_camera_image() File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(*self.args, **self.kwargs) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/camera/blink.py", line 76, in camera_image return self._camera.image_from_cache.content AttributeError: 'NoneType' object has no attribute 'content'

Repeating every minute or so post startup.

Typo in log output

Describe the bug
Typo in blinkpy.py line 147

Expected behavior
Should read "onboarded" instead of "unboarded"

blinkpy version: 0.10.1

Add more debug logging

Is your feature request related to a problem? Please describe.
Setting logger to debug doesn't provide much info currently, as there are only a handful of debug prints.

Describe the solution you'd like
We should add a debug write every time a link is called, so we know what the platform is actually doing. We should also remove the video page debug print since it spits out a ton of useless information.

Ignore case when accessing camera name

Currently the camera dictionary can be accessed with the camera name, but case matters. We should ignore case sensitivity here to make it less annoying to access.

Use of homescreen API endpoint is unreliable

Describe the bug
Currently, the blinkpy library requests a region_id from Blink upon login, and uses this as the basis for all API calls. In the US, this endpoint begins with the rest.prod subdomain, while in Europe it is usally rest.prde. However, not all of the API endpoints in Europe use the rest.prde subdomain, based on comments in the repo this library is based upon. This seems likely to be the root cause of homeassistant/homeassistant#18341.

To Reproduce
Steps to reproduce the behavior:

  1. Successfully login with European endpoint
  2. Make various API calls
  3. Some fail, some succeed

Expected behavior
First, we need to figure out if there are any safe API endpoint subdomains, or if there's a way to retrieve the correct subdomain on a case-by-case basis. After that, it's just a matter of keeping track of the correct subdomain to use per API call.

Home Assistant version (if applicable): 0.81.0+

blinkpy version: 0.10.1 (but all versions are affected)

Additional Information
If you are having this issue and are willing to help debug to find a solution, please repeat the following steps and report the response (you must have curl installed on your system):

Debug steps (I need people to help with this!)

Step 1: Login

curl -H "Host: prod.immedia-semi.com" -H "Content-Type: application/json" --data-binary '{ "password" : "your blink password", "client_specifier" : "iPhone 9.2 | 2.2 | 222", "email" : "your blink login/email" }' --compressed https://rest.prod.immedia-semi.com/login

Take note of the authtoken that is printed to your terminal window (but do not share it). Please post the "region" dictionary (it should look like "region":{"prde":"Europe"} or something like that). Also note the network id (4-5 characters, all numbers). Looks like the following:
"networks": {"1234":{"name":"somename", "onboarded":"True"}}
If you have multiple network ids, only record the one that also has "onboarded":"True"

Step 2: Try arming/disarming the system
Based on the linked home-assistant issue, this is one potential failure point for European-based API endpoints. To arm/disarm just replace the last work in the link in the following command with arm or disarm. To see if it worked, wait ten or more seconds and then open your Blink App on your phone.

curl -H "Host: prde.immedia-semi.com" -H "TOKEN_AUTH: authtoken from login" --data-binary --compressed https://rest.prde.immedia-semi.com/network/*network_id_from_previous_step*/arm

If this doesn't work (you should received a 101 Unauthorized error), try the following:

  • replace prde in the above command with prod
  • If that does not work, replace prde in the above command with u002
  • If that does not work, replaced prde in the above command with piri

Those variation are to see if there is some consistently safe API endpoint and will help determine future debug steps.

Temperature alerts

Is your feature request related to a problem? Please describe.
The blink app has the ability to calibrate the temperature sensor and set temperature alerts.

Describe the solution you'd like
Having the ability to set alerts and monitor them (as well as calibrate the sensor) would be neat. I do not know the API endpoint to do that yet, though.

Everything seems to run but no results

Entered all commands as listed in readme, but nothing printed out. I tried entering the wrong password and got error messages, but when I entered the right password, there was no information printed about any of my cameras. Any advice in troubleshooting? I'm using Windows 10. I've got Python 3.6.3. I installed blinkpy as you recommended. I could not successfully perform all the commands you recommended for developer install.

Reorganize

Despite the last reorg, i think this code could use some more cleanup. I think have a main blink module with sub components for sync modules and then cameras underneath that makes sense. Basically, cameras belong to sync modules, and sync modules belong to the core Blinkpy class.

Also, things like info refresh should be performs within each camera/sync module. I think there are a lot of superfluous API calls that can be paired down substantially.

The reorg should help make multi-sync unit integration a lot easier #36

More robust video features

Is your feature request related to a problem? Please describe.

  • Currently cannot delete videos with blinkpy.
  • Can only retrieve page-by-page info of videos
  • Can only download latest video with built-in functions

Describe the solution you'd like

  • Video deletion api endpoint exists and can be implemented: https://github.com/fronzbot/blinkpy/blob/dev/API.md#video-information
  • Same link shows endpoint for unwatched videos
  • Should have ability to download all unwatched videos as well as download videos across a certain page range (with built-in throttling so we don't hammer the Blink servers).

Using updated version in home assistant.

I am trying to get the updated version of blink.py to work in HASS, except after updating to 0.79.3 HASS still is using the old version. I removed my custom component copy of blink and commented it out then in again within the config YAML and restarted. The cameras show up and work except it is the old version as proved by the old camera naming scheme and the old snap picture service name. I checked the release notes and nothing was noted about a Blink update. But the Home Assistant GitHub shows the updated version, so I don't know if this is on my side or a HASS based issue.

My config is just
blink: username: [email protected] password: Blinkpassword

cannot get motion video clips using events() functions

Are the api updated?
Could anyone help?
Thanks!

The results are as below:
{
"event": [
{
"id": xxxxx,
"created_at": "2017-12-28T22:02:53+00:00",
"updated_at": "2017-12-28T22:02:53+00:00",
"type": "armed",
"notified": false,
"duration": null,
"status": null,
"command_id": null,
"camera_id": null,
"siren_id": null,
"sync_module_id": xxxx,
"network_id": null,
"account_id": xxxxx,
"syncmodule": xxxxx,
"camera": null,
"siren": null,
"account": xxxxx
}
]
}

Concurrent command support

Does this library (or the API) support running multiple commands at the same time? I tried running the "request_new_video" command on two different cameras simultaneously, and got the error "Cannot obtain new token for server auth".

Update camera and sync module with more targeted urls

Currently we're using a summary page to update the sync module and camera status. We probably should be using the syncmodules and cameras urls instead as shown in #90 since the information is more relevant and likely easier to parse.

Other uri

Hi!

I love the work on the blink4home camera. Also love the support in home-assistant! I had a custom component, but it did far less.

There is one thing. The url prod.immedia-semi.com doesn't work with my setup. Never has sadly. It seems that I can login, but any other action after that is blocked with the messge that I don't have authorisation.
After a bit of reverse engineering I found out that the app uses the following url:
https://rest.prir.immedia-semi.com

This works with my blink4home setup. Since it's used in the official app, it would be better to start using this (and also prevent others from having the same problem as me). The api on this url is the same as the one before.

Can you change/test this? Or do you want me to change it through a branch and send you a pull request?

Migrate to async

I'd like to make this API entirely async to improve home-assistant integration. In addition, I'd like to use the built-in 'async' keywords which would mean no more 3.4 support.

Use ffmpeg to grab a frame of the most recently recorded clip

Based on this comment use ffmpeg to grab a frame of the most recently recorded clip and use that as a thumbnail.

My thought is to use this as the thumbnail by default, and have a separate attribute for still_image. This way we can change the cached image based on whether snap_picture was called (in which case we want to display the regular thumbnail rather than a frame from the clip).

Commands from linked post:

ffmpeg -y -ss 00:00:04 -i BlinkVideo.mp4 -vf 'crop=720:720:280:0' -vframes 1 -vcodec png BlinkImage.png

Breaking down the switches:

  • -y Overwrite any existing file.
  • -ss 00:00:04 Start at the 4th second of the video (in my setup the visitor is normally well in frame here).
  • -i BlinkVideo.mp4 The input video.
  • -vf β€˜crop=720:720:280:0’ Crop the image to 720px X 720px starting at 280 pixels from the left and 0 pixels from the top. This leaves me with a square image that I then display in HA Dashboard.
  • -vframes 1 Only grab 1 frame for saving.
  • -vcodec png Save it as a PNG,
  • BlinkImage.png The output image file.

Command-line support

Want to build in command-line support so to make this tool easier to use. Will likely require some code refactoring.

Mark blink as unavailable if auth token cannot be renewed

Describe the bug
If blinkpy is unable to re-authorize with the Blink servers, it will log an error stating that fact. Any subsequent request will go through the same re-authorization attempt (which is fine) but will log the error again (which is NOT fine).

To Reproduce
Steps to reproduce the behavior (this should be implemented as a test):

  1. De-authorize blinkpy (change token to some dummy value)
  2. Make a request and when blinkpy attempts to re-authorize, replace with incorrect headers. An error is logged at this stage.
  3. Repeat step 2. Another error is logged, even though we have never made a successful request.

Expected behavior
Upon the first failed re-authorization attempt, we should mark blinkpy as unavailable. This available property should be added to the main Blink class and initially set to False. When we retrieve a valid token, we set this to True. Upon a failed re-authorization attempt, Blink.available should be set to False. Any subsequent request should check this variable prior to both the request and the logging of the error.

To summarize:

  • Set Blink.available to False upon a failed re-authorization
  • Check this value prior to a request and prior to logging an error (failed re-auth error should only be logged ONCE).

blinkpy version: 0.10.2

Currently doesn't work for non-US regions

prod.immedia-semi.com only works as host for US region. Need to get region at login to change immedia-semi.com subdomain.

For example, logging in with the following header:

headers = {'Host': 'prod.immedia-semi.com',
           'Content-Type': 'application/json',
          }

Results in the following json response:

{'region': {'prod': 'United States'}, 
'networks': {<REDACTED>: {'name': <REDACTED>, 'onboarded': True}}, 
'authtoken': {'message': 'auth', 'authtoken': <REDACTED>}}

Need to set subdomain:

(subdomain, region), = response.json()['region'].items()

Backup login url incorrect

Describe the bug
Backup login url in the helpers/constants.py module contains errant / instead of .. Should be rest.piri. instead of rest.piri/

To Reproduce
Steps to reproduce the behavior:

  1. Fail with LOGIN_URL
  2. BACKUP_LOGIN_URL will fail because of incorrect format

blinkpy version: 0.11.0

Tests for token reauth

Add tests to verify we can reauthorize and don't get stuck in loops if authorization not working

No camera show's up

from blinkpy import blinkpy

blink = blinkpy.Blink(username='[email protected]', 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

Token Checking/Reauthorization

Token expires after 24hrs. Would like to add in a feature where the token are handled behind the scenes in order to be backwards compatible with existing module that rely on blinkpy (such as the home assistant Blink module).

Perhaps when blinkpy calls the _request function we do a token check and grab a new one if the existing token has expired?

0.10.0 Does not reauthorize

Describe the bug
Due to an addition to 0.10.0, I introduced a bug that prevents re-authorization. Blink will lose connection to the servers after a certain amount of time due to auth token expiry.

To Reproduce
Steps to reproduce the behavior:

  1. Create Blink instance
  2. Leave running
  3. Eventually will see a logged error as well as an exception regarding the events retrieval when performing a system refresh.

Expected behavior
When the first request fails, we should re-authorize and attempt again before throwing an error.

Home Assistant version (if applicable): 0.80.2

blinkpy version (not needed if filling out Home Assistant version): 0.10.0

Log Output/Additional Information

2018-10-18 07:58:12 ERROR (SyncWorker_5) [blinkpy.helpers.util] Cannot connect to server. Possible outage.
2018-10-18 07:58:12 ERROR (MainThread) [homeassistant.helpers.entity] Update for alarm_control_panel.blink_sync fails
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/app/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/app/homeassistant/components/alarm_control_panel/blink.py", line 77, in update
    self.data.refresh()
  File "/usr/local/lib/python3.6/site-packages/blinkpy/blinkpy.py", line 160, in refresh
    self.sync.refresh(force_cache=force_cache)
  File "/usr/local/lib/python3.6/site-packages/blinkpy/sync_module.py", line 114, in refresh
    self.events = self.get_events()
  File "/usr/local/lib/python3.6/site-packages/blinkpy/sync_module.py", line 105, in get_events
    return response['event']
TypeError: 'NoneType' object is not subscriptable

The error exists on lines 49-53 of 'blinkpy.helpers.util`, copied below. When we hit the exception, we should retry before logging an error (instead of checking for retry in the code following the mentioned lines)

 try:
        response = blink.session.send(prepped, stream=stream)
 except (exceptions.ConnectionError, exceptions.Timeout):
        # CHECK IF RETRY HERE, IF NOT, PROCEED
        _LOGGER.error("Cannot connect to server. Possible outage.")
        return None

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.