當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。