platypush/backend/__init__.py
def register_service(self,
                         port: Optional[int] = None,
                         name: Optional[str] = None,
                         srv_type: Optional[str] = None,
                         srv_name: Optional[str] = None,
                         udp: bool = False,
                         properties: Optional[Dict] = None):
        """
        Initialize the Zeroconf service configuration for this backend.

        :param port: Service listen port (default: the backend ``port`` attribute if available, or ``None``).
        :param name: Service short name (default: backend name).
        :param srv_type: Service type (default: ``_platypush-{name}._{proto}.local.``).
        :param srv_name: Full service name (default: ``{hostname or device_id}.{type}``).
        :param udp: Set to True if this is a UDP service.
        :param properties: Extra properties to be passed on the service. Default:

            .. code-block:: json

                {
                    "name": "Platypush",
                    "vendor": "Platypush",
                    "version": "{platypush_version}"
                }

        """
        try:
            from zeroconf import ServiceInfo, Zeroconf
            from platypush.plugins.zeroconf import ZeroconfListener
        except ImportError:
            self.logger.warning('zeroconf package not available, service discovery will be disabled.')
            return

        self.zeroconf = Zeroconf()
        srv_desc = {
            'name': 'Platypush',
            'vendor': 'Platypush',
            'version': __version__,
            **(properties or {}),
        }

        name = name or re.sub(r'Backend$', '', self.__class__.__name__).lower()
        srv_type = srv_type or '_platypush-{name}._{proto}.local.'.format(name=name, proto='udp' if udp else 'tcp')
        srv_name = srv_name or '{host}.{type}'.format(host=self.device_id, type=srv_type)

        if port:
            srv_port = port
        else:
            srv_port = self.port if hasattr(self, 'port') else None

        self.zeroconf_info = ServiceInfo(srv_type, srv_name,
                                         addresses=[socket.inet_aton(self._get_ip())],
                                         port=srv_port,
                                         weight=0,
                                         priority=0,
                                         properties=srv_desc)

        if not self.zeroconf_info:
            self.logger.warning('Could not register Zeroconf service')
            return

        self.zeroconf.register_service(self.zeroconf_info)
        self.bus.post(ZeroconfServiceAddedEvent(service_type=srv_type, service_name=srv_name,
                                                service_info=ZeroconfListener.parse_service_info(self.zeroconf_info)))

        Initialize the Zeroconf service configuration for this backend.

        :param port: Service listen port (default: the backend ``port`` attribute if available, or ``None``).
        :param name: Service short name (default: backend name).
        :param srv_type: Service type (default: ``_platypush-{name}._{proto}.local.``).
        :param srv_name: Full service name (default: ``{hostname or device_id}.{type}``).
        :param udp: Set to True if this is a UDP service.
        :param properties: Extra properties to be passed on the service. Default:

            .. code-block:: json

                {
                    "name": "Platypush",
                    "vendor": "Platypush",
                    "version": "{platypush_version}"
                }

        
Initialize the Zeroconf service configuration for this backend.
Initialize the Zeroconf service configuration for this backend .
def register_service(self,
                         port: Optional[int] = None,
                         name: Optional[str] = None,
                         srv_type: Optional[str] = None,
                         srv_name: Optional[str] = None,
                         udp: bool = False,
                         properties: Optional[Dict] = None):
        try:
            from zeroconf import ServiceInfo, Zeroconf
            from platypush.plugins.zeroconf import ZeroconfListener
        except ImportError:
            self.logger.warning('zeroconf package not available, service discovery will be disabled.')
            return
        self.zeroconf = Zeroconf()
        srv_desc = {
            'name': 'Platypush',
            'vendor': 'Platypush',
            'version': __version__,
            **(properties or {}),
        }
        name = name or re.sub(r'Backend$', '', self.__class__.__name__).lower()
        srv_type = srv_type or '_platypush-{name}._{proto}.local.'.format(name=name, proto='udp' if udp else 'tcp')
        srv_name = srv_name or '{host}.{type}'.format(host=self.device_id, type=srv_type)
        if port:
            srv_port = port
        else:
            srv_port = self.port if hasattr(self, 'port') else None
        self.zeroconf_info = ServiceInfo(srv_type, srv_name,
                                         addresses=[socket.inet_aton(self._get_ip())],
                                         port=srv_port,
                                         weight=0,
                                         priority=0,
                                         properties=srv_desc)
        if not self.zeroconf_info:
            self.logger.warning('Could not register Zeroconf service')
            return
        self.zeroconf.register_service(self.zeroconf_info)
        self.bus.post(ZeroconfServiceAddedEvent(service_type=srv_type, service_name=srv_name,
                                                service_info=ZeroconfListener.parse_service_info(self.zeroconf_info)))
def register_service ( self , port : Optional [ int ] = None , name : Optional [ str ] = None , srv_type : Optional [ str ] = None , srv_name : Optional [ str ] = None , udp : bool = False , properties : Optional [ Dict ] = None ) : try : from zeroconf import ServiceInfo , Zeroconf from platypush . plugins . zeroconf import ZeroconfListener except ImportError : self . logger . warning ( 'zeroconf package not available, service discovery will be disabled.' ) return self . zeroconf = Zeroconf ( ) srv_desc = { 'name' : 'Platypush' , 'vendor' : 'Platypush' , 'version' : __version__ , ** ( properties or { } ) , } name = name or re . sub ( r'Backend$' , '' , self . __class__ . __name__ ) . lower ( ) srv_type = srv_type or '_platypush-{name}._{proto}.local.' . format ( name = name , proto = 'udp' if udp else 'tcp' ) srv_name = srv_name or '{host}.{type}' . format ( host = self . device_id , type = srv_type ) if port : srv_port = port else : srv_port = self . port if hasattr ( self , 'port' ) else None self . zeroconf_info = ServiceInfo ( srv_type , srv_name , addresses = [ socket . inet_aton ( self . _get_ip ( ) ) ] , port = srv_port , weight = 0 , priority = 0 , properties = srv_desc ) if not self . zeroconf_info : self . logger . warning ( 'Could not register Zeroconf service' ) return self . zeroconf . register_service ( self . zeroconf_info ) self . bus . post ( ZeroconfServiceAddedEvent ( service_type = srv_type , service_name = srv_name , service_info = ZeroconfListener . parse_service_info ( self . zeroconf_info ) ) )
Initialize the Zeroconf service configuration for this backend.
Initialize the Zeroconf service configuration for this backend .
"""
        Initialize the Zeroconf service configuration for this backend.

        :param port: Service listen port (default: the backend ``port`` attribute if available, or ``None``).
        :param name: Service short name (default: backend name).
        :param srv_type: Service type (default: ``_platypush-{name}._{proto}.local.``).
        :param srv_name: Full service name (default: ``{hostname or device_id}.{type}``).
        :param udp: Set to True if this is a UDP service.
        :param properties: Extra properties to be passed on the service. Default:

            .. code-block:: json

                {
                    "name": "Platypush",
                    "vendor": "Platypush",
                    "version": "{platypush_version}"
                }

        """
self
port
Optional[int]
Service listen port (default: the backend ``port`` attribute if available, or ``None``).
Service listen port ( default : the backend ` ` port ` ` attribute if available or ` ` None ` ` ) .
name
Optional[str]
Service short name (default: backend name).
Service short name ( default : backend name ) .
srv_type
Optional[str]
Service type (default: ``_platypush-{name}._{proto}.local.``).
Service type ( default : ` ` _platypush - { name } . _ { proto } . local . ` ` ) .
srv_name
Optional[str]
Full service name (default: ``{hostname or device_id}.{type}``).
Full service name ( default : ` ` { hostname or device_id } . { type } ` ` ) .
udp
bool
Set to True if this is a UDP service.
Set to True if this is a UDP service .
properties
Optional[Dict]
Extra properties to be passed on the service. Default:
code-block:: json

{
"name": "Platypush",
"vendor": "Platypush",
"version": "{platypush_version}"
}
Extra properties to be passed on the service . Default : code - block :: json { " name " : " Platypush " " vendor " : " Platypush " " version " : " { platypush_version } " }