Commit 275094b4 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Common - Objects Factory:

- Improved definition of endpoint descriptors
parent d07e31ed
Loading
Loading
Loading
Loading
+14 −9
Original line number Diff line number Diff line
@@ -136,20 +136,25 @@ def json_device_tfs_disabled(
        device_uuid, DEVICE_TFS_TYPE, DEVICE_DISABLED, name=name, endpoints=endpoints, config_rules=config_rules,
        drivers=drivers)

def json_device_connect_rules(address : str, port : int, settings : Dict = {}):
def json_device_connect_rules(address : str, port : int, settings : Dict = {}) -> List[Dict]:
    return [
        json_config_rule_set('_connect/address',  address),
        json_config_rule_set('_connect/port',     port),
        json_config_rule_set('_connect/settings', settings),
    ]

def json_device_emulated_connect_rules(
        endpoint_descriptors : List[Tuple[str, str, List[int]]], address : str = DEVICE_EMU_ADDRESS,
        port : int = DEVICE_EMU_PORT
    ):
def json_endpoint_descriptor(
    endpoint_uuid : str, endpoint_type : str, endpoint_name : Optional[str] = None,
    sample_types : List[int] = [], location : Optional[Dict] = None
) -> Dict:
    result = {'uuid': endpoint_uuid, 'type': endpoint_type}
    if endpoint_name is not None: result['name'] = endpoint_name
    if sample_types is not None and len(sample_types) > 0: result['sample_types'] = sample_types
    if location is not None and len(location) > 0: result['location'] = location
    return result

    settings = {'endpoints': [
        {'uuid': endpoint_uuid, 'type': endpoint_type, 'sample_types': sample_types}
        for endpoint_uuid,endpoint_type,sample_types in endpoint_descriptors
    ]}
def json_device_emulated_connect_rules(
    endpoint_descriptors : List[Dict], address : str = DEVICE_EMU_ADDRESS, port : int = DEVICE_EMU_PORT
) -> List[Dict]:
    settings = {'endpoints': endpoint_descriptors}
    return json_device_connect_rules(address, port, settings=settings)