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

Arlo - Fixes for updated library #9892

Merged
merged 8 commits into from Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/arlo.py
Expand Up @@ -12,7 +12,7 @@
from homeassistant.helpers import config_validation as cv
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD

REQUIREMENTS = ['pyarlo==0.0.7']
REQUIREMENTS = ['pyarlo==0.1.0']

_LOGGER = logging.getLogger(__name__)

Expand Down
35 changes: 16 additions & 19 deletions homeassistant/components/camera/arlo.py
Expand Up @@ -19,7 +19,7 @@

_LOGGER = logging.getLogger(__name__)

SCAN_INTERVAL = timedelta(minutes=10)
SCAN_INTERVAL = timedelta(seconds=90)

ARLO_MODE_ARMED = 'armed'
ARLO_MODE_DISARMED = 'disarmed'
Expand All @@ -31,6 +31,7 @@
ATTR_POWERSAVE = 'power_save_mode'
ATTR_SIGNAL_STRENGTH = 'signal_strength'
ATTR_UNSEEN_VIDEOS = 'unseen_videos'
ATTR_LAST_REFRESH = 'last_refresh'

CONF_FFMPEG_ARGUMENTS = 'ffmpeg_arguments'

Expand Down Expand Up @@ -73,6 +74,8 @@ def __init__(self, hass, camera, device_info):
self._motion_status = False
self._ffmpeg = hass.data[DATA_FFMPEG]
self._ffmpeg_arguments = device_info.get(CONF_FFMPEG_ARGUMENTS)
self._last_refresh = None
self._camera.base_station.refresh_rate = SCAN_INTERVAL.total_seconds()
self.attrs = {}

def camera_image(self):
Expand Down Expand Up @@ -105,14 +108,17 @@ def name(self):
def device_state_attributes(self):
"""Return the state attributes."""
return {
ATTR_BATTERY_LEVEL: self.attrs.get(ATTR_BATTERY_LEVEL),
ATTR_BRIGHTNESS: self.attrs.get(ATTR_BRIGHTNESS),
ATTR_FLIPPED: self.attrs.get(ATTR_FLIPPED),
ATTR_MIRRORED: self.attrs.get(ATTR_MIRRORED),
ATTR_MOTION: self.attrs.get(ATTR_MOTION),
ATTR_POWERSAVE: self.attrs.get(ATTR_POWERSAVE),
ATTR_SIGNAL_STRENGTH: self.attrs.get(ATTR_SIGNAL_STRENGTH),
ATTR_UNSEEN_VIDEOS: self.attrs.get(ATTR_UNSEEN_VIDEOS),
name: value for name, value in (
(ATTR_BATTERY_LEVEL, self._camera.battery_level),
(ATTR_BRIGHTNESS, self._camera.brightness),
(ATTR_FLIPPED, self._camera.flip_state),
(ATTR_MIRRORED, self._camera.mirror_state),
(ATTR_MOTION, self._camera.motion_detection_sensitivity),
(ATTR_POWERSAVE, POWERSAVE_MODE_MAPPING.get(
self._camera.powersave_mode)),
(ATTR_SIGNAL_STRENGTH, self._camera.signal_strength),
(ATTR_UNSEEN_VIDEOS, self._camera.unseen_videos),
) if value is not None
}

@property
Expand Down Expand Up @@ -160,13 +166,4 @@ def disable_motion_detection(self):

def update(self):
"""Add an attribute-update task to the executor pool."""
self.attrs[ATTR_BATTERY_LEVEL] = self._camera.get_battery_level
self.attrs[ATTR_BRIGHTNESS] = self._camera.get_battery_level
self.attrs[ATTR_FLIPPED] = self._camera.get_flip_state,
self.attrs[ATTR_MIRRORED] = self._camera.get_mirror_state,
self.attrs[
ATTR_MOTION] = self._camera.get_motion_detection_sensitivity,
self.attrs[ATTR_POWERSAVE] = POWERSAVE_MODE_MAPPING[
self._camera.get_powersave_mode],
self.attrs[ATTR_SIGNAL_STRENGTH] = self._camera.get_signal_strength,
self.attrs[ATTR_UNSEEN_VIDEOS] = self._camera.unseen_videos
self._camera.update()
24 changes: 21 additions & 3 deletions homeassistant/components/sensor/arlo.py
Expand Up @@ -29,7 +29,8 @@
'last_capture': ['Last', None, 'run-fast'],
'total_cameras': ['Arlo Cameras', None, 'video'],
'captured_today': ['Captured Today', None, 'file-video'],
'battery_level': ['Battery Level', '%', 'battery-50']
'battery_level': ['Battery Level', '%', 'battery-50'],
'signal_strength': ['Signal Strength', None, 'signal']
}

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
Expand Down Expand Up @@ -97,6 +98,16 @@ def unit_of_measurement(self):

def update(self):
"""Get the latest data and updates the state."""
try:
base_station = self._data.base_station
except (AttributeError, IndexError):
return

if not base_station:
return

base_station.refresh_rate = SCAN_INTERVAL.total_seconds()

self._data.update()

if self._sensor_type == 'total_cameras':
Expand All @@ -114,7 +125,13 @@ def update(self):

elif self._sensor_type == 'battery_level':
try:
self._state = self._data.get_battery_level
self._state = self._data.battery_level
except TypeError:
self._state = None

elif self._sensor_type == 'signal_strength':
try:
self._state = self._data.signal_strength
except TypeError:
self._state = None

Expand All @@ -128,7 +145,8 @@ def device_state_attributes(self):

if self._sensor_type == 'last_capture' or \
self._sensor_type == 'captured_today' or \
self._sensor_type == 'battery_level':
self._sensor_type == 'battery_level' or \
self._sensor_type == 'signal_strength':
attrs['model'] = self._data.model_id

return attrs
2 changes: 1 addition & 1 deletion requirements_all.txt
Expand Up @@ -568,7 +568,7 @@ pyairvisual==1.0.0
pyalarmdotcom==0.3.0

# homeassistant.components.arlo
pyarlo==0.0.7
pyarlo==0.1.0

# homeassistant.components.notify.xmpp
pyasn1-modules==0.1.5
Expand Down