Skip to content

Commit 296c21f

Browse files
committed
Revert "Added constants and error file to clean stuff up"
This reverts commit 69b7be7.
1 parent 5215d0f commit 296c21f

File tree

4 files changed

+49
-102
lines changed

4 files changed

+49
-102
lines changed

blinkpy.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,24 @@
55
blinkpy by Kevin Fronczak - A Blink camera Python library
66
https://github.com/fronzbot/blinkpy
77
Original protocol hacking by MattTW : https://github.com/MattTW/BlinkMonitorProtocol
8+
89
Published under the MIT license - See LICENSE file for more details.
10+
911
"Blink Wire-Free HS Home Monitoring & Alert Systems" is a trademark owned by Immedia Inc., see www.blinkforhome.com for more information.
1012
I am in no way affiliated with Blink, nor Immedia Inc.
1113
'''
1214

15+
import logging
1316
import requests
1417
import getpass
1518
import json
16-
import errors as ERROR
17-
from constants import (BLINK_URL, LOGIN_URL,
18-
BASE_URL, DEFAULT_URL,
19-
HOME_URL, EVENT_URL,
20-
NETWORK_URL, NETWORKS_URL,
21-
ONLINE)
19+
20+
BLINK_URL = 'immedia-semi.com'
21+
LOGIN_URL = 'https://prod.' + BLINK_URL + '/login'
22+
BASE_URL = 'https://prod.' + BLINK_URL
23+
DEFAULT_URL = 'prod.' + BLINK_URL
24+
25+
logger = logging.getLogger('blinkpy')
2226

2327

2428
def _request(url, data=None, headers=None, type='get', stream=False, json=True):
@@ -30,18 +34,18 @@ def _request(url, data=None, headers=None, type='get', stream=False, json=True):
3034
elif type is 'get' and not json:
3135
response = requests.get(url, headers=headers, stream=stream)
3236
else:
33-
raise BlinkException(ERROR.REQUEST)
37+
raise ValueError("Cannot perform requests of type " + type)
3438

3539
if json and 'message' in response.keys():
36-
raise BlinkAuthenticationException((response['code'], response['message']))
40+
raise BlinkAuthenticationException(response['code'], response['message'])
3741

3842
return response
3943

4044

4145
class BlinkException(Exception):
42-
def __init__(self, errcode):
43-
self.id = errcode[0]
44-
self.message = errcode[1]
46+
def __init__(self, id, message):
47+
self.id = id
48+
self.message = message
4549

4650

4751
class BlinkAuthenticationException(BlinkException):
@@ -181,7 +185,7 @@ def update(self, values):
181185
self._NOTIFICATIONS = values['notifications']
182186

183187
def image_refresh(self):
184-
url = HOME_URL
188+
url = BASE_URL + '/homescreen'
185189
response = _request(url, headers=self._HEADER, type='get')['devices']
186190
for element in response:
187191
try:
@@ -254,17 +258,18 @@ def region_id(self):
254258
@property
255259
def events(self):
256260
"""Gets all events on server"""
257-
url = EVENT_URL + self._NETWORKID
261+
url = BASE_URL + '/events/network/' + self._NETWORKID
258262
headers = self._AUTH_HEADER
259263
self._EVENTS = _request(url, headers=headers, type='get')['event']
260264
return self._EVENTS
261265

262266
@property
263267
def online(self):
264268
"""Returns True or False depending on if sync module is online/offline"""
265-
url = NETWORK_URL + self._NETWORKID + '/syncmodules'
269+
url = BASE_URL + 'network/' + self._NETWORKID + '/syncmodules'
266270
headers = self._AUTH_HEADER
267-
return ONLINE[_request(url, headers=headers, type='get')['syncmodule']['status']]
271+
online_dict = {'online': True, 'offline': False}
272+
return online_dict[_request(url, headers=headers, type='get')['syncmodule']['status']]
268273

269274
def last_motion(self):
270275
"""Finds last motion of each camera"""
@@ -292,7 +297,7 @@ def arm(self, value):
292297
value_to_append = 'arm'
293298
else:
294299
value_to_append = 'disarm'
295-
url = NETWORK_URL + self._NETWORKID + '/' + value_to_append
300+
url = BASE_URL + '/network/' + self._NETWORKID + '/' + value_to_append
296301
_request(url, headers=self._AUTH_HEADER, type='post')
297302

298303
def refresh(self):
@@ -313,7 +318,7 @@ def get_summary(self):
313318
headers = self._AUTH_HEADER
314319

315320
if self._AUTH_HEADER is None:
316-
raise BlinkException(ERROR.AUTH_TOKEN)
321+
raise BlinkException(0, "Authentication header incorrect. Are you sure you logged in and received your token?")
317322

318323
return _request(url, headers=headers, type='get')
319324

@@ -332,16 +337,16 @@ def get_cameras(self):
332337
def set_links(self):
333338
"""Sets access links and required headers for each camera in system"""
334339
for name, camera in self._CAMERAS.items():
335-
image_url = NETWORK_URL + self._NETWORKID + '/camera/' + camera.id + '/thumbnail'
336-
arm_url = NETWORK_URL + self._NETWORKID + '/camera/' + camera.id + '/'
340+
image_url = BASE_URL + '/network/' + self._NETWORKID + '/camera/' + camera.id + '/thumbnail'
341+
arm_url = BASE_URL + '/network/' + self._NETWORKID + '/camera/' + camera.id + '/'
337342
camera.image_link = image_url
338343
camera.arm_link = arm_url
339344
camera.header = self._AUTH_HEADER
340345

341346
def setup_system(self):
342347
"""Method logs in and sets auth token and network ids for future requests"""
343348
if self._username is None or self._password is None:
344-
raise BlinkAuthenticationException(ERROR.AUTHENTICATE)
349+
raise BlinkAuthenticationException(3, "Cannot authenticate since either password or username has not been set")
345350

346351
self.get_auth_token()
347352
self.get_ids()
@@ -356,9 +361,9 @@ def login(self):
356361
def get_auth_token(self):
357362
"""Retrieves the authentication token from Blink"""
358363
if not isinstance(self._username, str):
359-
raise BlinkAuthenticationException(ERROR.USERNAME)
364+
raise BlinkAuthenticationException(0, "Username must be a string")
360365
if not isinstance(self._password, str):
361-
raise BlinkAuthenticationException(ERROR.PASSWORD)
366+
raise BlinkAuthenticationException(0, "Password must be a string")
362367

363368
headers = {'Host': DEFAULT_URL,
364369
'Content-Type': 'application/json'
@@ -378,11 +383,11 @@ def get_auth_token(self):
378383

379384
def get_ids(self):
380385
"""Sets the network ID and Account ID"""
381-
url = NETWORKS_URL
386+
url = BASE_URL + '/networks'
382387
headers = self._AUTH_HEADER
383388

384389
if self._AUTH_HEADER is None:
385-
raise BlinkException(ERROR.AUTH_TOKEN)
390+
raise BlinkException(0, "Authentication header incorrect. Are you sure you logged in and received your token?")
386391

387392
response = _request(url, headers=headers, type='get')
388393
self._NETWORKID = str(response['networks'][0]['id'])

constants.py

Lines changed: 0 additions & 54 deletions
This file was deleted.

errors.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

setup.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
# -*- coding: utf-8 -*-
22

33
from setuptools import setup
4-
from constants import (__version__, PROJECT_PACKAGE_NAME,
5-
PROJECT_LICENSE, PROJECT_URL,
6-
PROJECT_EMAIL, PROJECT_DESCRIPTION,
7-
PROJECT_CLASSIFIERS, PROJECT_AUTHOR,
8-
PROJECT_LONG_DESCRIPTION)
94

105
setup(
11-
name = PROJECT_PACKAGE_NAME,
12-
version = __version__,
13-
description = PROJECT_DESCRIPTION,
14-
long_description = PROJECT_LONG_DESCRIPTION,
15-
author = PROJECT_AUTHOR,
16-
author_email = PROJECT_EMAIL,
17-
license = PROJECT_LICENSE,
18-
url = PROJECT_URL,
19-
platforms = 'any',
20-
py_modules = ['blinkpy'],
21-
install_requires = ['requests>=2,<3'],
22-
test_suite = 'tests',
23-
classifiers = PROJECT_CLASSIFIERS
6+
name = 'blinkpy',
7+
version = '0.4.4',
8+
description = 'A Blink camera Python library',
9+
long_description='A library that communicates with Blink cameras',
10+
author = 'Kevin Fronczak',
11+
author_email = "kfronczak@gmail.com",
12+
license='MIT',
13+
url = 'https://github.com/fronzbot/blinkpy',
14+
py_modules=['blinkpy'],
15+
install_requires=['requests>=2,<3'],
16+
classifiers=[
17+
'Development Status :: 4 - Beta',
18+
'Intended Audience :: Developers',
19+
'License :: OSI Approved :: MIT License',
20+
'Programming Language :: Python :: 3.4',
21+
'Programming Language :: Python :: 3.5',
22+
'Programming Language :: Python :: 3.6',
23+
'Environment :: Plugins',
24+
'Environment :: Web Environment'
25+
]
2426
)

0 commit comments

Comments
 (0)