-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Allow Nest Cam turn on/off #15681
Merged
MartinHjelmare
merged 3 commits into
home-assistant:dev
from
awarecan:add-turn-on-off-nest-camera
Jul 25, 2018
Merged
Allow Nest Cam turn on/off #15681
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,9 @@ | |
import requests | ||
|
||
from homeassistant.components import nest | ||
from homeassistant.components.camera import (PLATFORM_SCHEMA, Camera) | ||
from homeassistant.components.camera import (PLATFORM_SCHEMA, Camera, | ||
SUPPORT_ON_OFF) | ||
from homeassistant.exceptions import HomeAssistantError | ||
from homeassistant.util.dt import utcnow | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
@@ -76,7 +78,34 @@ def brand(self): | |
"""Return the brand of the camera.""" | ||
return NEST_BRAND | ||
|
||
# This doesn't seem to be getting called regularly, for some reason | ||
@property | ||
def supported_features(self): | ||
"""Nest Cam support turn on and off.""" | ||
return SUPPORT_ON_OFF | ||
|
||
@property | ||
def is_on(self): | ||
"""Return true if on.""" | ||
return self._online and self._is_streaming | ||
|
||
def turn_off(self): | ||
"""Turn off camera.""" | ||
_LOGGER.debug('Turn off camera %s', self._name) | ||
# Calling Nest API in is_streaming setter | ||
self.device.is_streaming = False | ||
self.schedule_update_ha_state(True) | ||
|
||
def turn_on(self): | ||
"""Turn on camera.""" | ||
if not self._online: | ||
raise HomeAssistantError('Camera {} is offline.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We usually don't raise within entity actuator methods. Log error and return is normal. |
||
.format(self._name)) | ||
|
||
_LOGGER.debug('Turn on camera %s', self._name) | ||
# Calling Nest API in is_streaming setter | ||
self.device.is_streaming = True | ||
self.schedule_update_ha_state(True) | ||
|
||
def update(self): | ||
"""Cache value from Python-nest.""" | ||
self._location = self.device.where | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a polling entity, this line isn't needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. Just test out on real device, after this statement, camera still need few seconds to finish process and return is_streaming = True. The update statement is useless here anyway.