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

Allow Nest Cam turn on/off #15681

Merged
Merged
Changes from 1 commit
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
33 changes: 31 additions & 2 deletions homeassistant/components/camera/nest.py
Expand Up @@ -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__)
Expand Down Expand Up @@ -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)
Copy link
Member

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.

Copy link
Contributor Author

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.


def turn_on(self):
"""Turn on camera."""
if not self._online:
raise HomeAssistantError('Camera {} is offline.'
Copy link
Member

Choose a reason for hiding this comment

The 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
Expand Down