-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add upower_power_profiles_daemon template
This works like the existing power_profiles_daemon template, but for the new D-Bus name/object path introduced in https://gitlab.freedesktop.org/upower/power-profiles-daemon/-/releases/0.20 Enable integration test on Ubuntu, which has version 0.13 in 22.04 LTS.
- Loading branch information
1 parent
9e46a1f
commit b24f7b7
Showing
4 changed files
with
92 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
"""power-profiles-daemon >= 0.20 mock template | ||
This creates the expected methods and properties of the main | ||
org.freedesktop.UPower.PowerProfiles object. | ||
This provides the D-Bus API as of version 0.20. | ||
""" | ||
|
||
# This program is free software; you can redistribute it and/or modify it under | ||
# the terms of the GNU Lesser General Public License as published by the Free | ||
# Software Foundation; either version 3 of the License, or (at your option) any | ||
# later version. See http://www.gnu.org/copyleft/lgpl.html for the full text | ||
# of the license. | ||
|
||
__author__ = "Bastien Nocera" | ||
__copyright__ = """ | ||
(c) 2021, Red Hat Inc. | ||
(c) 2017 - 2024 Martin Pitt <[email protected]> | ||
""" | ||
|
||
import dbus | ||
|
||
BUS_NAME = "org.freedesktop.UPower.PowerProfiles" | ||
MAIN_OBJ = "/org/freedesktop/UPower/PowerProfiles" | ||
MAIN_IFACE = "org.freedesktop.UPower.PowerProfiles" | ||
SYSTEM_BUS = True | ||
|
||
|
||
def hold_profile(self, profile, reason, application_id): | ||
self.cookie += 1 | ||
element = {"Profile": profile, "Reason": reason, "ApplicationId": application_id} | ||
self.holds[self.cookie] = element | ||
self.props[MAIN_IFACE]["ActiveProfileHolds"] = [] | ||
for value in self.holds.values(): | ||
self.props[MAIN_IFACE]["ActiveProfileHolds"].append(value) | ||
return self.cookie | ||
|
||
|
||
def release_profile(self, cookie): | ||
self.holds.pop(cookie) | ||
self.props[MAIN_IFACE]["ActiveProfileHolds"] = [] | ||
for value in self.holds.values(): | ||
self.props[MAIN_IFACE]["ActiveProfileHolds"].append(value) | ||
if len(self.props[MAIN_IFACE]["ActiveProfileHolds"]) == 0: | ||
self.props[MAIN_IFACE]["ActiveProfileHolds"] = dbus.Array([], signature="(aa{sv})") | ||
|
||
|
||
def load(mock, parameters): | ||
# Loaded! | ||
mock.loaded = True | ||
mock.cookie = 0 | ||
mock.hold_profile = hold_profile | ||
mock.release_profile = release_profile | ||
mock.holds = {} | ||
|
||
props = { | ||
"ActiveProfile": parameters.get("ActiveProfile", "balanced"), | ||
"PerformanceDegraded": parameters.get("PerformanceDegraded", ""), | ||
"Profiles": [ | ||
dbus.Dictionary({"Profile": "power-saver", "Driver": "dbusmock"}, signature="sv"), | ||
dbus.Dictionary({"Profile": "balanced", "Driver": "dbusmock"}, signature="sv"), | ||
dbus.Dictionary({"Profile": "performance", "Driver": "dbusmock"}, signature="sv"), | ||
], | ||
"Actions": dbus.Array([], signature="s"), | ||
"ActiveProfileHolds": dbus.Array([], signature="(aa{sv})"), | ||
} | ||
mock.AddProperties(MAIN_IFACE, dbus.Dictionary(props, signature="sv")) | ||
|
||
mock.AddMethods( | ||
MAIN_IFACE, | ||
[ | ||
("HoldProfile", "sss", "u", "ret = self.hold_profile(self, args[0], args[1], args[2])"), | ||
("ReleaseProfile", "u", "", "self.release_profile(self, args[0])"), | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters