# coding: utf-8

"""
    ngsi-v2

    NGSI V2 API

    OpenAPI spec version: v2
    
    Generated by: https://github.com/swagger-api/swagger-codegen.git

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""

from __future__ import absolute_import

import sys
import os
import re

# python 2 and python 3 compatibility library
from six import iteritems

from ..configuration import Configuration
from ..api_client import ApiClient


class EntitiesApi(object):
    """
    NOTE: This class is auto generated by the swagger code generator program.
    Do not edit the class manually.
    Ref: https://github.com/swagger-api/swagger-codegen
    """

    def __init__(self, api_client=None):
        config = Configuration()
        if api_client:
            self.api_client = api_client
        else:
            if not config.api_client:
                config.api_client = ApiClient()
            self.api_client = config.api_client

    def create_entity(self, body, **kwargs):
        """
        
        The payload is an object representing the entity to be created. The object follows the JSON entity Representation format (described in a \"JSON Entity Representation\" section). Response: * Successful operation uses 201 Created. Reponse includes a `Location` header with the URL of the   created entity. * Errors use a non-2xx and (optionally) an error payload. See subsection on \"Error Responses\" for   more details.

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.create_entity(body, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param Entity body: JSON Entity Representation (required)
        :param str options: Options dictionary
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('callback'):
            return self.create_entity_with_http_info(body, **kwargs)
        else:
            (data) = self.create_entity_with_http_info(body, **kwargs)
            return data

    def create_entity_with_http_info(self, body, **kwargs):
        """
        
        The payload is an object representing the entity to be created. The object follows the JSON entity Representation format (described in a \"JSON Entity Representation\" section). Response: * Successful operation uses 201 Created. Reponse includes a `Location` header with the URL of the   created entity. * Errors use a non-2xx and (optionally) an error payload. See subsection on \"Error Responses\" for   more details.

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.create_entity_with_http_info(body, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param Entity body: JSON Entity Representation (required)
        :param str options: Options dictionary
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['body', 'options']
        all_params.append('callback')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method create_entity" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'body' is set
        if ('body' not in params) or (params['body'] is None):
            raise ValueError("Missing the required parameter `body` when calling `create_entity`")


        collection_formats = {}

        resource_path = '/entities'.replace('{format}', 'json')
        path_params = {}

        query_params = {}
        if 'options' in params:
            query_params['options'] = params['options']

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'body' in params:
            body_params = params['body']

        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept(['application/json'])
        if not header_params['Accept']:
            del header_params['Accept']

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.\
            select_header_content_type(['application/json'])

        # Authentication setting
        auth_settings = ['fiware_token']

        return self.api_client.call_api(resource_path, 'POST',
                                            path_params,
                                            query_params,
                                            header_params,
                                            body=body_params,
                                            post_params=form_params,
                                            files=local_var_files,
                                            response_type=None,
                                            auth_settings=auth_settings,
                                            callback=params.get('callback'),
                                            _return_http_data_only=params.get('_return_http_data_only'),
                                            _preload_content=params.get('_preload_content', True),
                                            _request_timeout=params.get('_request_timeout'),
                                            collection_formats=collection_formats)

    def list_entities(self, **kwargs):
        """
        
        Retrieves a list of entities that match different criteria by id, type, pattern matching (either id or type) and/or those which match a query or geographical query (see [Simple Query Language](#simple_query_language) and  [Geographical Queries](#geographical_queries)). A given entity has to match all the criteria to be retrieved (i.e., the criteria is combined in a logical AND way). Note that pattern matching query parameters are incompatible (i.e. mutually exclusive) with their corresponding exact matching parameters, i.e. `idPattern` with `id` and `typePattern` with `type`. The response payload is an array containing one object per matching entity. Each entity follows the JSON entity Representation format (described in \"JSON Entity Representation\" section).  Response code: * Successful operation uses 200 OK * Errors use a non-2xx and (optionally) an error payload. See subsection on \"Error Responses\" for   more details.

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.list_entities(callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str id: A comma-separated list of elements. Retrieve entities whose ID matches one of the elements in the list. Incompatible with idPattern.
        :param str type: comma-separated list of elements. Retrieve entities whose type matches one of the elements in the list. Incompatible with `typePattern`.
        :param str id_pattern: A correctly formated regular expression. Retrieve entities whose ID matches the regular expression. Incompatible with id.
        :param str type_pattern: A correctly formated regular expression. Retrieve entities whose type matches the regular expression. Incompatible with `type`.
        :param str q: A query expression, composed of a list of statements separated by `;`, i.e., q=statement;statements;statement. See [Simple Query Language specification](#simple_query_language).
        :param str mq: A query expression for attribute metadata, composed of a list of statements separated by `;`, i.e., mq=statement1;statement2;statement3. See [Simple Query Language specification](#simple_query_language).
        :param str georel: Spatial relationship between matching entities and a reference shape. See [Geographical Queries](#geographical_queries).
        :param str geometry: Geografical area to which the query is restricted. See [Geographical Queries](#geographical_queries).
        :param str coords: List of latitude-longitude pairs of coordinates separated by ';'. See [Geographical Queries](#geographical_queries).
        :param float limit: Limits the number of entities to be retrieved
        :param float offset: Establishes the offset from where entities are retrieved
        :param str attrs: Comma-separated list of attribute names whose data are to be included in the response. The attributes are retrieved in the order specified by this parameter. If this parameter is not included, the attributes are retrieved in arbitrary order.
        :param str order_by: Criteria for ordering results. See \"Ordering Results\" section for details.
        :param str options: Options dictionary
        :return: list[Entity]
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('callback'):
            return self.list_entities_with_http_info(**kwargs)
        else:
            (data) = self.list_entities_with_http_info(**kwargs)
            return data

    def list_entities_with_http_info(self, **kwargs):
        """
        
        Retrieves a list of entities that match different criteria by id, type, pattern matching (either id or type) and/or those which match a query or geographical query (see [Simple Query Language](#simple_query_language) and  [Geographical Queries](#geographical_queries)). A given entity has to match all the criteria to be retrieved (i.e., the criteria is combined in a logical AND way). Note that pattern matching query parameters are incompatible (i.e. mutually exclusive) with their corresponding exact matching parameters, i.e. `idPattern` with `id` and `typePattern` with `type`. The response payload is an array containing one object per matching entity. Each entity follows the JSON entity Representation format (described in \"JSON Entity Representation\" section).  Response code: * Successful operation uses 200 OK * Errors use a non-2xx and (optionally) an error payload. See subsection on \"Error Responses\" for   more details.

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.list_entities_with_http_info(callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str id: A comma-separated list of elements. Retrieve entities whose ID matches one of the elements in the list. Incompatible with idPattern.
        :param str type: comma-separated list of elements. Retrieve entities whose type matches one of the elements in the list. Incompatible with `typePattern`.
        :param str id_pattern: A correctly formated regular expression. Retrieve entities whose ID matches the regular expression. Incompatible with id.
        :param str type_pattern: A correctly formated regular expression. Retrieve entities whose type matches the regular expression. Incompatible with `type`.
        :param str q: A query expression, composed of a list of statements separated by `;`, i.e., q=statement;statements;statement. See [Simple Query Language specification](#simple_query_language).
        :param str mq: A query expression for attribute metadata, composed of a list of statements separated by `;`, i.e., mq=statement1;statement2;statement3. See [Simple Query Language specification](#simple_query_language).
        :param str georel: Spatial relationship between matching entities and a reference shape. See [Geographical Queries](#geographical_queries).
        :param str geometry: Geografical area to which the query is restricted. See [Geographical Queries](#geographical_queries).
        :param str coords: List of latitude-longitude pairs of coordinates separated by ';'. See [Geographical Queries](#geographical_queries).
        :param float limit: Limits the number of entities to be retrieved
        :param float offset: Establishes the offset from where entities are retrieved
        :param str attrs: Comma-separated list of attribute names whose data are to be included in the response. The attributes are retrieved in the order specified by this parameter. If this parameter is not included, the attributes are retrieved in arbitrary order.
        :param str order_by: Criteria for ordering results. See \"Ordering Results\" section for details.
        :param str options: Options dictionary
        :return: list[Entity]
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['id', 'type', 'id_pattern', 'type_pattern', 'q', 'mq', 'georel', 'geometry', 'coords', 'limit', 'offset', 'attrs', 'order_by', 'options']
        all_params.append('callback')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method list_entities" % key
                )
            params[key] = val
        del params['kwargs']


        collection_formats = {}

        resource_path = '/entities'.replace('{format}', 'json')
        path_params = {}

        query_params = {}
        if 'id' in params:
            query_params['id'] = params['id']
        if 'type' in params:
            query_params['type'] = params['type']
        if 'id_pattern' in params:
            query_params['idPattern'] = params['id_pattern']
        if 'type_pattern' in params:
            query_params['typePattern'] = params['type_pattern']
        if 'q' in params:
            query_params['q'] = params['q']
        if 'mq' in params:
            query_params['mq'] = params['mq']
        if 'georel' in params:
            query_params['georel'] = params['georel']
        if 'geometry' in params:
            query_params['geometry'] = params['geometry']
        if 'coords' in params:
            query_params['coords'] = params['coords']
        if 'limit' in params:
            query_params['limit'] = params['limit']
        if 'offset' in params:
            query_params['offset'] = params['offset']
        if 'attrs' in params:
            query_params['attrs'] = params['attrs']
        if 'order_by' in params:
            query_params['orderBy'] = params['order_by']
        if 'options' in params:
            query_params['options'] = params['options']

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None

        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept(['application/json'])
        if not header_params['Accept']:
            del header_params['Accept']

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.\
            select_header_content_type([])

        # Authentication setting
        auth_settings = ['fiware_token']

        return self.api_client.call_api(resource_path, 'GET',
                                            path_params,
                                            query_params,
                                            header_params,
                                            body=body_params,
                                            post_params=form_params,
                                            files=local_var_files,
                                            response_type='list[Entity]',
                                            auth_settings=auth_settings,
                                            callback=params.get('callback'),
                                            _return_http_data_only=params.get('_return_http_data_only'),
                                            _preload_content=params.get('_preload_content', True),
                                            _request_timeout=params.get('_request_timeout'),
                                            collection_formats=collection_formats)

    def remove_entity(self, entity_id, **kwargs):
        """
        
        Delete the entity. Response: * Successful operation uses 204 No Content * Errors use a non-2xx and (optionally) an error payload. See subsection on \"Error Responses\" for   more details.

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.remove_entity(entity_id, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str entity_id: Id of the entity to be deleted (required)
        :param str type: Entity type, to avoid ambiguity in the case there are several entities with the same entity id.
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('callback'):
            return self.remove_entity_with_http_info(entity_id, **kwargs)
        else:
            (data) = self.remove_entity_with_http_info(entity_id, **kwargs)
            return data

    def remove_entity_with_http_info(self, entity_id, **kwargs):
        """
        
        Delete the entity. Response: * Successful operation uses 204 No Content * Errors use a non-2xx and (optionally) an error payload. See subsection on \"Error Responses\" for   more details.

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.remove_entity_with_http_info(entity_id, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str entity_id: Id of the entity to be deleted (required)
        :param str type: Entity type, to avoid ambiguity in the case there are several entities with the same entity id.
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['entity_id', 'type']
        all_params.append('callback')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method remove_entity" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'entity_id' is set
        if ('entity_id' not in params) or (params['entity_id'] is None):
            raise ValueError("Missing the required parameter `entity_id` when calling `remove_entity`")


        collection_formats = {}

        resource_path = '/entities/{entityId}'.replace('{format}', 'json')
        path_params = {}
        if 'entity_id' in params:
            path_params['entityId'] = params['entity_id']

        query_params = {}
        if 'type' in params:
            query_params['type'] = params['type']

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None

        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept(['application/json'])
        if not header_params['Accept']:
            del header_params['Accept']

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.\
            select_header_content_type([])

        # Authentication setting
        auth_settings = ['fiware_token']

        return self.api_client.call_api(resource_path, 'DELETE',
                                            path_params,
                                            query_params,
                                            header_params,
                                            body=body_params,
                                            post_params=form_params,
                                            files=local_var_files,
                                            response_type=None,
                                            auth_settings=auth_settings,
                                            callback=params.get('callback'),
                                            _return_http_data_only=params.get('_return_http_data_only'),
                                            _preload_content=params.get('_preload_content', True),
                                            _request_timeout=params.get('_request_timeout'),
                                            collection_formats=collection_formats)

    def replace_all_entity_attributes(self, entity_id, body, **kwargs):
        """
        
        The request payload is an object representing the new entity attributes. The object follows the JSON entity Representation format (described in a \"JSON Entity Representation\" above), except that `id` and `type` are not allowed. The attributes previously existing in the entity are removed and replaced by the ones in the request. Response: * Successful operation uses 204 No Content * Errors use a non-2xx and (optionally) an error payload. See subsection on \"Error Responses\" for   more details.

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.replace_all_entity_attributes(entity_id, body, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str entity_id: Id of the entity in question. (required)
        :param Attribute body: JSON Attribute Representation (required)
        :param str type: Entity type, to avoid ambiguity in the case there are several entities with the same entity id.
        :param str options: Operations options
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('callback'):
            return self.replace_all_entity_attributes_with_http_info(entity_id, body, **kwargs)
        else:
            (data) = self.replace_all_entity_attributes_with_http_info(entity_id, body, **kwargs)
            return data

    def replace_all_entity_attributes_with_http_info(self, entity_id, body, **kwargs):
        """
        
        The request payload is an object representing the new entity attributes. The object follows the JSON entity Representation format (described in a \"JSON Entity Representation\" above), except that `id` and `type` are not allowed. The attributes previously existing in the entity are removed and replaced by the ones in the request. Response: * Successful operation uses 204 No Content * Errors use a non-2xx and (optionally) an error payload. See subsection on \"Error Responses\" for   more details.

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.replace_all_entity_attributes_with_http_info(entity_id, body, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str entity_id: Id of the entity in question. (required)
        :param Attribute body: JSON Attribute Representation (required)
        :param str type: Entity type, to avoid ambiguity in the case there are several entities with the same entity id.
        :param str options: Operations options
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['entity_id', 'body', 'type', 'options']
        all_params.append('callback')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method replace_all_entity_attributes" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'entity_id' is set
        if ('entity_id' not in params) or (params['entity_id'] is None):
            raise ValueError("Missing the required parameter `entity_id` when calling `replace_all_entity_attributes`")
        # verify the required parameter 'body' is set
        if ('body' not in params) or (params['body'] is None):
            raise ValueError("Missing the required parameter `body` when calling `replace_all_entity_attributes`")


        collection_formats = {}

        resource_path = '/entities/{entityId}/attrs'.replace('{format}', 'json')
        path_params = {}
        if 'entity_id' in params:
            path_params['entityId'] = params['entity_id']

        query_params = {}
        if 'type' in params:
            query_params['type'] = params['type']
        if 'options' in params:
            query_params['options'] = params['options']

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'body' in params:
            body_params = params['body']

        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept(['application/json'])
        if not header_params['Accept']:
            del header_params['Accept']

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.\
            select_header_content_type(['application/json'])

        # Authentication setting
        auth_settings = ['fiware_token']

        return self.api_client.call_api(resource_path, 'PUT',
                                            path_params,
                                            query_params,
                                            header_params,
                                            body=body_params,
                                            post_params=form_params,
                                            files=local_var_files,
                                            response_type=None,
                                            auth_settings=auth_settings,
                                            callback=params.get('callback'),
                                            _return_http_data_only=params.get('_return_http_data_only'),
                                            _preload_content=params.get('_preload_content', True),
                                            _request_timeout=params.get('_request_timeout'),
                                            collection_formats=collection_formats)

    def retrieve_entity(self, entity_id, **kwargs):
        """
        
        The response is an object representing the entity identified by the ID. The object follows the JSON entity Representation format (described in \"JSON Entity Representation\" section). This operation must return one entity element only, but there may be more than one entity with the same ID (e.g. entities with same ID but different types). In such case, an error message is returned, with the HTTP status code set to 409 Conflict. Response: * Successful operation uses 200 OK * Errors use a non-2xx and (optionally) an error payload. See subsection on \"Error Responses\" for more details.

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.retrieve_entity(entity_id, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str entity_id: Id of the entity to be retrieved (required)
        :param str type: Entity type, to avoid ambiguity in case there are several entities with the same entity id.
        :param str attrs: Comma-separated list of attribute names whose data must be included in the response. The attributes are retrieved in the order specified by this parameter. If this parameter is not included, the attributes are retrieved in arbitrary order, and all the attributes of the entity are included in the response.
        :param str options: Options dictionary
        :return: Entity
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('callback'):
            return self.retrieve_entity_with_http_info(entity_id, **kwargs)
        else:
            (data) = self.retrieve_entity_with_http_info(entity_id, **kwargs)
            return data

    def retrieve_entity_with_http_info(self, entity_id, **kwargs):
        """
        
        The response is an object representing the entity identified by the ID. The object follows the JSON entity Representation format (described in \"JSON Entity Representation\" section). This operation must return one entity element only, but there may be more than one entity with the same ID (e.g. entities with same ID but different types). In such case, an error message is returned, with the HTTP status code set to 409 Conflict. Response: * Successful operation uses 200 OK * Errors use a non-2xx and (optionally) an error payload. See subsection on \"Error Responses\" for more details.

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.retrieve_entity_with_http_info(entity_id, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str entity_id: Id of the entity to be retrieved (required)
        :param str type: Entity type, to avoid ambiguity in case there are several entities with the same entity id.
        :param str attrs: Comma-separated list of attribute names whose data must be included in the response. The attributes are retrieved in the order specified by this parameter. If this parameter is not included, the attributes are retrieved in arbitrary order, and all the attributes of the entity are included in the response.
        :param str options: Options dictionary
        :return: Entity
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['entity_id', 'type', 'attrs', 'options']
        all_params.append('callback')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method retrieve_entity" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'entity_id' is set
        if ('entity_id' not in params) or (params['entity_id'] is None):
            raise ValueError("Missing the required parameter `entity_id` when calling `retrieve_entity`")


        collection_formats = {}

        resource_path = '/entities/{entityId}'.replace('{format}', 'json')
        path_params = {}
        if 'entity_id' in params:
            path_params['entityId'] = params['entity_id']

        query_params = {}
        if 'type' in params:
            query_params['type'] = params['type']
        if 'attrs' in params:
            query_params['attrs'] = params['attrs']
        if 'options' in params:
            query_params['options'] = params['options']

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None

        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept(['application/json'])
        if not header_params['Accept']:
            del header_params['Accept']

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.\
            select_header_content_type([])

        # Authentication setting
        auth_settings = ['fiware_token']

        return self.api_client.call_api(resource_path, 'GET',
                                            path_params,
                                            query_params,
                                            header_params,
                                            body=body_params,
                                            post_params=form_params,
                                            files=local_var_files,
                                            response_type='Entity',
                                            auth_settings=auth_settings,
                                            callback=params.get('callback'),
                                            _return_http_data_only=params.get('_return_http_data_only'),
                                            _preload_content=params.get('_preload_content', True),
                                            _request_timeout=params.get('_request_timeout'),
                                            collection_formats=collection_formats)

    def retrieve_entity_attributes(self, entity_id, **kwargs):
        """
        
        This request is similar to retreiving the whole entity, however this one omits the `id` and `type` fields. Just like the general request of getting an entire entity, this operation must return only one entity element. If more than one entity with the same ID is found (e.g. entities with same ID but different type), an error message is returned, with the HTTP status code set to 409 Conflict. Response: * Successful operation uses 200 OK * Errors use a non-2xx and (optionally) an error payload. See subsection on \"Error Responses\" for   more details.

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.retrieve_entity_attributes(entity_id, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str entity_id: Id of the entity to be retrieved (required)
        :param str type: Entity type, to avoid ambiguity in the case there are several entities with the same entity id.
        :param str attrs: Comma-separated list of attribute names whose data are to be included in the response. The attributes are retrieved in the order specified by this parameter. If this parameter is not included, the attributes are retrieved in arbitrary order, and all the attributes of the entity are included in the response.
        :param str options: Options dictionary
        :return: Attribute
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('callback'):
            return self.retrieve_entity_attributes_with_http_info(entity_id, **kwargs)
        else:
            (data) = self.retrieve_entity_attributes_with_http_info(entity_id, **kwargs)
            return data

    def retrieve_entity_attributes_with_http_info(self, entity_id, **kwargs):
        """
        
        This request is similar to retreiving the whole entity, however this one omits the `id` and `type` fields. Just like the general request of getting an entire entity, this operation must return only one entity element. If more than one entity with the same ID is found (e.g. entities with same ID but different type), an error message is returned, with the HTTP status code set to 409 Conflict. Response: * Successful operation uses 200 OK * Errors use a non-2xx and (optionally) an error payload. See subsection on \"Error Responses\" for   more details.

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.retrieve_entity_attributes_with_http_info(entity_id, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str entity_id: Id of the entity to be retrieved (required)
        :param str type: Entity type, to avoid ambiguity in the case there are several entities with the same entity id.
        :param str attrs: Comma-separated list of attribute names whose data are to be included in the response. The attributes are retrieved in the order specified by this parameter. If this parameter is not included, the attributes are retrieved in arbitrary order, and all the attributes of the entity are included in the response.
        :param str options: Options dictionary
        :return: Attribute
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['entity_id', 'type', 'attrs', 'options']
        all_params.append('callback')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method retrieve_entity_attributes" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'entity_id' is set
        if ('entity_id' not in params) or (params['entity_id'] is None):
            raise ValueError("Missing the required parameter `entity_id` when calling `retrieve_entity_attributes`")


        collection_formats = {}

        resource_path = '/entities/{entityId}/attrs'.replace('{format}', 'json')
        path_params = {}
        if 'entity_id' in params:
            path_params['entityId'] = params['entity_id']

        query_params = {}
        if 'type' in params:
            query_params['type'] = params['type']
        if 'attrs' in params:
            query_params['attrs'] = params['attrs']
        if 'options' in params:
            query_params['options'] = params['options']

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None

        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept(['application/json'])
        if not header_params['Accept']:
            del header_params['Accept']

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.\
            select_header_content_type([])

        # Authentication setting
        auth_settings = ['fiware_token']

        return self.api_client.call_api(resource_path, 'GET',
                                            path_params,
                                            query_params,
                                            header_params,
                                            body=body_params,
                                            post_params=form_params,
                                            files=local_var_files,
                                            response_type='Attribute',
                                            auth_settings=auth_settings,
                                            callback=params.get('callback'),
                                            _return_http_data_only=params.get('_return_http_data_only'),
                                            _preload_content=params.get('_preload_content', True),
                                            _request_timeout=params.get('_request_timeout'),
                                            collection_formats=collection_formats)

    def update_existing_entity_attributes(self, entity_id, body, **kwargs):
        """
        
        The request payload is an object representing the attributes to update. The object follows the JSON entity Representation format (described in \"JSON Entity Representation\" section), except that `id` and `type` are not allowed. The entity attributes are updated with the ones in the payload. In addition to that, if one or more attributes in the payload doesn't exist in the entity, an error is returned. Response: * Successful operation uses 204 No Content * Errors use a non-2xx and (optionally) an error payload. See subsection on \"Error Responses\" for   more details.

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.update_existing_entity_attributes(entity_id, body, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str entity_id: Id of the entity to be updated (required)
        :param Attribute body: JSON Attribute Representation (required)
        :param str type: Entity type, to avoid ambiguity in case there are several entities with the same entity id.
        :param str options: Operations options
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('callback'):
            return self.update_existing_entity_attributes_with_http_info(entity_id, body, **kwargs)
        else:
            (data) = self.update_existing_entity_attributes_with_http_info(entity_id, body, **kwargs)
            return data

    def update_existing_entity_attributes_with_http_info(self, entity_id, body, **kwargs):
        """
        
        The request payload is an object representing the attributes to update. The object follows the JSON entity Representation format (described in \"JSON Entity Representation\" section), except that `id` and `type` are not allowed. The entity attributes are updated with the ones in the payload. In addition to that, if one or more attributes in the payload doesn't exist in the entity, an error is returned. Response: * Successful operation uses 204 No Content * Errors use a non-2xx and (optionally) an error payload. See subsection on \"Error Responses\" for   more details.

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.update_existing_entity_attributes_with_http_info(entity_id, body, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str entity_id: Id of the entity to be updated (required)
        :param Attribute body: JSON Attribute Representation (required)
        :param str type: Entity type, to avoid ambiguity in case there are several entities with the same entity id.
        :param str options: Operations options
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['entity_id', 'body', 'type', 'options']
        all_params.append('callback')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method update_existing_entity_attributes" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'entity_id' is set
        if ('entity_id' not in params) or (params['entity_id'] is None):
            raise ValueError("Missing the required parameter `entity_id` when calling `update_existing_entity_attributes`")
        # verify the required parameter 'body' is set
        if ('body' not in params) or (params['body'] is None):
            raise ValueError("Missing the required parameter `body` when calling `update_existing_entity_attributes`")


        collection_formats = {}

        resource_path = '/entities/{entityId}/attrs'.replace('{format}', 'json')
        path_params = {}
        if 'entity_id' in params:
            path_params['entityId'] = params['entity_id']

        query_params = {}
        if 'type' in params:
            query_params['type'] = params['type']
        if 'options' in params:
            query_params['options'] = params['options']

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'body' in params:
            body_params = params['body']

        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept(['application/json'])
        if not header_params['Accept']:
            del header_params['Accept']

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.\
            select_header_content_type(['application/json'])

        # Authentication setting
        auth_settings = ['fiware_token']

        return self.api_client.call_api(resource_path, 'PATCH',
                                            path_params,
                                            query_params,
                                            header_params,
                                            body=body_params,
                                            post_params=form_params,
                                            files=local_var_files,
                                            response_type=None,
                                            auth_settings=auth_settings,
                                            callback=params.get('callback'),
                                            _return_http_data_only=params.get('_return_http_data_only'),
                                            _preload_content=params.get('_preload_content', True),
                                            _request_timeout=params.get('_request_timeout'),
                                            collection_formats=collection_formats)

    def update_or_append_entity_attributes(self, entity_id, body, **kwargs):
        """
        
        The request payload is an object representing the attributes to append or update. The object follows the JSON entity Representation format (described in \"JSON Entity Representation\" section), except that `id` and `type` are not allowed. The entity attributes are updated with the ones in the payload, depending on whether the `append` operation option is used or not. * If `append` is not used: the entity attributes are updated (if they previously exist) or appended   (if they don't previously exist) with the ones in the payload. * If `append` is used (i.e. strict append semantics): all the attributes in the payload not   previously existing in the entity are appended. In addition to that, in case some of the   attributes in the payload already exist in the entity, an error is returned. Response: * Successful operation uses 204 No Content * Errors use a non-2xx and (optionally) an error payload. See subsection on \"Error Responses\" for   more details.

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.update_or_append_entity_attributes(entity_id, body, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str entity_id: Entity id to be updated (required)
        :param Attribute body: JSON Attribute Representation (required)
        :param str type: Entity type, to avoid ambiguity in case there are several entities with the same entity id.
        :param str options: Operations options
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('callback'):
            return self.update_or_append_entity_attributes_with_http_info(entity_id, body, **kwargs)
        else:
            (data) = self.update_or_append_entity_attributes_with_http_info(entity_id, body, **kwargs)
            return data

    def update_or_append_entity_attributes_with_http_info(self, entity_id, body, **kwargs):
        """
        
        The request payload is an object representing the attributes to append or update. The object follows the JSON entity Representation format (described in \"JSON Entity Representation\" section), except that `id` and `type` are not allowed. The entity attributes are updated with the ones in the payload, depending on whether the `append` operation option is used or not. * If `append` is not used: the entity attributes are updated (if they previously exist) or appended   (if they don't previously exist) with the ones in the payload. * If `append` is used (i.e. strict append semantics): all the attributes in the payload not   previously existing in the entity are appended. In addition to that, in case some of the   attributes in the payload already exist in the entity, an error is returned. Response: * Successful operation uses 204 No Content * Errors use a non-2xx and (optionally) an error payload. See subsection on \"Error Responses\" for   more details.

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please define a `callback` function
        to be invoked when receiving the response.
        >>> def callback_function(response):
        >>>     pprint(response)
        >>>
        >>> thread = api.update_or_append_entity_attributes_with_http_info(entity_id, body, callback=callback_function)

        :param callback function: The callback function
            for asynchronous request. (optional)
        :param str entity_id: Entity id to be updated (required)
        :param Attribute body: JSON Attribute Representation (required)
        :param str type: Entity type, to avoid ambiguity in case there are several entities with the same entity id.
        :param str options: Operations options
        :return: None
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['entity_id', 'body', 'type', 'options']
        all_params.append('callback')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method update_or_append_entity_attributes" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'entity_id' is set
        if ('entity_id' not in params) or (params['entity_id'] is None):
            raise ValueError("Missing the required parameter `entity_id` when calling `update_or_append_entity_attributes`")
        # verify the required parameter 'body' is set
        if ('body' not in params) or (params['body'] is None):
            raise ValueError("Missing the required parameter `body` when calling `update_or_append_entity_attributes`")


        collection_formats = {}

        resource_path = '/entities/{entityId}/attrs'.replace('{format}', 'json')
        path_params = {}
        if 'entity_id' in params:
            path_params['entityId'] = params['entity_id']

        query_params = {}
        if 'type' in params:
            query_params['type'] = params['type']
        if 'options' in params:
            query_params['options'] = params['options']

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'body' in params:
            body_params = params['body']

        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept(['application/json'])
        if not header_params['Accept']:
            del header_params['Accept']

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.\
            select_header_content_type(['application/json'])

        # Authentication setting
        auth_settings = ['fiware_token']

        return self.api_client.call_api(resource_path, 'POST',
                                            path_params,
                                            query_params,
                                            header_params,
                                            body=body_params,
                                            post_params=form_params,
                                            files=local_var_files,
                                            response_type=None,
                                            auth_settings=auth_settings,
                                            callback=params.get('callback'),
                                            _return_http_data_only=params.get('_return_http_data_only'),
                                            _preload_content=params.get('_preload_content', True),
                                            _request_timeout=params.get('_request_timeout'),
                                            collection_formats=collection_formats)
