当前位置: 首页>>代码示例>>Python>>正文


Python SettingsBase.set_pending_setting方法代码示例

本文整理汇总了Python中settings.settings_base.SettingsBase.set_pending_setting方法的典型用法代码示例。如果您正苦于以下问题:Python SettingsBase.set_pending_setting方法的具体用法?Python SettingsBase.set_pending_setting怎么用?Python SettingsBase.set_pending_setting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在settings.settings_base.SettingsBase的用法示例。


在下文中一共展示了SettingsBase.set_pending_setting方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __adjust_sample_rate_sec

# 需要导入模块: from settings.settings_base import SettingsBase [as 别名]
# 或者: from settings.settings_base.SettingsBase import set_pending_setting [as 别名]
    def __adjust_sample_rate_sec(self, val=None):

        if val is None:
            # then use existing setting, which shall be string
            val = SettingsBase.get_setting(self, "sample_rate_sec")

        elif isinstance(val, types.IntType):
            # else make int as seconds into string
            val = str(val)

        # else assume is string

        # Parse out the sample rate string, set self.__rate to seconds
        self.__rate = int(parse_time_duration( val, in_type='sec', out_type='sec'))
        #if self.trace_debug_events():
        #    print '%s: import sample rate (%s) as %d sec' % \
        #          (self.showname, val, self.__rate)

        val = SettingsBase.get_setting(self, "sample_rate_sec")
        if val != str(self.__rate):
            # then we changed the value
            try:
                SettingsBase.set_pending_setting(self, \
                        "sample_rate_sec", str(self.__rate))

                # push the new settings into running system
                self.apply_settings()

            except:
                traceback.print_exc()

        if (self.__rate % 60) == 0:
            # then we'll do the 'clean minutes' function
            self.__clean_minutes = 0
        else:
            self.__clean_minutes = None

        return
开发者ID:Lewiswight,项目名称:4CT-GW--master,代码行数:40,代码来源:massa_m300s_multi.py

示例2: start

# 需要导入模块: from settings.settings_base import SettingsBase [as 别名]
# 或者: from settings.settings_base.SettingsBase import set_pending_setting [as 别名]
    def start(self):

 
        
        # Fetch the XBee Manager name from the Settings Manager:
        xbee_manager_name = SettingsBase.get_setting(self, "xbee_device_manager")
        dm = self.__core.get_service("device_driver_manager")
        self.__xbee_manager = dm.instance_get(xbee_manager_name)

        cm = self.__core.get_service("channel_manager")
        cp = cm.channel_publisher_get()

        # Register ourselves with the XBee Device Manager instance:
        self.__xbee_manager.xbee_device_register(self)

        # Get the extended address of the device:
        self.__extended_address = SettingsBase.get_setting(self, 
                                                           "extended_address")

        
        address = self.__extended_address
        self.thermostat = TemplateDevice(("thermostat_" + address), self.__core)
        time.sleep(3)
        SettingsBase.set_pending_setting(self, "channel1_source", ("thermostat_" + address + ".heat_on"))
        SettingsBase.set_pending_setting(self, "channel2_source", ("thermostat_" + address + ".heat_off"))
        
       # channel1_source: "thermostat_[00:05:a2:00:40:52:e0:fc]!.heat_on"
        #        channel2_source: "thermostat_[00:05:a2:00:40:52:e0:fc]!.heat_off"
        print
        print ("thermostat_" + address + ".heat_on")
        print ("thermostat_" + address + ".heat_off")
     #   str1 = ("thermostat_" + address + ".heat_on")
      #  str2 = ("thermostat_" + address + ".heat_off")
        self.apply_settings()
        
        
        
        # Create a callback specification for our device address, endpoint
        # Digi XBee profile and sample cluster id:
        xbdm_rx_event_spec = XBeeDeviceManagerRxEventSpec()
        xbdm_rx_event_spec.cb_set(self.sample_indication)
        xbdm_rx_event_spec.match_spec_set(
            (self.__extended_address, 0xe8, 0xc105, 0x92),
            (True, True, True, True))
        self.__xbee_manager.xbee_device_event_spec_add(self,
                                xbdm_rx_event_spec)

        # Create a callback specification that calls back this driver when
        # our device has left the configuring state and has transitioned
        # to the running state:
        xbdm_running_event_spec = XBeeDeviceManagerRunningEventSpec()
        xbdm_running_event_spec.cb_set(self.running_indication)
        self.__xbee_manager.xbee_device_event_spec_add(self,
                                                        xbdm_running_event_spec)

        # Create a DDO configuration block for this device:
        xbee_ddo_cfg = XBeeConfigBlockDDO(self.__extended_address)
        
        xbee_ddo_cfg.add_parameter("NI", "")

        # Get the gateway's extended address:
        gw_xbee_sh, gw_xbee_sl = gw_extended_address_tuple()

        # Set the destination for I/O samples to be the gateway:
        xbee_ddo_cfg.add_parameter('DH', gw_xbee_sh)
        xbee_ddo_cfg.add_parameter('DL', gw_xbee_sl)

        # Configure pins DIO0 .. DIO3 for digital input:
        pr = 0xe1 # DIO0-3 pullups off, all else on
        ic = 0

        for io_pin in range(4):
            dir = SettingsBase.get_setting(self, 'channel%d_dir' % (io_pin+1) )
            dir = dir.lower()

            # Enable input on all pins:
            xbee_ddo_cfg.add_parameter(CONTROL_LINES[io_pin][IN], 3)

            # Build our change detection mask for all io pins:
            ic |= 1 << INPUT_CHANNEL_TO_PIN[io_pin]

            if dir == 'in':
                # Disable sinking driver output:
                xbee_ddo_cfg.add_parameter(CONTROL_LINES[io_pin][OUT], 4)

            elif dir == 'out':
                # Create the output channel for this IO pin:
                self.add_property(
                    ChannelSourceDeviceProperty(
                        name='channel%d_output' % (io_pin+1), type=Boolean,
                        initial=Sample(timestamp=0, value=Boolean(False), unit='1'),
                        perms_mask=(DPROP_PERM_GET|DPROP_PERM_SET),
                        options=DPROP_OPT_AUTOTIMESTAMP,
                        set_cb=lambda sample, io=io_pin: \
                                self.set_output(sample, io) )
                    )

                # If set, subscribe to the channel that drives our output logic:
                source = SettingsBase.get_setting(self, 'channel%d_source' 
                                                  % (io_pin+1))
#.........这里部分代码省略.........
开发者ID:Lewiswight,项目名称:4CT-GW--master,代码行数:103,代码来源:xbee_dio.py

示例3: sample_indication

# 需要导入模块: from settings.settings_base import SettingsBase [as 别名]
# 或者: from settings.settings_base.SettingsBase import set_pending_setting [as 别名]
    def sample_indication(self, buf, addr):

        # check if we want to scroll a trace line or not
        do_trace = SettingsBase.get_setting(self, "trace")
        if do_trace:
            msg = ['XBeeSensor(%s): ' % self.__name]

        # Parse the I/O sample:
        io_sample = parse_is(buf)
        
        # Calculate sensor channel values:
        if io_sample.has_key("AD1") and io_sample.has_key("AD2") and io_sample.has_key("AD3"):
            light_mv, temperature_mv, humidity_mv = \
                map(lambda cn: sample_to_mv(io_sample[cn]), ("AD1", "AD2", "AD3"))

            #
            # handle temperature - first as celsius
            #
            scale = "F"
            temperature = temperature_mv
            if not SettingsBase.get_setting(self, "sleep"):
                # self-heating correction if running full-time - reduce 2 DegC
                temperature -= .001
            temperature = round(temperature, 2)
            
                
    
            #self.property_set("motion", Sample(0, temperature, scale))
            #if do_trace:
            #    msg.append( "%d %s" % (temperature, scale))
    
            #
            # handle the light value
            #
            light = round((light_mv / 10), 2)
            if light < 0:
                # clamp to be zero or higher
                light = 0
            self.property_set("temperature", Sample(0, light, "F"))
           # if do_trace:
            #    msg.append( ", %d brightness" % light)
    
            #
            # handle humidity - might be missing
            #
            if self.property_exists("humidity"):
                humidity = ((humidity_mv * 108.2 / 33.2) / 5000.0 - 0.16) / 0.0062
                if humidity < 0.0:
                    # clamp to min of 0%
                    humidity = 0.0
                elif humidity > 100.0:
                    # clamp to be max of 100%
                    humidity = 100.0
                self.property_set("humidity", Sample(0, humidity, "%"))
                if do_trace:
                    msg.append( ", %d RH%%" % humidity)
            else: # it remains the original default
                humidity = 0
        
        
        activate = self.property_get("power_on").value

        # Low battery check (attached to DIO11/P1):
        # Invert the signal it is actually not_low_battery:
        if io_sample.has_key("DIO2") and activate:
            low_battery = not bool(io_sample["DIO2"])
            if low_battery != bool(self.property_get("low_battery").value):
                self.property_set("low_battery", Sample(0, low_battery))
    
            if do_trace:
                if low_battery:
                    msg.append( ", low_battery")
                # try to keep memory use from dragging out
                msg = "".join( msg)
                print msg
                del msg

        temp = self.property_get("temperature").value
        SettingsBase.set_pending_setting(self, 'temp', temp)
        
        motion = self.property_get("low_battery").value
        
        
        if activate and motion:
            self.property_set("motion_event",
            Sample(0, Boolean(True, style=STYLE_ONOFF)))
        else:
            self.property_set("motion_event",
            Sample(0, Boolean(False, style=STYLE_ONOFF)))
            


        return
开发者ID:Lewiswight,项目名称:4CT-GW--master,代码行数:95,代码来源:temp_motion.py


注:本文中的settings.settings_base.SettingsBase.set_pending_setting方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。