コード例 #1
0
    def __init__(self, name, core_services):
        self.__name = name
        self.__core = core_services

        from core.tracing import get_tracer
        self.__tracer = get_tracer(name)

        ## Settings Table Definition:
        settings_list = [
            Setting(name='volume',
                    type=int,
                    required=True,
                    default_value=5000,
                    verify_function=lambda x: x >= 1),
            Setting(name='initial_level',
                    type=int,
                    required=False,
                    default_value=50,
                    verify_function=lambda x: x >= 0 and x <= 100),
            Setting(name='initial_temperature',
                    type=int,
                    required=False,
                    default_value=12,
                    verify_function=lambda x: x >= TEMPERATURE_MIN_LIMIT and x
                    <= TEMPERATURE_MAX_LIMIT),
            Setting(name='inflow_rate',
                    type=float,
                    required=False,
                    default_value=10,
                    verify_function=lambda x: x >= 0),
            Setting(name='outflow_rate',
                    type=float,
                    required=False,
                    default_value=20,
                    verify_function=lambda x: x >= 0),
            Setting(name='min_level_alarm',
                    type=int,
                    required=False,
                    default_value=None,
                    verify_function=lambda x: x >= 0 and x <= 100),
            Setting(name='max_level_alarm',
                    type=int,
                    required=False,
                    default_value=None,
                    verify_function=lambda x: x > 0 and x <= 100),
            Setting(name='min_temperature_alarm',
                    type=int,
                    required=False,
                    default_value=None,
                    verify_function=lambda x: x >= 0),
            Setting(name='max_temperature_alarm',
                    type=int,
                    required=False,
                    default_value=None,
                    verify_function=lambda x: x >= 0),
        ]

        ## Channel Properties Definition:
        property_list = [
            ChannelSourceDeviceProperty(name="level",
                                        type=int,
                                        initial=Sample(timestamp=0,
                                                       value=0,
                                                       unit="%"),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="temperature",
                                        type=float,
                                        initial=Sample(timestamp=0,
                                                       value=0.0,
                                                       unit="C"),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(
                name="valve_in",
                type=Boolean,
                initial=Sample(timestamp=0,
                               value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET | DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda sample: self.set_valve(VALVE_IN, sample)),
            ChannelSourceDeviceProperty(
                name="valve_out",
                type=Boolean,
                initial=Sample(timestamp=0,
                               value=Boolean(False, style=STYLE_ONOFF)),
                perms_mask=(DPROP_PERM_GET | DPROP_PERM_SET),
                options=DPROP_OPT_AUTOTIMESTAMP,
                set_cb=lambda sample: self.set_valve(VALVE_OUT, sample)),
            ChannelSourceDeviceProperty(name="level_alarm",
                                        type=str,
                                        initial=Sample(timestamp=0, value=""),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="temperature_alarm",
                                        type=str,
                                        initial=Sample(timestamp=0, value=""),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
            ChannelSourceDeviceProperty(name="virtual",
                                        type=bool,
                                        initial=Sample(timestamp=0,
                                                       value=True),
                                        perms_mask=DPROP_PERM_GET,
                                        options=DPROP_OPT_AUTOTIMESTAMP),
        ]

        ## Initialize the DeviceBase interface:
        DeviceBase.__init__(self, self.__name, self.__core, settings_list,
                            property_list)

        ## Thread initialization:
        self.__stopevent = threading.Event()
        threading.Thread.__init__(self, name=name)
        threading.Thread.setDaemon(self, True)