Пример #1
0
 def remove(self):
     self._ensure_exists()
     remove_subscription_api_request = RemoveSubscriptionApiRequest()
     remove_subscription_api_request.subscription_id(self._id)
     api_request = ApiRequest(self._api)
     api_request.action('%s/unsubscribe' % self._get_subscription_type())
     api_request.set('subscriptionId', self._id)
     api_request.remove_subscription_request(
         remove_subscription_api_request)
     api_request.execute('Unsubscribe failure.')
     self._id = None
Пример #2
0
 def unsubscribe_notifications(self):
     self._ensure_exists()
     action = 'notification/insert'
     self._ensure_subscription_exists(action)
     subscription_id = self._subscription_id(action)
     remove_subscription_api_request = RemoveSubscriptionApiRequest()
     remove_subscription_api_request.subscription_id(subscription_id)
     api_request = ApiRequest(self._api)
     api_request.action('notification/unsubscribe')
     api_request.set('subscriptionId', subscription_id)
     api_request.remove_subscription_request(
         remove_subscription_api_request)
     api_request.execute('Unsubscribe notifications failure.')
     self._remove_subscription(action, subscription_id)
Пример #3
0
 def unsubscribe_update_commands(self):
     self._ensure_exists()
     action = 'command/update'
     self._ensure_subscription_exists(action)
     subscription_id = self._subscription_id(action)
     remove_subscription_api_request = RemoveSubscriptionApiRequest()
     remove_subscription_api_request.subscription_id(subscription_id)
     api_request = ApiRequest(self._api)
     api_request.action('command/unsubscribe')
     api_request.set('subscriptionId', subscription_id)
     api_request.remove_subscription_request(
         remove_subscription_api_request)
     api_request.execute('Unsubscribe update commands failure.')
     self._remove_subscription(action, subscription_id)
Пример #4
0
 def _auth(self):
     api_request = ApiRequest(self._api)
     if not api_request.websocket_transport:
         return
     api_request.action('authenticate')
     api_request.set('token', self._access_token)
     api_request.execute('Authentication failure.')
Пример #5
0
 def get_info(self):
     api_request = ApiRequest(self)
     api_request.url('info')
     api_request.action('server/info')
     api_request.response_key('info')
     info = api_request.execute('Info get failure.')
     return {
         'api_version': info['apiVersion'],
         'server_timestamp': info['serverTimestamp'],
         'rest_server_url': info.get('restServerUrl'),
         'websocket_server_url': info.get('webSocketServerUrl')
     }
Пример #6
0
 def unsubscribe_notifications(self, device_ids):
     action = 'notification/insert'
     self.ensure_subscription_exists(action, device_ids)
     subscription_ids, subscription_calls = self._unsubscribe(
         action, device_ids)
     for subscription_id in subscription_ids:
         remove_subscription_api_request = RemoveSubscriptionApiRequest()
         remove_subscription_api_request.subscription_id(subscription_id)
         api_request = ApiRequest(self)
         api_request.action('notification/unsubscribe')
         api_request.set('subscriptionId', subscription_id)
         api_request.remove_subscription_request(
             remove_subscription_api_request)
         api_request.execute('Unsubscribe notifications failure.')
         self.remove_subscription(action, subscription_id)
     timestamp = self.get_info()['server_timestamp']
     for subscription_call in subscription_calls:
         subscription_call['timestamp'] = timestamp
         self.subscribe_notifications(**subscription_call)
Пример #7
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.')
Пример #8
0
 def get_cluster_info(self):
     api_request = ApiRequest(self)
     api_request.url('info/config/cluster')
     api_request.action('cluster/info')
     api_request.response_key('clusterInfo')
     return api_request.execute('Cluster info get failure.')
Пример #9
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.')
Пример #10
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)
Пример #11
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)
Пример #12
0
 def refresh(self):
     if not self._refresh_token:
         raise TokenError('Can\'t refresh token without "refresh_token"')
     api_request = ApiRequest(self._api)
     api_request.method('POST')
     api_request.url('token/refresh')
     api_request.action('token/refresh')
     api_request.set('refreshToken', self._refresh_token)
     tokens = api_request.execute('Token refresh failure.')
     self._access_token = tokens['accessToken']
Пример #13
0
 def _tokens(self):
     api_request = ApiRequest(self._api)
     api_request.method('POST')
     api_request.url('token')
     api_request.action('token')
     api_request.set('login', self._login)
     api_request.set('password', self._password)
     tokens = api_request.execute('Login failure.')
     self._refresh_token = tokens['refreshToken']
     self._access_token = tokens['accessToken']
Пример #14
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)
Пример #15
0
 def refresh(self):
     api_request = ApiRequest(self._api)
     api_request.method('POST')
     api_request.url('token/refresh')
     api_request.action('token/refresh')
     api_request.set('refreshToken', self._refresh_token)
     tokens = api_request.execute('Token refresh failure.')
     self._access_token = tokens['accessToken']