diff --git a/src/linux/integration-test.py b/src/linux/integration-test.py index 66993a5..dd27655 100755 --- a/src/linux/integration-test.py +++ b/src/linux/integration-test.py @@ -1802,7 +1802,7 @@ class Tests(dbusmock.DBusTestCase): devs = self.proxy.EnumerateDevices() self.assertEqual(len(devs), 2) bat0_up = devs[0] - bat1_up = devs[0] + bat1_up = devs[1] for bat in [bat0_up, bat1_up]: self.assertEqual( @@ -1905,7 +1905,7 @@ class Tests(dbusmock.DBusTestCase): devs = self.proxy.EnumerateDevices() self.assertEqual(len(devs), 2) bat0_up = devs[0] - bat1_up = devs[0] + bat1_up = devs[1] for bat in [bat0_up, bat1_up]: self.assertEqual( @@ -2049,7 +2049,7 @@ class Tests(dbusmock.DBusTestCase): devs = self.proxy.EnumerateDevices() self.assertEqual(len(devs), 2) bat0_up = devs[0] - bat1_up = devs[0] + bat1_up = devs[1] for bat in [bat0_up, bat1_up]: self.assertEqual( @@ -2098,6 +2098,184 @@ class Tests(dbusmock.DBusTestCase): ) as fp: self.assertEqual(fp.read(), "80") + def test_battery_charge_limit_multiple_batteries_with_charge_types_longlife_standard( + self, + ): + """ + The charge threshold is controlled by + 1. charge_control_start_threshold and charge_control_end_threshold. + 2. the charge_types attribute with Long_life and Standard. + 3. the charge_types attribute with Long_life, Fast and Adaptive. + """ + + if not self.polkit: + self.start_polkitd({}) + self.polkit_obj.SetAllowed(["org.freedesktop.UPower.enable-charging-limit"]) + + bat0 = self.testbed.add_device( + "power_supply", + "BAT0", + None, + [ + "type", + "Battery", + "present", + "1", + "status", + "unknown", + "energy_full", + "60000000", + "energy_full_design", + "80000000", + "energy_now", + "48000000", + "voltage_now", + "12000000", + "charge_types", + "[Standard] Long_Life", + ], + [], + ) + self.testbed.set_property( + "/sys/class/power_supply/BAT0", "CHARGE_LIMIT", "70,80" + ) + + bat1 = self.testbed.add_device( + "power_supply", + "BAT1", + None, + [ + "type", + "Battery", + "present", + "1", + "status", + "unknown", + "energy_full", + "60000000", + "energy_full_design", + "80000000", + "energy_now", + "48000000", + "voltage_now", + "12000000", + "charge_control_start_threshold", + "0", + "charge_control_end_threshold", + "100", + ], + [], + ) + self.testbed.set_property( + "/sys/class/power_supply/BAT1", "CHARGE_LIMIT", "70,80" + ) + + bat2 = self.testbed.add_device( + "power_supply", + "BAT2", + None, + [ + "type", + "Battery", + "present", + "1", + "status", + "unknown", + "energy_full", + "60000000", + "energy_full_design", + "80000000", + "energy_now", + "48000000", + "voltage_now", + "12000000", + "charge_types", + "[Standard] Fast Long_Life", + ], + [], + ) + self.testbed.set_property( + "/sys/class/power_supply/BAT0", "CHARGE_LIMIT", "70,80" + ) + + self.start_daemon() + devs = self.proxy.EnumerateDevices() + self.assertEqual(len(devs), 3) + bat0_up = devs[0] + bat1_up = devs[1] + bat2_up = devs[2] + + for bat in [bat0_up, bat1_up]: + self.assertEqual( + self.get_dbus_dev_property(bat, "ChargeThresholdSupported"), True + ) + self.assertEqual( + self.get_dbus_dev_property(bat, "ChargeThresholdEnabled"), False + ) + self.assertEqual( + self.get_dbus_dev_property(bat, "ChargeStartThreshold"), 70 + ) + self.assertEqual(self.get_dbus_dev_property(bat, "ChargeEndThreshold"), 80) + + # Enable the charging limits + self.enable_charge_limits(bat0_up, True) + self.enable_charge_limits(bat1_up, True) + self.enable_charge_limits(bat2_up, True) + + # Battery 0 + # The charge_types was found and only two charge_types are supported, Long_Life and Standard + self.assertEqual( + self.get_dbus_dev_property(bat0_up, "ChargeThresholdEnabled"), True + ) + battery_name = bat0_up.split("_")[-1] + + with open(f"/sys/class/power_supply/{battery_name}/charge_types") as fp: + self.assertEqual(fp.read(), "Long_Life") + + # Charge_types was not found on Battery 1, and the daemon won't complain + # when setting the charge limits. + self.assertEqual( + self.get_dbus_dev_property(bat1_up, "ChargeThresholdEnabled"), True + ) + battery_name = bat1_up.split("_")[-1] + with open( + f"/sys/class/power_supply/{battery_name}/charge_control_start_threshold" + ) as fp: + self.assertEqual(fp.read(), "70") + with open( + f"/sys/class/power_supply/{battery_name}/charge_control_end_threshold" + ) as fp: + self.assertEqual(fp.read(), "80") + + # Battery 2 + # The charge_types was found and charge_types are Long_Life, Fast, and Standard + self.assertEqual( + self.get_dbus_dev_property(bat0_up, "ChargeThresholdEnabled"), True + ) + battery_name = bat2_up.split("_")[-1] + + with open(f"/sys/class/power_supply/{battery_name}/charge_types") as fp: + self.assertEqual(fp.read(), "Long_Life") + + # Disable charging limit + self.testbed.set_attribute(bat0, "charge_types", "Fast [Custom]") + self.enable_charge_limits(bat0_up, False) + self.enable_charge_limits(bat1_up, False) + self.enable_charge_limits(bat2_up, False) + + self.assertEqual( + self.get_dbus_dev_property(bat0_up, "ChargeThresholdEnabled"), False + ) + # Battery 0 switches to "Standard" + battery_name = bat0_up.split("_")[-1] + with open(f"/sys/class/power_supply/{battery_name}/charge_types") as fp: + self.assertEqual(fp.read(), "Standard") + + # Battery 2 switches to "Fast" + battery_name = bat2_up.split("_")[-1] + with open(f"/sys/class/power_supply/{battery_name}/charge_types") as fp: + self.assertEqual(fp.read(), "Fast") + def test_battery_charge_limit_multiple_batteries_polkit_not_allowed(self): """Battery with charge limits with multiple batteries, but polkit isn't allowed""" @@ -2168,7 +2346,7 @@ class Tests(dbusmock.DBusTestCase): devs = self.proxy.EnumerateDevices() self.assertEqual(len(devs), 2) bat0_up = devs[0] - bat1_up = devs[0] + bat1_up = devs[1] for bat in [bat0_up, bat1_up]: self.assertEqual(