~kennylevinsen/poweralertd-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] Add flag to only use the events from power supplies

Details
Message ID
<20240218103111.68490-1-damien.dev@tardypad.me>
DKIM signature
pass
Download raw message
Patch: +15 -2
Some devices don't have a proper separate upower type (for example
headsets) and could be just defined as "battery". So it's impossible
just with the ignore flag to ignore them while keeping monitoring
power supply batteries.
---
 main.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/main.c b/main.c
index 219c79d..a6c408d 100644
--- a/main.c
+++ b/main.c
@@ -144,7 +144,8 @@ static int send_warning_update(sd_bus *bus, struct upower_device *device) {
static const char usage[] = "usage: %s [options]\n"
"  -h				show this help message\n"
"  -s				ignore the events at startup\n"
"  -i <device_type>		ignore this device type, can be use several times\n";
"  -i <device_type>		ignore this device type, can be use several times\n"
"  -S				only use the events coming from power supplies\n";


int main(int argc, char *argv[]) {
@@ -152,9 +153,10 @@ int main(int argc, char *argv[]) {
	int device_type = 0;
	int ignore_types_mask = 0;
	bool ignore_initial = false;
	bool ignore_non_power_supplies = false;
	bool initialized = false;

	while ((opt = getopt(argc, argv, "hsi:")) != -1) {
	while ((opt = getopt(argc, argv, "hsi:S")) != -1) {
		switch (opt) {
		case 'i':
			device_type = upower_device_type_int(optarg);
@@ -168,6 +170,9 @@ int main(int argc, char *argv[]) {
		case 's':
			ignore_initial = true;
			break;
		case 'S':
			ignore_non_power_supplies = true;
			break;
		case 'h':
		default:
			fprintf(stderr, usage, argv[0]);
@@ -212,6 +217,10 @@ int main(int argc, char *argv[]) {
				goto next_device;
			}

			if (ignore_non_power_supplies && !device->power_supply) {
				goto next_device;
			}

			if (upower_device_has_battery(device)) {
				ret = send_state_update(user_bus, device);
				if (ret < 0) {
@@ -241,6 +250,10 @@ next_device:
				continue;
			}

			if (ignore_non_power_supplies && !device->power_supply) {
				continue;
			}

			ret = send_remove(user_bus, device);
			if (ret < 0) {
				fprintf(stderr, "could not send device removal notification: %s\n", strerror(-ret));
-- 
2.43.2
Details
Message ID
<718a791e-019e-4a5b-98d2-ef2345476e3d@kl.wtf>
In-Reply-To
<20240218103111.68490-1-damien.dev@tardypad.me> (view parent)
DKIM signature
pass
Download raw message
Applied, thanks!

On 2/18/24 11:30, Damien Tardy-Panis wrote:
> Some devices don't have a proper separate upower type (for example
> headsets) and could be just defined as "battery". So it's impossible
> just with the ignore flag to ignore them while keeping monitoring
> power supply batteries.

Note that Headset is indeed a UPower type. There were types missing in 
poweralertd due to somewhat lacking documentation on UPower's side. I 
opened https://gitlab.freedesktop.org/upower/upower/-/merge_requests/215 
to get that resolved.
Reply to thread Export thread (mbox)