Scheduled maintenance on Saturday, 27 September 2025, from 07:00 AM to 4:00 PM GMT (09:00 AM to 6:00 PM CEST) - some services may be unavailable -

Skip to content
Snippets Groups Projects
LinkEndpoint.py 2.28 KiB
Newer Older
  • Learn to ignore specific revisions
  • Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    from __future__ import annotations
    from typing import TYPE_CHECKING, Dict
    from ..entity._Entity import _Entity
    from .Endpoint import Endpoint
    from .Keys import KEY_LINK_ENDPOINT
    
    if TYPE_CHECKING:
        from .Context import Context
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
        from .Topology import Topology
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
        from .Link import Link
    
    VALIDATORS = {
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
        'device_uuid': lambda v: v is not None and isinstance(v, str) and (len(v) > 0),
        'endpoint_uuid': lambda v: v is not None and isinstance(v, str) and (len(v) > 0),
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    TRANSCODERS = {} # no transcoding applied to attributes
    
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    class LinkEndpoint(_Entity):
        def __init__(self, link_endpoint_uuid : str, parent : 'Link'):
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
            super().__init__(parent, link_endpoint_uuid, KEY_LINK_ENDPOINT, VALIDATORS, TRANSCODERS)
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    
        @property
        def parent(self) -> 'Link': return self._parent
    
        @property
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
        def context(self) -> 'Context': return self.parent.context
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    
        @property
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
        def context_uuid(self) -> str: return self.parent.context_uuid
    
        @property
        def topology(self) -> 'Topology': return self.parent.topology
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    
        @property
        def topology_uuid(self) -> str: return self.parent.topology_uuid
    
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
        @property
        def link(self) -> 'Link': return self.parent
    
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
        @property
        def link_uuid(self) -> str: return self.parent.link_uuid
    
        @property
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
        def link_endpoint_uuid(self) -> str: return self._entity_uuid
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    
        def create(self, endpoint : Endpoint) -> 'LinkEndpoint':
            self.update(update_attributes={
                'device_uuid': endpoint.device_uuid,
                'endpoint_uuid': endpoint.endpoint_uuid,
            })
            self.parent.endpoints.add(self.link_endpoint_uuid)
            return self
    
        def update(self, update_attributes={}, remove_attributes=[]) -> 'LinkEndpoint':
            self.attributes.update(update_attributes=update_attributes, remove_attributes=remove_attributes)
            return self
    
        def delete(self) -> None:
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
            self.attributes.delete()
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
            self.parent.endpoints.delete(self.link_endpoint_uuid)
    
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
        def dump_id(self) -> Dict:
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
            attributes = self.attributes.get()
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
            device_uuid = attributes.get('device_uuid', None)
            endpoint_uuid = attributes.get('endpoint_uuid', None)
            endpoint = self.topology.device(device_uuid).endpoint(endpoint_uuid)
            return endpoint.dump_id()
    
        def dump(self) -> Dict:
            return self.dump_id()