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

Added new request url for camera config #65

Merged
merged 2 commits into from
May 21, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions blinkpy/blinkpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,17 @@ def __init__(self, config, blink):
config['thumbnail'])
self.clip = "{}{}".format(self.urls.base_url, config['video'])
self.temperature = config['temp']
self.battery = config['battery']
self._battery_string = config['battery']
self.notifications = config['notifications']
self.motion = {}
self.motion = dict()
self.header = None
self.image_link = None
self.arm_link = None
self.region_id = config['region_id']
self.battery_voltage = -180

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing whitespace

self.motion_detected = None
self.wifi_strength = None
self.camera_config = dict()

@property
def attributes(self):
Expand All @@ -128,6 +132,8 @@ def attributes(self):
'thumbnail': self.thumbnail,
'video': self.clip,
'notifications': self.notifications,
'motion_detected': self.motion_detected,
'wifi_strength': self.wifi_strength,
'network_id': self.blink.network_id
}
return attributes
Expand All @@ -142,13 +148,18 @@ def armed(self):
"""Return camera arm status."""
return True if self._status == 'armed' else False

@property
def battery(self):
"""Return battery level as percentage."""
return round(self.battery_voltage / 180 * 100)

@property
def battery_string(self):
"""Return string indicating battery status."""
status = "Unknown"
if self.battery > 1 and self.battery <= 3:
if self._battery_string > 1 and self._battery_string <= 3:
status = "OK"
elif self.battery >= 0:
elif self._battery_string >= 0:
status = "Low"
return status

Expand All @@ -175,10 +186,24 @@ def update(self, values):
self.urls.base_url, values['thumbnail'])
self.clip = "{}{}".format(
self.urls.base_url, values['video'])
self.temperature = values['temp']
self.battery = values['battery']
self._battery_string = values['battery']
self.notifications = values['notifications']

try:
cfg = self.blink._camera_config_request(self.id)
self.camera_config = cfg
except:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not use bare except'

_LOGGER.warning("Could not get config for {} with id {}".format(
self.name, self.id))
try:
self.battery_voltage = cfg['camera'][0]['battery_voltage']
self.motion_detected = cfg['camera'][0]['motion_alert']
self.wifi_strength = cfg['camera'][0]['wifi_strength']
self.temperature = cfg['camera'][0]['temperature']
except KeyError:
_LOGGER.warning("Problem extracting config for camera {}".format(
self.name))

def image_refresh(self):
"""Refresh current thumbnail."""
url = self.urls.home_url
Expand Down Expand Up @@ -365,6 +390,7 @@ def get_cameras(self):
device = BlinkCamera(element, self)
self.cameras[device.name] = device
self._idlookup[device.id] = device.name
self.refresh()

def set_links(self):
"""Set access links and required headers for each camera in system."""
Expand Down Expand Up @@ -497,3 +523,11 @@ def _status_request(self):
self.network_id)
headers = self._auth_header
return _request(self, url=url, headers=headers, reqtype='get')

def _camera_config_request(self, camera_id):
"""Retrieve more info about Blink config."""
url = "{}/network/{}/camera/{}/config".format(self.urls.base_url,
self.network_id,
str(camera_id))
headers = self._auth_header
return _request(self, url=url, headers=headers, reqtype='get')