當前位置: 首頁>>代碼示例>>Python>>正文


Python psutil.sensors_temperatures方法代碼示例

本文整理匯總了Python中psutil.sensors_temperatures方法的典型用法代碼示例。如果您正苦於以下問題:Python psutil.sensors_temperatures方法的具體用法?Python psutil.sensors_temperatures怎麽用?Python psutil.sensors_temperatures使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在psutil的用法示例。


在下文中一共展示了psutil.sensors_temperatures方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_emulate_data

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import sensors_temperatures [as 別名]
def test_emulate_data(self):
        def open_mock(name, *args, **kwargs):
            if name.endswith('/name'):
                return io.StringIO(u("name"))
            elif name.endswith('/temp1_label'):
                return io.StringIO(u("label"))
            elif name.endswith('/temp1_input'):
                return io.BytesIO(b"30000")
            elif name.endswith('/temp1_max'):
                return io.BytesIO(b"40000")
            elif name.endswith('/temp1_crit'):
                return io.BytesIO(b"50000")
            else:
                return orig_open(name, *args, **kwargs)

        orig_open = open
        patch_point = 'builtins.open' if PY3 else '__builtin__.open'
        with mock.patch(patch_point, side_effect=open_mock):
            with mock.patch('glob.glob',
                            return_value=['/sys/class/hwmon/hwmon0/temp1']):
                temp = psutil.sensors_temperatures()['name'][0]
                self.assertEqual(temp.label, 'label')
                self.assertEqual(temp.current, 30.0)
                self.assertEqual(temp.high, 40.0)
                self.assertEqual(temp.critical, 50.0) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:27,代碼來源:test_linux.py

示例2: next

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import sensors_temperatures [as 別名]
def next(self):
        def flatten(l):
            return [item for sublist in l for item in sublist]

        self.cur_temp = sensors_temperatures().get(self.sensor_name)[0].current
        if self.cur_temp <= self.cold:
            self.angle = self.cold_angle
        elif self.cur_temp < self.target:
            self.angle = ((self.cold_angle - self.target_angle)
                          / (self.target - self.cold)
                          * (self.target - self.cur_temp))
        elif self.cur_temp == self.target:
            self.angle = self.target_angle
        elif self.cur_temp > self.hot:
            self.angle = self.hot_angle
        elif self.cur_temp > self.target:
            self.angle = 120 - ((self.target_angle - self.hot_angle)
                                / (self.hot - self.target)
                                * (self.cur_temp - self.target))
        for dev in self._devices:
            values = flatten([compass_to_rgb(self.angle)] * dev.num_leds)
            dev.set_lighting(values=values) 
開發者ID:chestm007,項目名稱:linux_thermaltake_riing,代碼行數:24,代碼來源:lighting_manager.py

示例3: _sensors

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import sensors_temperatures [as 別名]
def _sensors():

    contents = []

    if hasattr(psutil, "sensors_temperatures"):
        sensors_temperatures = psutil.sensors_temperatures()
        for name, entries in sensors_temperatures.items():
            for entry in entries:
                contents.append(
                    _format_info(entry.label or name, '%s °C' % entry.current))

    sbattery = psutil.sensors_battery()

    if sbattery:
        contents.append(_format_info('battery_percent', '%s %%' % sbattery.percent))
        contents.append(_format_info('secsleft', sbattery.secsleft))
        contents.append(_format_info('power_plugged', sbattery.power_plugged))
    _print_info(contents, 'Sensors') 
開發者ID:zhanghe06,項目名稱:news_spider,代碼行數:20,代碼來源:sys_monitor.py

示例4: test_sensors_temperatures

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import sensors_temperatures [as 別名]
def test_sensors_temperatures(self):
        self.execute(psutil.sensors_temperatures) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:4,代碼來源:test_memory_leaks.py

示例5: test_sensors_temperatures

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import sensors_temperatures [as 別名]
def test_sensors_temperatures(self):
        self.assertEqual(hasattr(psutil, "sensors_temperatures"), LINUX) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:4,代碼來源:test_contracts.py

示例6: test_sensors_temperatures

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import sensors_temperatures [as 別名]
def test_sensors_temperatures(self):
        temps = psutil.sensors_temperatures()
        for name, entries in temps.items():
            self.assertIsInstance(name, str)
            for entry in entries:
                self.assertIsInstance(entry.label, str)
                if entry.current is not None:
                    self.assertGreaterEqual(entry.current, 0)
                if entry.high is not None:
                    self.assertGreaterEqual(entry.high, 0)
                if entry.critical is not None:
                    self.assertGreaterEqual(entry.critical, 0) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:14,代碼來源:test_system.py

示例7: test_sensors_temperatures_fahreneit

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import sensors_temperatures [as 別名]
def test_sensors_temperatures_fahreneit(self):
        d = {'coretemp': [('label', 50.0, 60.0, 70.0)]}
        with mock.patch("psutil._psplatform.sensors_temperatures",
                        return_value=d) as m:
            temps = psutil.sensors_temperatures(
                fahrenheit=True)['coretemp'][0]
            assert m.called
            self.assertEqual(temps.current, 122.0)
            self.assertEqual(temps.high, 140.0)
            self.assertEqual(temps.critical, 158.0) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:12,代碼來源:test_system.py

示例8: test_temperatures

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import sensors_temperatures [as 別名]
def test_temperatures(self):
        if not psutil.sensors_temperatures():
            self.skipTest("no temperatures")
        self.assert_stdout('temperatures.py') 
開發者ID:giampaolo,項目名稱:psutil,代碼行數:6,代碼來源:test_misc.py

示例9: test_sensors_temperatures

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import sensors_temperatures [as 別名]
def test_sensors_temperatures(self):
        self.assertEqual(
            hasattr(psutil, "sensors_temperatures"), LINUX or FREEBSD) 
開發者ID:giampaolo,項目名稱:psutil,代碼行數:5,代碼來源:test_contracts.py

示例10: test_emulate_class_hwmon

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import sensors_temperatures [as 別名]
def test_emulate_class_hwmon(self):
        def open_mock(name, *args, **kwargs):
            if name.endswith('/name'):
                return io.StringIO(u("name"))
            elif name.endswith('/temp1_label'):
                return io.StringIO(u("label"))
            elif name.endswith('/temp1_input'):
                return io.BytesIO(b"30000")
            elif name.endswith('/temp1_max'):
                return io.BytesIO(b"40000")
            elif name.endswith('/temp1_crit'):
                return io.BytesIO(b"50000")
            else:
                return orig_open(name, *args, **kwargs)

        orig_open = open
        patch_point = 'builtins.open' if PY3 else '__builtin__.open'
        with mock.patch(patch_point, side_effect=open_mock):
            # Test case with /sys/class/hwmon
            with mock.patch('glob.glob',
                            return_value=['/sys/class/hwmon/hwmon0/temp1']):
                temp = psutil.sensors_temperatures()['name'][0]
                self.assertEqual(temp.label, 'label')
                self.assertEqual(temp.current, 30.0)
                self.assertEqual(temp.high, 40.0)
                self.assertEqual(temp.critical, 50.0) 
開發者ID:giampaolo,項目名稱:psutil,代碼行數:28,代碼來源:test_linux.py

示例11: test_emulate_class_thermal

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import sensors_temperatures [as 別名]
def test_emulate_class_thermal(self):
        def open_mock(name, *args, **kwargs):
            if name.endswith('0_temp'):
                return io.BytesIO(b"50000")
            elif name.endswith('temp'):
                return io.BytesIO(b"30000")
            elif name.endswith('0_type'):
                return io.StringIO(u("critical"))
            elif name.endswith('type'):
                return io.StringIO(u("name"))
            else:
                return orig_open(name, *args, **kwargs)

        def glob_mock(path):
            if path == '/sys/class/hwmon/hwmon*/temp*_*':
                return []
            elif path == '/sys/class/hwmon/hwmon*/device/temp*_*':
                return []
            elif path == '/sys/class/thermal/thermal_zone*':
                return ['/sys/class/thermal/thermal_zone0']
            elif path == '/sys/class/thermal/thermal_zone0/trip_point*':
                return ['/sys/class/thermal/thermal_zone1/trip_point_0_type',
                        '/sys/class/thermal/thermal_zone1/trip_point_0_temp']
            return []

        orig_open = open
        patch_point = 'builtins.open' if PY3 else '__builtin__.open'
        with mock.patch(patch_point, side_effect=open_mock):
            with mock.patch('glob.glob', create=True, side_effect=glob_mock):
                temp = psutil.sensors_temperatures()['name'][0]
                self.assertEqual(temp.label, '')
                self.assertEqual(temp.current, 30.0)
                self.assertEqual(temp.high, 50.0)
                self.assertEqual(temp.critical, 50.0) 
開發者ID:giampaolo,項目名稱:psutil,代碼行數:36,代碼來源:test_linux.py

示例12: main

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import sensors_temperatures [as 別名]
def main():
    if not hasattr(psutil, "sensors_temperatures"):
        sys.exit("platform not supported")
    temps = psutil.sensors_temperatures()
    if not temps:
        sys.exit("can't read any temperature")
    for name, entries in temps.items():
        print(name)
        for entry in entries:
            print("    %-20s %s °C (high = %s °C, critical = %s °C)" % (
                entry.label or name, entry.current, entry.high,
                entry.critical))
        print() 
開發者ID:giampaolo,項目名稱:psutil,代碼行數:15,代碼來源:temperatures.py

示例13: _get_temp

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import sensors_temperatures [as 別名]
def _get_temp(self):
        return sensors_temperatures().get(self.sensor_name)[0].current 
開發者ID:chestm007,項目名稱:linux_thermaltake_riing,代碼行數:4,代碼來源:fan_manager.py

示例14: get_cpu_temp

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import sensors_temperatures [as 別名]
def get_cpu_temp():
    t = psutil.sensors_temperatures()
    for x in ['cpu-thermal', 'cpu_thermal']:
        if x in t:
            return t[x][0].current
    print("Warning: Unable to get CPU temperature!")
    return 0 
開發者ID:pimoroni,項目名稱:fanshim-python,代碼行數:9,代碼來源:automatic.py

示例15: update

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import sensors_temperatures [as 別名]
def update(self):
        sample = OrderedDict(sorted(psutil.sensors_temperatures().items()))
        self.last_measurement = []
        for sensor in sample:
            for minor_sensor in sample[sensor]:
                self.last_measurement.append(minor_sensor.current)

        if self.last_measurement:
            self.max_last_temp = max(self.last_measurement)
            # Call check for hooks
            Source.update(self) 
開發者ID:amanusk,項目名稱:s-tui,代碼行數:13,代碼來源:temp_source.py


注:本文中的psutil.sensors_temperatures方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。