Пример #1
0
 def _subscribe_update_commands(self,
                                device_id=None,
                                network_ids=(),
                                device_type_ids=(),
                                names=(),
                                timestamp=None):
     action = 'command/update'
     join_names = ','.join(map(str, names))
     join_network_ids = ','.join(map(str, network_ids))
     join_device_type_ids = ','.join(map(str, device_type_ids))
     if not timestamp:
         timestamp = self.server_timestamp
     auth_subscription_api_request = AuthSubscriptionApiRequest(self)
     auth_subscription_api_request.action(action)
     auth_subscription_api_request.url('device/command/poll')
     auth_subscription_api_request.param('returnUpdatedCommands', True)
     auth_subscription_api_request.param('deviceId', device_id)
     auth_subscription_api_request.param('networkIds', join_network_ids)
     auth_subscription_api_request.param('deviceTypeIds',
                                         join_device_type_ids)
     auth_subscription_api_request.param('names', join_names)
     auth_subscription_api_request.param('timestamp', timestamp)
     auth_subscription_api_request.response_timestamp_key('lastUpdated')
     auth_subscription_api_request.response_key('command')
     api_request = ApiRequest(self)
     api_request.action('command/subscribe')
     api_request.set('returnUpdatedCommands', True)
     api_request.set('deviceId', device_id)
     api_request.set('networkIds', network_ids)
     api_request.set('deviceTypeIds', device_type_ids)
     api_request.set('names', names)
     api_request.set('timestamp', timestamp)
     api_request.subscription_request(auth_subscription_api_request)
     return api_request.execute('Subscribe update commands failure.')
Пример #2
0
 def _subscribe_notifications(self,
                              device_id=None,
                              network_ids=(),
                              device_type_ids=(),
                              names=(),
                              timestamp=None):
     action = 'notification/insert'
     join_names = ','.join(map(str, names))
     join_network_ids = ','.join(map(str, network_ids))
     join_device_type_ids = ','.join(map(str, device_type_ids))
     if not timestamp:
         timestamp = self.server_timestamp
     auth_subscription_api_request = AuthSubscriptionApiRequest(self)
     auth_subscription_api_request.action(action)
     auth_subscription_api_request.url('device/notification/poll')
     auth_subscription_api_request.param('deviceId', device_id)
     auth_subscription_api_request.param('networkIds', join_network_ids)
     auth_subscription_api_request.param('deviceTypeIds',
                                         join_device_type_ids)
     auth_subscription_api_request.param('names', join_names)
     auth_subscription_api_request.param('timestamp', timestamp)
     auth_subscription_api_request.response_key('notification')
     api_request = ApiRequest(self)
     api_request.action('notification/subscribe')
     api_request.set('deviceId', device_id)
     api_request.set('networkIds', network_ids)
     api_request.set('deviceTypeIds', device_type_ids)
     api_request.set('names', names)
     api_request.set('timestamp', timestamp)
     api_request.subscription_request(auth_subscription_api_request)
     return api_request.execute('Subscribe notifications failure.')
Пример #3
0
 def subscribe_update_commands(self, names=None, timestamp=None):
     self._ensure_exists()
     action = 'command/update'
     self._ensure_subscription_not_exist(action)
     join_names = ','.join(names) if names else None
     if not timestamp:
         timestamp = self._api.server_timestamp
     auth_subscription_api_request = AuthSubscriptionApiRequest(self._api)
     auth_subscription_api_request.action(action)
     auth_subscription_api_request.url('device/{deviceId}/command/poll',
                                       deviceId=self._id)
     auth_subscription_api_request.param('returnUpdatedCommands', True)
     auth_subscription_api_request.param('names', join_names)
     auth_subscription_api_request.param('timestamp', timestamp)
     auth_subscription_api_request.response_timestamp_key('lastUpdated')
     auth_subscription_api_request.response_key('command')
     api_request = ApiRequest(self._api)
     api_request.action('command/subscribe')
     api_request.set('returnUpdatedCommands', True)
     api_request.set('deviceId', self._id)
     api_request.set('names', names)
     api_request.set('timestamp', timestamp)
     api_request.subscription_request(auth_subscription_api_request)
     subscription = api_request.execute(
         'Subscribe update commands failure.')
     self._subscription(action, subscription['subscriptionId'], names)
Пример #4
0
 def subscribe_insert_commands(self,
                               device_ids,
                               names=None,
                               timestamp=None):
     action = 'command/insert'
     self.ensure_subscription_not_exist(action, device_ids)
     join_device_ids = ','.join(device_ids)
     join_names = ','.join(names) if names else None
     if not timestamp:
         timestamp = self.server_timestamp
     auth_subscription_api_request = AuthSubscriptionApiRequest(self)
     auth_subscription_api_request.action(action)
     auth_subscription_api_request.url('device/command/poll')
     auth_subscription_api_request.param('deviceIds', join_device_ids)
     auth_subscription_api_request.param('names', join_names)
     auth_subscription_api_request.param('timestamp', timestamp)
     auth_subscription_api_request.response_key('command')
     api_request = ApiRequest(self)
     api_request.action('command/subscribe')
     api_request.set('deviceIds', device_ids)
     api_request.set('names', names)
     api_request.set('timestamp', timestamp)
     api_request.subscription_request(auth_subscription_api_request)
     subscription = api_request.execute(
         'Subscribe insert commands failure.')
     subscription_id = subscription['subscriptionId']
     self.subscription(action, subscription_id, device_ids, names)
Пример #5
0
 def subscribe_notifications(self, names=None, timestamp=None):
     self._ensure_exists()
     action = 'notification/insert'
     self._ensure_subscription_not_exist(action)
     join_names = ','.join(names) if names else None
     if not timestamp:
         timestamp = self._api.server_timestamp
     auth_subscription_api_request = AuthSubscriptionApiRequest(self._api)
     auth_subscription_api_request.action(action)
     auth_subscription_api_request.url(
         'device/{deviceId}/notification/poll', deviceId=self._id)
     auth_subscription_api_request.param('names', join_names)
     auth_subscription_api_request.param('timestamp', timestamp)
     auth_subscription_api_request.response_key('notification')
     api_request = ApiRequest(self._api)
     api_request.action('notification/subscribe')
     api_request.set('deviceId', self._id)
     api_request.set('names', names)
     api_request.set('timestamp', timestamp)
     api_request.subscription_request(auth_subscription_api_request)
     subscription = api_request.execute('Subscribe notifications failure.')
     self._subscription(action, subscription['subscriptionId'], names)