mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
add time calculations to acpi parser
This commit is contained in:
34
EXAMPLES.md
34
EXAMPLES.md
@ -13,7 +13,11 @@ acpi -V | jc --acpi -p # or: jc -p acpi -V
|
||||
"until_charged": "00:29:20",
|
||||
"design_capacity_mah": 2110,
|
||||
"last_full_capacity": 2271,
|
||||
"last_full_capacity_percent": 100
|
||||
"last_full_capacity_percent": 100,
|
||||
"until_charged_hours": 0,
|
||||
"until_charged_minutes": 29,
|
||||
"until_charged_seconds": 20,
|
||||
"until_charged_total_seconds": 1760
|
||||
},
|
||||
{
|
||||
"type": "Adapter",
|
||||
@ -54,6 +58,34 @@ acpi -V | jc --acpi -p # or: jc -p acpi -V
|
||||
"messages": [
|
||||
"Processor 0 of 10"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": 2,
|
||||
"messages": [
|
||||
"x86_pkg_temp no state information available"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": 3,
|
||||
"messages": [
|
||||
"Processor 0 of 10"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": 4,
|
||||
"messages": [
|
||||
"intel_powerclamp no state information available"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": 5,
|
||||
"messages": [
|
||||
"Processor 0 of 10"
|
||||
]
|
||||
}
|
||||
]
|
||||
```
|
||||
|
@ -31,7 +31,11 @@ Examples:
|
||||
"until_charged": "00:29:20",
|
||||
"design_capacity_mah": 2110,
|
||||
"last_full_capacity": 2271,
|
||||
"last_full_capacity_percent": 100
|
||||
"last_full_capacity_percent": 100,
|
||||
"until_charged_hours": 0,
|
||||
"until_charged_minutes": 29,
|
||||
"until_charged_seconds": 20,
|
||||
"until_charged_total_seconds": 1760
|
||||
},
|
||||
{
|
||||
"type": "Adapter",
|
||||
@ -209,29 +213,37 @@ Returns:
|
||||
|
||||
[
|
||||
{
|
||||
"type": string,
|
||||
"id": integer,
|
||||
"state": string,
|
||||
"charge_percent": integer,
|
||||
"until_charged": string,
|
||||
"charge_remaining" string,
|
||||
"design_capacity_mah": integer,
|
||||
"last_full_capacity": integer,
|
||||
"last_full_capacity_percent": integer,
|
||||
"on-line": boolean,
|
||||
"mode": string,
|
||||
"temperature": float,
|
||||
"temperature_unit": string,
|
||||
"type": string,
|
||||
"id": integer,
|
||||
"state": string,
|
||||
"charge_percent": integer,
|
||||
"until_charged": string,
|
||||
"until_charged_hours": integer,
|
||||
"until_charged_minuts": integer,
|
||||
"until_charged_seconds": integer,
|
||||
"until_charged_total_seconds": integer,
|
||||
"charge_remaining": string,
|
||||
"charge_remaining_hours": integer,
|
||||
"charge_remaining_minutes": integer,
|
||||
"charge_remaining_seconds": integer,
|
||||
"charge_remaining_total_seconds": integer,
|
||||
"design_capacity_mah": integer,
|
||||
"last_full_capacity": integer,
|
||||
"last_full_capacity_percent": integer,
|
||||
"on-line": boolean,
|
||||
"mode": string,
|
||||
"temperature": float,
|
||||
"temperature_unit": string,
|
||||
"trip_points": [
|
||||
{
|
||||
"id": integer,
|
||||
"switches_to_mode": string,
|
||||
"temperature": float,
|
||||
"temperature_unit": string
|
||||
"id": integer,
|
||||
"switches_to_mode": string,
|
||||
"temperature": float,
|
||||
"temperature_unit": string
|
||||
}
|
||||
],
|
||||
"messages": [
|
||||
string
|
||||
string
|
||||
]
|
||||
}
|
||||
]
|
||||
|
@ -29,7 +29,11 @@ Examples:
|
||||
"until_charged": "00:29:20",
|
||||
"design_capacity_mah": 2110,
|
||||
"last_full_capacity": 2271,
|
||||
"last_full_capacity_percent": 100
|
||||
"last_full_capacity_percent": 100,
|
||||
"until_charged_hours": 0,
|
||||
"until_charged_minutes": 29,
|
||||
"until_charged_seconds": 20,
|
||||
"until_charged_total_seconds": 1760
|
||||
},
|
||||
{
|
||||
"type": "Adapter",
|
||||
@ -214,29 +218,37 @@ def process(proc_data):
|
||||
|
||||
[
|
||||
{
|
||||
"type": string,
|
||||
"id": integer,
|
||||
"state": string,
|
||||
"charge_percent": integer,
|
||||
"until_charged": string,
|
||||
"charge_remaining" string,
|
||||
"design_capacity_mah": integer,
|
||||
"last_full_capacity": integer,
|
||||
"last_full_capacity_percent": integer,
|
||||
"on-line": boolean,
|
||||
"mode": string,
|
||||
"temperature": float,
|
||||
"temperature_unit": string,
|
||||
"type": string,
|
||||
"id": integer,
|
||||
"state": string,
|
||||
"charge_percent": integer,
|
||||
"until_charged": string,
|
||||
"until_charged_hours": integer,
|
||||
"until_charged_minuts": integer,
|
||||
"until_charged_seconds": integer,
|
||||
"until_charged_total_seconds": integer,
|
||||
"charge_remaining": string,
|
||||
"charge_remaining_hours": integer,
|
||||
"charge_remaining_minutes": integer,
|
||||
"charge_remaining_seconds": integer,
|
||||
"charge_remaining_total_seconds": integer,
|
||||
"design_capacity_mah": integer,
|
||||
"last_full_capacity": integer,
|
||||
"last_full_capacity_percent": integer,
|
||||
"on-line": boolean,
|
||||
"mode": string,
|
||||
"temperature": float,
|
||||
"temperature_unit": string,
|
||||
"trip_points": [
|
||||
{
|
||||
"id": integer,
|
||||
"switches_to_mode": string,
|
||||
"temperature": float,
|
||||
"temperature_unit": string
|
||||
"id": integer,
|
||||
"switches_to_mode": string,
|
||||
"temperature": float,
|
||||
"temperature_unit": string
|
||||
}
|
||||
],
|
||||
"messages": [
|
||||
string
|
||||
string
|
||||
]
|
||||
}
|
||||
]
|
||||
@ -278,6 +290,21 @@ def process(proc_data):
|
||||
except (ValueError):
|
||||
tp[key] = None
|
||||
|
||||
for entry in proc_data:
|
||||
if 'until_charged' in entry:
|
||||
entry['until_charged_hours'] = int(entry['until_charged'].split(':')[0])
|
||||
entry['until_charged_minutes'] = int(entry['until_charged'].split(':')[1])
|
||||
entry['until_charged_seconds'] = int(entry['until_charged'].split(':')[2])
|
||||
entry['until_charged_total_seconds'] = (entry['until_charged_hours'] * 3600) + \
|
||||
(entry['until_charged_minutes'] * 60) + entry['until_charged_seconds']
|
||||
|
||||
if 'charge_remaining' in entry:
|
||||
entry['charge_remaining_hours'] = int(entry['charge_remaining'].split(':')[0])
|
||||
entry['charge_remaining_minutes'] = int(entry['charge_remaining'].split(':')[1])
|
||||
entry['charge_remaining_seconds'] = int(entry['charge_remaining'].split(':')[2])
|
||||
entry['charge_remaining_total_seconds'] = (entry['charge_remaining_hours'] * 3600) + \
|
||||
(entry['charge_remaining_minutes'] * 60) + entry['charge_remaining_seconds']
|
||||
|
||||
return proc_data
|
||||
|
||||
|
||||
|
2
tests/fixtures/generic/acpi-V.json
vendored
2
tests/fixtures/generic/acpi-V.json
vendored
@ -1 +1 @@
|
||||
[{"type": "Battery", "id": 0, "state": "Charging", "charge_percent": 71, "until_charged": "00:29:20", "design_capacity_mah": 2110, "last_full_capacity": 2271, "last_full_capacity_percent": 100}, {"type": "Battery", "id": 1, "state": "Discharging", "charge_percent": 98, "charge_remaining": "01:43:14", "design_capacity_mah": 4400, "last_full_capacity": 3013, "last_full_capacity_percent": 68}, {"type": "Battery", "id": 2, "state": "Discharging", "charge_percent": 0}, {"type": "Battery", "id": 3, "state": "Full", "charge_percent": 100}, {"type": "Adapter", "id": 0, "on-line": true}, {"type": "Adapter", "id": 1, "on-line": false}, {"type": "Thermal", "id": 0, "mode": "ok", "temperature": 46.0, "temperature_unit": "C", "trip_points": [{"id": 0, "switches_to_mode": "critical", "temperature": 127.0, "temperature_unit": "C"}, {"id": 1, "switches_to_mode": "hot", "temperature": 127.0, "temperature_unit": "C"}]}, {"type": "Thermal", "id": 1, "mode": "ok", "temperature": 55.0, "temperature_unit": "C", "trip_points": [{"id": 0, "switches_to_mode": "critical", "temperature": 130.0, "temperature_unit": "C"}, {"id": 1, "switches_to_mode": "hot", "temperature": 100.0, "temperature_unit": "C"}]}, {"type": "Cooling", "id": 0, "messages": ["Processor 0 of 10"]}, {"type": "Cooling", "id": 1, "messages": ["Processor 0 of 10"]}, {"type": "Cooling", "id": 2, "messages": ["x86_pkg_temp no state information available"]}, {"type": "Cooling", "id": 3, "messages": ["Processor 0 of 10"]}, {"type": "Cooling", "id": 4, "messages": ["intel_powerclamp no state information available", "another message"]}, {"type": "Cooling", "id": 5, "messages": ["Processor 0 of 10"]}]
|
||||
[{"type":"Battery","id":0,"state":"Charging","charge_percent":71,"until_charged":"00:29:20","design_capacity_mah":2110,"last_full_capacity":2271,"last_full_capacity_percent":100,"until_charged_hours":0,"until_charged_minutes":29,"until_charged_seconds":20,"until_charged_total_seconds":1760},{"type":"Battery","id":1,"state":"Discharging","charge_percent":98,"charge_remaining":"01:43:14","design_capacity_mah":4400,"last_full_capacity":3013,"last_full_capacity_percent":68,"charge_remaining_hours":1,"charge_remaining_minutes":43,"charge_remaining_seconds":14,"charge_remaining_total_seconds":6194},{"type":"Battery","id":2,"state":"Discharging","charge_percent":0},{"type":"Battery","id":3,"state":"Full","charge_percent":100},{"type":"Adapter","id":0,"on-line":true},{"type":"Adapter","id":1,"on-line":false},{"type":"Thermal","id":0,"mode":"ok","temperature":46.0,"temperature_unit":"C","trip_points":[{"id":0,"switches_to_mode":"critical","temperature":127.0,"temperature_unit":"C"},{"id":1,"switches_to_mode":"hot","temperature":127.0,"temperature_unit":"C"}]},{"type":"Thermal","id":1,"mode":"ok","temperature":55.0,"temperature_unit":"C","trip_points":[{"id":0,"switches_to_mode":"critical","temperature":130.0,"temperature_unit":"C"},{"id":1,"switches_to_mode":"hot","temperature":100.0,"temperature_unit":"C"}]},{"type":"Cooling","id":0,"messages":["Processor 0 of 10"]},{"type":"Cooling","id":1,"messages":["Processor 0 of 10"]},{"type":"Cooling","id":2,"messages":["x86_pkg_temp no state information available"]},{"type":"Cooling","id":3,"messages":["Processor 0 of 10"]},{"type":"Cooling","id":4,"messages":["intel_powerclamp no state information available","another message"]},{"type":"Cooling","id":5,"messages":["Processor 0 of 10"]}]
|
||||
|
2
tests/fixtures/generic/acpi-V2.json
vendored
2
tests/fixtures/generic/acpi-V2.json
vendored
@ -1 +1 @@
|
||||
[{"type": "Battery", "id": 0, "state": "Charging", "charge_percent": 71, "until_charged": "00:29:20", "design_capacity_mah": 2110, "last_full_capacity": 2271, "last_full_capacity_percent": 100}, {"type": "Adapter", "id": 0, "on-line": true}, {"type": "Thermal", "id": 0, "mode": "ok", "temperature": 46.0, "temperature_unit": "C", "trip_points": [{"id": 0, "switches_to_mode": "critical", "temperature": 127.0, "temperature_unit": "C"}, {"id": 1, "switches_to_mode": "hot", "temperature": 127.0, "temperature_unit": "C"}]}, {"type": "Cooling", "id": 0, "messages": ["Processor 0 of 10"]}, {"type": "Cooling", "id": 1, "messages": ["Processor 0 of 10"]}, {"type": "Cooling", "id": 2, "messages": ["x86_pkg_temp no state information available"]}, {"type": "Cooling", "id": 3, "messages": ["Processor 0 of 10"]}, {"type": "Cooling", "id": 4, "messages": ["intel_powerclamp no state information available"]}, {"type": "Cooling", "id": 5, "messages": ["Processor 0 of 10"]}]
|
||||
[{"type":"Battery","id":0,"state":"Charging","charge_percent":71,"until_charged":"00:29:20","design_capacity_mah":2110,"last_full_capacity":2271,"last_full_capacity_percent":100,"until_charged_hours":0,"until_charged_minutes":29,"until_charged_seconds":20,"until_charged_total_seconds":1760},{"type":"Adapter","id":0,"on-line":true},{"type":"Thermal","id":0,"mode":"ok","temperature":46.0,"temperature_unit":"C","trip_points":[{"id":0,"switches_to_mode":"critical","temperature":127.0,"temperature_unit":"C"},{"id":1,"switches_to_mode":"hot","temperature":127.0,"temperature_unit":"C"}]},{"type":"Cooling","id":0,"messages":["Processor 0 of 10"]},{"type":"Cooling","id":1,"messages":["Processor 0 of 10"]},{"type":"Cooling","id":2,"messages":["x86_pkg_temp no state information available"]},{"type":"Cooling","id":3,"messages":["Processor 0 of 10"]},{"type":"Cooling","id":4,"messages":["intel_powerclamp no state information available"]},{"type":"Cooling","id":5,"messages":["Processor 0 of 10"]}]
|
||||
|
2
tests/fixtures/generic/acpi-V3.json
vendored
2
tests/fixtures/generic/acpi-V3.json
vendored
@ -1 +1 @@
|
||||
[{"type": "Battery", "id": 0, "state": "Discharging", "charge_percent": 98, "charge_remaining": "01:43:14", "design_capacity_mah": 4400, "last_full_capacity": 3013, "last_full_capacity_percent": 68}, {"type": "Battery", "id": 1, "state": "Discharging", "charge_percent": 0}, {"type": "Adapter", "id": 0, "on-line": false}, {"type": "Thermal", "id": 0, "mode": "ok", "temperature": 60.5, "temperature_unit": "C", "trip_points": [{"id": 0, "switches_to_mode": "critical", "temperature": 84.0, "temperature_unit": "C"}]}, {"type": "Cooling", "id": 0, "messages": ["Processor 0 of 3"]}, {"type": "Cooling", "id": 1, "messages": ["intel_powerclamp no state information available"]}, {"type": "Cooling", "id": 2, "messages": ["Processor 0 of 3"]}, {"type": "Cooling", "id": 3, "messages": ["x86_pkg_temp no state information available"]}, {"type": "Cooling", "id": 4, "messages": ["Processor 0 of 3"]}, {"type": "Cooling", "id": 5, "messages": ["LCD 0 of 15"]}, {"type": "Cooling", "id": 6, "messages": ["Processor 0 of 3"]}]
|
||||
[{"type":"Battery","id":0,"state":"Discharging","charge_percent":98,"charge_remaining":"01:43:14","design_capacity_mah":4400,"last_full_capacity":3013,"last_full_capacity_percent":68,"charge_remaining_hours":1,"charge_remaining_minutes":43,"charge_remaining_seconds":14,"charge_remaining_total_seconds":6194},{"type":"Battery","id":1,"state":"Discharging","charge_percent":0},{"type":"Adapter","id":0,"on-line":false},{"type":"Thermal","id":0,"mode":"ok","temperature":60.5,"temperature_unit":"C","trip_points":[{"id":0,"switches_to_mode":"critical","temperature":84.0,"temperature_unit":"C"}]},{"type":"Cooling","id":0,"messages":["Processor 0 of 3"]},{"type":"Cooling","id":1,"messages":["intel_powerclamp no state information available"]},{"type":"Cooling","id":2,"messages":["Processor 0 of 3"]},{"type":"Cooling","id":3,"messages":["x86_pkg_temp no state information available"]},{"type":"Cooling","id":4,"messages":["Processor 0 of 3"]},{"type":"Cooling","id":5,"messages":["LCD 0 of 15"]},{"type":"Cooling","id":6,"messages":["Processor 0 of 3"]}]
|
||||
|
2
tests/fixtures/generic/acpi-V4.json
vendored
2
tests/fixtures/generic/acpi-V4.json
vendored
@ -1 +1 @@
|
||||
[{"type": "Battery", "id": 0, "state": "Full", "charge_percent": 100, "design_capacity_mah": 1969, "last_full_capacity": 2118, "last_full_capacity_percent": 100}, {"type": "Adapter", "id": 0, "on-line": true}, {"type": "Thermal", "id": 0, "mode": "ok", "temperature": 45.0, "temperature_unit": "C", "trip_points": [{"id": 0, "switches_to_mode": "critical", "temperature": 127.0, "temperature_unit": "C"}, {"id": 1, "switches_to_mode": "hot", "temperature": 127.0, "temperature_unit": "C"}]}, {"type": "Cooling", "id": 0, "messages": ["Processor 0 of 10"]}, {"type": "Cooling", "id": 1, "messages": ["Processor 0 of 10"]}, {"type": "Cooling", "id": 2, "messages": ["x86_pkg_temp no state information available"]}, {"type": "Cooling", "id": 3, "messages": ["Processor 0 of 10"]}, {"type": "Cooling", "id": 4, "messages": ["intel_powerclamp no state information available"]}, {"type": "Cooling", "id": 5, "messages": ["Processor 0 of 10"]}]
|
||||
[{"type":"Battery","id":0,"state":"Full","charge_percent":100,"design_capacity_mah":1969,"last_full_capacity":2118,"last_full_capacity_percent":100},{"type":"Adapter","id":0,"on-line":true},{"type":"Thermal","id":0,"mode":"ok","temperature":45.0,"temperature_unit":"C","trip_points":[{"id":0,"switches_to_mode":"critical","temperature":127.0,"temperature_unit":"C"},{"id":1,"switches_to_mode":"hot","temperature":127.0,"temperature_unit":"C"}]},{"type":"Cooling","id":0,"messages":["Processor 0 of 10"]},{"type":"Cooling","id":1,"messages":["Processor 0 of 10"]},{"type":"Cooling","id":2,"messages":["x86_pkg_temp no state information available"]},{"type":"Cooling","id":3,"messages":["Processor 0 of 10"]},{"type":"Cooling","id":4,"messages":["intel_powerclamp no state information available"]},{"type":"Cooling","id":5,"messages":["Processor 0 of 10"]}]
|
||||
|
Reference in New Issue
Block a user