lapctl 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lapctl/__init__.py +3 -0
- lapctl/channels/__init__.py +1 -0
- lapctl/channels/telegram/__init__.py +1 -0
- lapctl/channels/telegram/api.py +336 -0
- lapctl/channels/telegram/auth.py +29 -0
- lapctl/channels/telegram/handlers.py +161 -0
- lapctl/channels/telegram/poller.py +163 -0
- lapctl/channels/telegram/render.py +166 -0
- lapctl/cli.py +527 -0
- lapctl/config.py +163 -0
- lapctl/core/__init__.py +1 -0
- lapctl/core/battery.py +69 -0
- lapctl/core/commands.py +1260 -0
- lapctl/core/confirm.py +68 -0
- lapctl/core/keyboards.py +140 -0
- lapctl/core/paths.py +77 -0
- lapctl/core/ratelimit.py +30 -0
- lapctl/drivers/__init__.py +1 -0
- lapctl/drivers/base.py +163 -0
- lapctl/drivers/linux_hyprland.py +574 -0
- lapctl/main.py +86 -0
- lapctl/registry.py +110 -0
- lapctl/results.py +86 -0
- lapctl-0.1.1.dist-info/METADATA +149 -0
- lapctl-0.1.1.dist-info/RECORD +29 -0
- lapctl-0.1.1.dist-info/WHEEL +5 -0
- lapctl-0.1.1.dist-info/entry_points.txt +2 -0
- lapctl-0.1.1.dist-info/licenses/LICENSE +21 -0
- lapctl-0.1.1.dist-info/top_level.txt +1 -0
lapctl/core/battery.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""Battery monitoring loop emitting low/full events."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
from collections.abc import Callable
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from typing import Literal
|
|
9
|
+
|
|
10
|
+
from lapctl.drivers.base import BaseDriver
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass(frozen=True)
|
|
14
|
+
class BatteryEvent:
|
|
15
|
+
"""Event emitted when battery crosses low or full threshold."""
|
|
16
|
+
|
|
17
|
+
kind: Literal["low", "full"]
|
|
18
|
+
capacity: int
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class BatteryMonitor:
|
|
22
|
+
"""Polls driver battery metrics and emits threshold transition events."""
|
|
23
|
+
|
|
24
|
+
def __init__(self, driver: BaseDriver, low_threshold: int = 79) -> None:
|
|
25
|
+
self.driver = driver
|
|
26
|
+
self.low_threshold = low_threshold
|
|
27
|
+
self.low_battery_notified = False
|
|
28
|
+
self.full_battery_notified = False
|
|
29
|
+
|
|
30
|
+
def check_once(self) -> BatteryEvent | None:
|
|
31
|
+
"""Read current battery state via driver and return an event if crossed."""
|
|
32
|
+
state = self.driver.get_battery_state()
|
|
33
|
+
if state is None:
|
|
34
|
+
return None
|
|
35
|
+
|
|
36
|
+
cap, is_discharging, is_charging_or_full = state
|
|
37
|
+
|
|
38
|
+
if cap <= self.low_threshold and is_discharging:
|
|
39
|
+
if not self.low_battery_notified:
|
|
40
|
+
self.low_battery_notified = True
|
|
41
|
+
return BatteryEvent(kind="low", capacity=cap)
|
|
42
|
+
else:
|
|
43
|
+
if cap > self.low_threshold or not is_discharging:
|
|
44
|
+
self.low_battery_notified = False
|
|
45
|
+
|
|
46
|
+
if cap == 100 and is_charging_or_full:
|
|
47
|
+
if not self.full_battery_notified:
|
|
48
|
+
self.full_battery_notified = True
|
|
49
|
+
return BatteryEvent(kind="full", capacity=cap)
|
|
50
|
+
else:
|
|
51
|
+
if cap < 100 or not is_charging_or_full:
|
|
52
|
+
self.full_battery_notified = False
|
|
53
|
+
|
|
54
|
+
return None
|
|
55
|
+
|
|
56
|
+
def run(
|
|
57
|
+
self,
|
|
58
|
+
on_event: Callable[[BatteryEvent], None],
|
|
59
|
+
interval_seconds: int = 60,
|
|
60
|
+
) -> None:
|
|
61
|
+
"""Continuously monitor battery and invoke on_event when triggered."""
|
|
62
|
+
while True:
|
|
63
|
+
time.sleep(interval_seconds)
|
|
64
|
+
try:
|
|
65
|
+
event = self.check_once()
|
|
66
|
+
if event is not None:
|
|
67
|
+
on_event(event)
|
|
68
|
+
except Exception as e:
|
|
69
|
+
print(f"Error in battery monitor loop: {e}")
|