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


Python psutil.sensors_battery方法代码示例

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


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

示例1: test_emulate_power_not_plugged_2

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import sensors_battery [as 别名]
def test_emulate_power_not_plugged_2(self):
        # Same as above but pretend /AC0/online does not exist in which
        # case code relies on /status file.
        def open_mock(name, *args, **kwargs):
            if name.endswith("AC0/online") or name.endswith("AC/online"):
                raise IOError(errno.ENOENT, "")
            elif name.endswith("/status"):
                return io.StringIO(u("discharging"))
            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) as m:
            self.assertEqual(psutil.sensors_battery().power_plugged, False)
            assert m.called 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:18,代码来源:test_linux.py

示例2: test_emulate_power_undetermined

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import sensors_battery [as 别名]
def test_emulate_power_undetermined(self):
        # Pretend we can't know whether the AC power cable not
        # connected (assert fallback to False).
        def open_mock(name, *args, **kwargs):
            if name.startswith("/sys/class/power_supply/AC0/online") or \
                    name.startswith("/sys/class/power_supply/AC/online"):
                raise IOError(errno.ENOENT, "")
            elif name.startswith("/sys/class/power_supply/BAT0/status"):
                return io.BytesIO(b"???")
            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) as m:
            self.assertIsNone(psutil.sensors_battery().power_plugged)
            assert m.called 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:test_linux.py

示例3: battery_WIN32

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import sensors_battery [as 别名]
def battery_WIN32(jarvis, s):
    """
    Provides basic info about battery fo win32
    """
    # https://stackoverflow.com/a/41988506/6771356
    import psutil

    def secs2hours(secs):
        mm, ss = divmod(secs, 60)
        hh, mm = divmod(mm, 60)
        return "%d:%02d:%02d" % (hh, mm, ss)

    batt = psutil.sensors_battery()
    if batt.power_plugged:
        jarvis.say("Battery is charging: %s%%" % batt.percent)
    else:
        jarvis.say("charge = %s%%, time left = %s" %
                   (batt.percent, secs2hours(batt.secsleft))) 
开发者ID:sukeesh,项目名称:Jarvis,代码行数:20,代码来源:battery.py

示例4: test_sensors_battery

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import sensors_battery [as 别名]
def test_sensors_battery(self):
        def secs2hours(secs):
            m, s = divmod(secs, 60)
            h, m = divmod(m, 60)
            return "%d:%02d" % (h, m)

        out = sh("acpiconf -i 0")
        fields = dict([(x.split('\t')[0], x.split('\t')[-1])
                       for x in out.split("\n")])
        metrics = psutil.sensors_battery()
        percent = int(fields['Remaining capacity:'].replace('%', ''))
        remaining_time = fields['Remaining time:']
        self.assertEqual(metrics.percent, percent)
        if remaining_time == 'unknown':
            self.assertEqual(metrics.secsleft, psutil.POWER_TIME_UNLIMITED)
        else:
            self.assertEqual(secs2hours(metrics.secsleft), remaining_time) 
开发者ID:giampaolo,项目名称:psutil,代码行数:19,代码来源:test_bsd.py

示例5: main

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import sensors_battery [as 别名]
def main():
    if not hasattr(psutil, "sensors_battery"):
        return sys.exit("platform not supported")
    batt = psutil.sensors_battery()
    if batt is None:
        return sys.exit("no battery is installed")

    print("charge:     %s%%" % round(batt.percent, 2))
    if batt.power_plugged:
        print("status:     %s" % (
            "charging" if batt.percent < 100 else "fully charged"))
        print("plugged in: yes")
    else:
        print("left:       %s" % secs2hours(batt.secsleft))
        print("status:     %s" % "discharging")
        print("plugged in: no") 
开发者ID:giampaolo,项目名称:psutil,代码行数:18,代码来源:battery.py

示例6: _sensors

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import sensors_battery [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

示例7: test_sensors_battery

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import sensors_battery [as 别名]
def test_sensors_battery(self):
        self.execute(psutil.sensors_battery) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:4,代码来源:test_memory_leaks.py

示例8: test_sensors_battery

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import sensors_battery [as 别名]
def test_sensors_battery(self):
        ret = psutil.sensors_battery()
        self.assertGreaterEqual(ret.percent, 0)
        self.assertLessEqual(ret.percent, 100)
        if ret.secsleft not in (psutil.POWER_TIME_UNKNOWN,
                                psutil.POWER_TIME_UNLIMITED):
            self.assertGreaterEqual(ret.secsleft, 0)
        else:
            if ret.secsleft == psutil.POWER_TIME_UNLIMITED:
                self.assertTrue(ret.power_plugged)
        self.assertIsInstance(ret.power_plugged, bool) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:13,代码来源:test_system.py

示例9: test_boot_time_fluctuation

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import sensors_battery [as 别名]
def test_boot_time_fluctuation(self):
        # https://github.com/giampaolo/psutil/issues/1007
        with mock.patch('psutil._pswindows.cext.boot_time', return_value=5):
            self.assertEqual(psutil.boot_time(), 5)
        with mock.patch('psutil._pswindows.cext.boot_time', return_value=4):
            self.assertEqual(psutil.boot_time(), 5)
        with mock.patch('psutil._pswindows.cext.boot_time', return_value=6):
            self.assertEqual(psutil.boot_time(), 5)
        with mock.patch('psutil._pswindows.cext.boot_time', return_value=333):
            self.assertEqual(psutil.boot_time(), 333)


# ===================================================================
# sensors_battery()
# =================================================================== 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:17,代码来源:test_windows.py

示例10: test_has_battery

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import sensors_battery [as 别名]
def test_has_battery(self):
        if win32api.GetPwrCapabilities()['SystemBatteriesPresent']:
            self.assertIsNotNone(psutil.sensors_battery())
        else:
            self.assertIsNone(psutil.sensors_battery()) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:7,代码来源:test_windows.py

示例11: test_percent

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import sensors_battery [as 别名]
def test_percent(self):
        w = wmi.WMI()
        battery_wmi = w.query('select * from Win32_Battery')[0]
        battery_psutil = psutil.sensors_battery()
        self.assertAlmostEqual(
            battery_psutil.percent, battery_wmi.EstimatedChargeRemaining,
            delta=1) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:9,代码来源:test_windows.py

示例12: test_emulate_no_battery

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import sensors_battery [as 别名]
def test_emulate_no_battery(self):
        with mock.patch("psutil._pswindows.cext.sensors_battery",
                        return_value=(0, 128, 0, 0)) as m:
            self.assertIsNone(psutil.sensors_battery())
            assert m.called 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:7,代码来源:test_windows.py

示例13: test_emulate_power_connected

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import sensors_battery [as 别名]
def test_emulate_power_connected(self):
        with mock.patch("psutil._pswindows.cext.sensors_battery",
                        return_value=(1, 0, 0, 0)) as m:
            self.assertEqual(psutil.sensors_battery().secsleft,
                             psutil.POWER_TIME_UNLIMITED)
            assert m.called 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:8,代码来源:test_windows.py

示例14: test_emulate_power_charging

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import sensors_battery [as 别名]
def test_emulate_power_charging(self):
        with mock.patch("psutil._pswindows.cext.sensors_battery",
                        return_value=(0, 8, 0, 0)) as m:
            self.assertEqual(psutil.sensors_battery().secsleft,
                             psutil.POWER_TIME_UNLIMITED)
            assert m.called 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:8,代码来源:test_windows.py

示例15: test_emulate_secs_left_unknown

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import sensors_battery [as 别名]
def test_emulate_secs_left_unknown(self):
        with mock.patch("psutil._pswindows.cext.sensors_battery",
                        return_value=(0, 0, 0, -1)) as m:
            self.assertEqual(psutil.sensors_battery().secsleft,
                             psutil.POWER_TIME_UNKNOWN)
            assert m.called


# ===================================================================
# Process APIs
# =================================================================== 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:13,代码来源:test_windows.py


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