本文整理汇总了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)
示例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)
示例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')
示例4: test_sensors_temperatures
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import sensors_temperatures [as 别名]
def test_sensors_temperatures(self):
self.execute(psutil.sensors_temperatures)
示例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)
示例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)
示例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)
示例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')
示例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)
示例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)
示例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)
示例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()
示例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
示例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
示例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)