Ejemplo n.º 1
0
    def __run_action(self,
                     method='GET',
                     resource=None,
                     mode=None,
                     publish_response=None):
        """Run action.

        :param method: Specify the method GET, POST or PUT. Default is GET.
        :param resource: Specify one of the resources to fetch from arlo.
        :param mode: Specify the mode to set, else None for GET operations
        :param publish_response: Set to True for SETs. Default False
        """
        url = NOTIFY_ENDPOINT.format(self.device_id)

        body = ACTION_BODY

        if resource:
            body['resource'] = resource

        if method == 'GET':
            body['action'] = "get"
            body['properties'] = None
        elif method == 'SET':
            body['action'] = "set"
            if resource == 'schedule':
                body['properties'] = {'active': 'true'}
            elif resource == 'subscribe':
                body['resource'] = "subscriptions/" + \
                        "{0}_web".format(self.user_id)
                dev = []
                dev.append(self.device_id)
                body['properties'] = {'devices': dev}
            elif resource == 'modes':
                body['properties'] = {'active': ACTION_MODES.get(mode)}
        else:
            _LOGGER.info("Invalid method requested")
            return None

        if not publish_response:
            body['publishResponse'] = 'false'
        else:
            body['publishResponse'] = 'true'

        body['from'] = "{0}_web".format(self.user_id)
        body['to'] = self.device_id
        body['transId'] = "web!e6d1b969.8aa4b!1498165992111"

        _LOGGER.debug("Action body: %s", body)

        ret = \
            self._session.query(url, method='POST', extra_params=body,
                                extra_headers={"xCloudId": self.xcloud_id})
        if ret.get('success'):
            return 'success'

        return None
Ejemplo n.º 2
0
    def __run_action(self, action):
        """Run action."""
        url = NOTIFY_ENDPOINT.format(self.device_id)
        body = RUN_ACTION_BODY
        body['from'] = "{0}_web".format(self.user_id)
        body['to'] = self.device_id
        body['properties'] = {'active': ACTION_MODES.get(action)}

        # if action is schedule, modify resource and properties
        if action == 'schedule':
            body['resource'] = 'schedule'
            body['properties'] = {'active': 'true'}

        ret = \
            self._session.query(url, method='POST', extra_params=body,
                                extra_headers={"xCloudId": self.xcloud_id})
        return ret.get('success') == True