connectors/PYRO_dialog.py
author Edouard Tisserant
Wed, 01 Jul 2020 10:36:20 +0200
changeset 2686 703ebf57508a
parent 2609 c8cb60bf6c6a
child 3750 f62625418bff
permissions -rw-r--r--
Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.

Websettings for modbus and bacnet are now passed to runtime as python files loaded (execfile) at init of PLCObject with the same globals.
Because if this, same names used in previously different modules now colide.
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# See COPYING file for copyrights details.

from __future__ import absolute_import

from itertools import repeat, islice, chain

from connectors.SchemeEditor import SchemeEditor


model = [('host', _("Host:")),
         ('port', _("Port:"))]

# (scheme, model, secure)
models = [("LOCAL", [], False), ("PYRO", model, False), ("PYROS", model, True)]

Schemes = list(zip(*models)[0])

_PerSchemeConf = {sch: (mod, sec) for sch, mod, sec in models}


class PYRO_dialog(SchemeEditor):
    def __init__(self, scheme, *args, **kwargs):
        # ID selector is enabled only on PYROS (secure)
        self.model, self.EnableIDSelector = _PerSchemeConf[scheme]

        SchemeEditor.__init__(self, scheme, *args, **kwargs)

    # pylint: disable=unused-variable
    def SetLoc(self, loc):
        hostport, ID = list(islice(chain(loc.split("#"), repeat("")), 2))
        host, port = list(islice(chain(hostport.split(":"), repeat("")), 2))
        self.SetFields(locals())

    def GetLoc(self):
        if self.model:
            fields = self.GetFields()
            template = "{host}"
            if fields['port']:
                template += ":{port}"
            if self.EnableIDSelector:
                if fields['ID']:
                    template += "#{ID}"

            return template.format(**fields)
        return ''