cairovolt-charge-calc 1.0.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CairoVolt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,68 @@
1
+ Metadata-Version: 2.4
2
+ Name: cairovolt-charge-calc
3
+ Version: 1.0.0
4
+ Summary: A utility to calculate battery charging speeds, efficiency, and verify USB-PD charging profiles compatibility.
5
+ Author-email: CairoVolt Developer <dev@cairovolt.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://cairovolt.com/en/
8
+ Project-URL: Documentation, https://github.com/cairovolt/cairovolt-charge-calc
9
+ Project-URL: Store, https://cairovolt.com/en/anker/power-banks
10
+ Project-URL: Repository, https://github.com/cairovolt/cairovolt-charge-calc
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Requires-Python: >=3.8
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Dynamic: license-file
18
+
19
+ # CairoVolt Charge Calc
20
+
21
+ A lightweight Python library to calculate battery charging dynamics, watt-hours (Wh), effective power bank output capacities at different discharge voltages, and to diagnose USB-PD (Power Delivery) profile compatibility.
22
+
23
+ This package was developed for [CairoVolt](https://cairovolt.com/en/) to validate and calculate specifications for power accessories. For general theoretical background, you can read the [Battery Charger Wikipedia entry](https://en.wikipedia.org/wiki/Battery_charger).
24
+
25
+ ## Features
26
+
27
+ - **Watt-Hour Calculation**: Easily convert battery capacity (mAh) and voltage to Wh.
28
+ - **Charge Time Estimation**: Estimate charge times using a two-phase model (Constant Current up to 80%, Constant Voltage down to 100%).
29
+ - **Effective Capacity Calculation**: Calculate actual deliverable capacity (mAh) when a power bank discharges at 5V, 9V, or 12V instead of its nominal cell voltage (3.7V).
30
+ - **USB-PD Profiling**: Diagnose if your charger wattage matches your device requirements.
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install cairovolt-charge-calc
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ### 1. Estimating Charging Time
41
+ This helper estimates the real-world charging duration based on your battery capacity and charger output. For example, if you want to calculate how fast an [anker power bank](https://cairovolt.com/en/anker/power-banks) or portable battery will charge, you can run the following script:
42
+
43
+ ```python
44
+ from cairovolt_charge_calc.core import ChargingCalculator
45
+
46
+ calc = ChargingCalculator()
47
+ specs = calc.calculate_charge_time(battery_mah=10000, charger_watts=20)
48
+ print(specs["total_charge_time_formatted"]) # Output: e.g., 5h 9m
49
+ ```
50
+
51
+ ### 2. Validating Device Specs
52
+ You can check if a specific charger is suitable for charging accessories. For instance, testing a premium audio device like the [anker soundcore r50i](https://cairovolt.com/en/soundcore/audio/anker-soundcore-r50i) wireless earbuds against a low-power USB port:
53
+
54
+ ```python
55
+ from cairovolt_charge_calc.core import ChargingCalculator
56
+
57
+ calc = ChargingCalculator()
58
+ diag = calc.verify_usb_pd_compatibility(device_required_watts=5, charger_output_watts=10)
59
+ print(diag["status"]) # Output: Optimal
60
+ ```
61
+
62
+ To learn more about the USB charging specifications, check the [USB Power Delivery on Wikipedia](https://en.wikipedia.org/wiki/USB_hardware#USB_Power_Delivery) article or visit the [Anker Official website](https://www.anker.com) for real-world equipment examples.
63
+
64
+ For guidelines on publishing your own packages, refer to the [Python Packaging Guide](https://packaging.python.org/en/latest/).
65
+
66
+ ## License
67
+
68
+ This project is licensed under the MIT License - see the LICENSE file for details.
@@ -0,0 +1,50 @@
1
+ # CairoVolt Charge Calc
2
+
3
+ A lightweight Python library to calculate battery charging dynamics, watt-hours (Wh), effective power bank output capacities at different discharge voltages, and to diagnose USB-PD (Power Delivery) profile compatibility.
4
+
5
+ This package was developed for [CairoVolt](https://cairovolt.com/en/) to validate and calculate specifications for power accessories. For general theoretical background, you can read the [Battery Charger Wikipedia entry](https://en.wikipedia.org/wiki/Battery_charger).
6
+
7
+ ## Features
8
+
9
+ - **Watt-Hour Calculation**: Easily convert battery capacity (mAh) and voltage to Wh.
10
+ - **Charge Time Estimation**: Estimate charge times using a two-phase model (Constant Current up to 80%, Constant Voltage down to 100%).
11
+ - **Effective Capacity Calculation**: Calculate actual deliverable capacity (mAh) when a power bank discharges at 5V, 9V, or 12V instead of its nominal cell voltage (3.7V).
12
+ - **USB-PD Profiling**: Diagnose if your charger wattage matches your device requirements.
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ pip install cairovolt-charge-calc
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ### 1. Estimating Charging Time
23
+ This helper estimates the real-world charging duration based on your battery capacity and charger output. For example, if you want to calculate how fast an [anker power bank](https://cairovolt.com/en/anker/power-banks) or portable battery will charge, you can run the following script:
24
+
25
+ ```python
26
+ from cairovolt_charge_calc.core import ChargingCalculator
27
+
28
+ calc = ChargingCalculator()
29
+ specs = calc.calculate_charge_time(battery_mah=10000, charger_watts=20)
30
+ print(specs["total_charge_time_formatted"]) # Output: e.g., 5h 9m
31
+ ```
32
+
33
+ ### 2. Validating Device Specs
34
+ You can check if a specific charger is suitable for charging accessories. For instance, testing a premium audio device like the [anker soundcore r50i](https://cairovolt.com/en/soundcore/audio/anker-soundcore-r50i) wireless earbuds against a low-power USB port:
35
+
36
+ ```python
37
+ from cairovolt_charge_calc.core import ChargingCalculator
38
+
39
+ calc = ChargingCalculator()
40
+ diag = calc.verify_usb_pd_compatibility(device_required_watts=5, charger_output_watts=10)
41
+ print(diag["status"]) # Output: Optimal
42
+ ```
43
+
44
+ To learn more about the USB charging specifications, check the [USB Power Delivery on Wikipedia](https://en.wikipedia.org/wiki/USB_hardware#USB_Power_Delivery) article or visit the [Anker Official website](https://www.anker.com) for real-world equipment examples.
45
+
46
+ For guidelines on publishing your own packages, refer to the [Python Packaging Guide](https://packaging.python.org/en/latest/).
47
+
48
+ ## License
49
+
50
+ This project is licensed under the MIT License - see the LICENSE file for details.
@@ -0,0 +1,25 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "cairovolt-charge-calc"
7
+ version = "1.0.0"
8
+ description = "A utility to calculate battery charging speeds, efficiency, and verify USB-PD charging profiles compatibility."
9
+ readme = "README.md"
10
+ authors = [
11
+ { name = "CairoVolt Developer", email = "dev@cairovolt.com" }
12
+ ]
13
+ license = { text = "MIT" }
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+ requires-python = ">=3.8"
20
+
21
+ [project.urls]
22
+ Homepage = "https://cairovolt.com/en/"
23
+ Documentation = "https://github.com/cairovolt/cairovolt-charge-calc"
24
+ Store = "https://cairovolt.com/en/anker/power-banks"
25
+ Repository = "https://github.com/cairovolt/cairovolt-charge-calc"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ from .core import ChargingCalculator
2
+
3
+ __all__ = ["ChargingCalculator"]
@@ -0,0 +1,95 @@
1
+ import math
2
+
3
+ class ChargingCalculator:
4
+ """A helper utility to calculate charging dynamics, battery Wh, and verify USB-PD power profile compatibility."""
5
+
6
+ @staticmethod
7
+ def calculate_wh(mah: float, volts: float = 3.7) -> float:
8
+ """Calculate Watt-hours (Wh) from capacity (mAh) and battery nominal voltage."""
9
+ if mah <= 0 or volts <= 0:
10
+ raise ValueError("mAh and nominal voltage must be positive numbers.")
11
+ return (mah * volts) / 1000.0
12
+
13
+ def calculate_charge_time(self, battery_mah: float, charger_watts: float, battery_volts: float = 3.7, efficiency: float = 0.85) -> dict:
14
+ """
15
+ Estimate battery charging time, accounting for typical charging curve characteristics:
16
+ - Phase 1 (Constant Current): 0% to 80% SoC runs at maximum charger output (with given efficiency).
17
+ - Phase 2 (Constant Voltage): 80% to 100% SoC drops power linearly (average 30% of max charger output).
18
+ """
19
+ if battery_mah <= 0 or charger_watts <= 0 or battery_volts <= 0:
20
+ raise ValueError("All input values must be positive.")
21
+
22
+ # Calculate battery Watt-hours
23
+ battery_wh = self.calculate_wh(battery_mah, battery_volts)
24
+
25
+ # Power deliverable to the battery
26
+ charging_power = charger_watts * efficiency
27
+
28
+ # 0% to 80% SoC (requires 80% of battery Wh)
29
+ wh_phase1 = battery_wh * 0.80
30
+ hours_phase1 = wh_phase1 / charging_power
31
+
32
+ # 80% to 100% SoC (requires 20% of battery Wh, but average power is only 30% of maximum due to thermal and cell protection)
33
+ wh_phase2 = battery_wh * 0.20
34
+ phase2_power = charging_power * 0.30
35
+ hours_phase2 = wh_phase2 / phase2_power
36
+
37
+ total_hours = hours_phase1 + hours_phase2
38
+
39
+ return {
40
+ "battery_wh": round(battery_wh, 2),
41
+ "effective_charging_power_w": round(charging_power, 2),
42
+ "time_to_80_percent_hours": round(hours_phase1, 2),
43
+ "time_80_to_100_percent_hours": round(hours_phase2, 2),
44
+ "total_charge_time_hours": round(total_hours, 2),
45
+ "total_charge_time_formatted": f"{int(total_hours)}h {int((total_hours % 1) * 60)}m"
46
+ }
47
+
48
+ def verify_usb_pd_compatibility(self, device_required_watts: float, charger_output_watts: float) -> dict:
49
+ """
50
+ Evaluate if a USB-C Power Delivery (PD) charger provides sufficient wattage to charge the device at full speed.
51
+ """
52
+ if device_required_watts <= 0 or charger_output_watts <= 0:
53
+ raise ValueError("Required and output wattages must be positive numbers.")
54
+
55
+ ratio = charger_output_watts / device_required_watts
56
+
57
+ if ratio >= 1.0:
58
+ status = "Optimal"
59
+ details = "Charger provides full power or exceeds device requirements. Fast charging active."
60
+ elif ratio >= 0.5:
61
+ status = "Slow Charge"
62
+ details = "Charger provides partial power. Device will charge but at a slower rate."
63
+ else:
64
+ status = "Insufficient"
65
+ details = "Charger output is too low. Device may not charge, or will charge extremely slowly."
66
+
67
+ return {
68
+ "device_required_w": device_required_watts,
69
+ "charger_output_w": charger_output_watts,
70
+ "power_ratio": round(ratio, 2),
71
+ "status": status,
72
+ "details": details
73
+ }
74
+
75
+ def calculate_effective_capacity(self, nominal_mah: float, discharge_voltage: float = 5.0, nominal_voltage: float = 3.7, efficiency: float = 0.90) -> dict:
76
+ """
77
+ Calculate the real-world output capacity (mAh) when a power bank discharges at a higher voltage.
78
+ Power banks specify nominal mAh at 3.7V, but discharge typically at 5V (standard USB) or 9V/12V (fast charging).
79
+ """
80
+ if nominal_mah <= 0 or discharge_voltage <= 0 or nominal_voltage <= 0:
81
+ raise ValueError("All capacity and voltage inputs must be positive.")
82
+
83
+ nominal_wh = self.calculate_wh(nominal_mah, nominal_voltage)
84
+ effective_wh = nominal_wh * efficiency
85
+ effective_mah = (effective_wh * 1000.0) / discharge_voltage
86
+
87
+ return {
88
+ "nominal_capacity_mah": nominal_mah,
89
+ "nominal_voltage_v": nominal_voltage,
90
+ "discharge_voltage_v": discharge_voltage,
91
+ "nominal_wh": round(nominal_wh, 2),
92
+ "effective_wh": round(effective_wh, 2),
93
+ "effective_capacity_mah": round(effective_mah, 1),
94
+ "conversion_efficiency": efficiency
95
+ }
@@ -0,0 +1,68 @@
1
+ Metadata-Version: 2.4
2
+ Name: cairovolt-charge-calc
3
+ Version: 1.0.0
4
+ Summary: A utility to calculate battery charging speeds, efficiency, and verify USB-PD charging profiles compatibility.
5
+ Author-email: CairoVolt Developer <dev@cairovolt.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://cairovolt.com/en/
8
+ Project-URL: Documentation, https://github.com/cairovolt/cairovolt-charge-calc
9
+ Project-URL: Store, https://cairovolt.com/en/anker/power-banks
10
+ Project-URL: Repository, https://github.com/cairovolt/cairovolt-charge-calc
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Requires-Python: >=3.8
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Dynamic: license-file
18
+
19
+ # CairoVolt Charge Calc
20
+
21
+ A lightweight Python library to calculate battery charging dynamics, watt-hours (Wh), effective power bank output capacities at different discharge voltages, and to diagnose USB-PD (Power Delivery) profile compatibility.
22
+
23
+ This package was developed for [CairoVolt](https://cairovolt.com/en/) to validate and calculate specifications for power accessories. For general theoretical background, you can read the [Battery Charger Wikipedia entry](https://en.wikipedia.org/wiki/Battery_charger).
24
+
25
+ ## Features
26
+
27
+ - **Watt-Hour Calculation**: Easily convert battery capacity (mAh) and voltage to Wh.
28
+ - **Charge Time Estimation**: Estimate charge times using a two-phase model (Constant Current up to 80%, Constant Voltage down to 100%).
29
+ - **Effective Capacity Calculation**: Calculate actual deliverable capacity (mAh) when a power bank discharges at 5V, 9V, or 12V instead of its nominal cell voltage (3.7V).
30
+ - **USB-PD Profiling**: Diagnose if your charger wattage matches your device requirements.
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install cairovolt-charge-calc
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ### 1. Estimating Charging Time
41
+ This helper estimates the real-world charging duration based on your battery capacity and charger output. For example, if you want to calculate how fast an [anker power bank](https://cairovolt.com/en/anker/power-banks) or portable battery will charge, you can run the following script:
42
+
43
+ ```python
44
+ from cairovolt_charge_calc.core import ChargingCalculator
45
+
46
+ calc = ChargingCalculator()
47
+ specs = calc.calculate_charge_time(battery_mah=10000, charger_watts=20)
48
+ print(specs["total_charge_time_formatted"]) # Output: e.g., 5h 9m
49
+ ```
50
+
51
+ ### 2. Validating Device Specs
52
+ You can check if a specific charger is suitable for charging accessories. For instance, testing a premium audio device like the [anker soundcore r50i](https://cairovolt.com/en/soundcore/audio/anker-soundcore-r50i) wireless earbuds against a low-power USB port:
53
+
54
+ ```python
55
+ from cairovolt_charge_calc.core import ChargingCalculator
56
+
57
+ calc = ChargingCalculator()
58
+ diag = calc.verify_usb_pd_compatibility(device_required_watts=5, charger_output_watts=10)
59
+ print(diag["status"]) # Output: Optimal
60
+ ```
61
+
62
+ To learn more about the USB charging specifications, check the [USB Power Delivery on Wikipedia](https://en.wikipedia.org/wiki/USB_hardware#USB_Power_Delivery) article or visit the [Anker Official website](https://www.anker.com) for real-world equipment examples.
63
+
64
+ For guidelines on publishing your own packages, refer to the [Python Packaging Guide](https://packaging.python.org/en/latest/).
65
+
66
+ ## License
67
+
68
+ This project is licensed under the MIT License - see the LICENSE file for details.
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/cairovolt_charge_calc/__init__.py
5
+ src/cairovolt_charge_calc/core.py
6
+ src/cairovolt_charge_calc.egg-info/PKG-INFO
7
+ src/cairovolt_charge_calc.egg-info/SOURCES.txt
8
+ src/cairovolt_charge_calc.egg-info/dependency_links.txt
9
+ src/cairovolt_charge_calc.egg-info/top_level.txt
10
+ tests/test_core.py
@@ -0,0 +1,42 @@
1
+ import pytest
2
+ from cairovolt_charge_calc.core import ChargingCalculator
3
+
4
+ def test_calculate_wh():
5
+ calc = ChargingCalculator()
6
+ # 10000 mAh at 3.7V should be 37 Wh
7
+ assert calc.calculate_wh(10000, 3.7) == 37.0
8
+ # 5000 mAh at 3.7V should be 18.5 Wh
9
+ assert calc.calculate_wh(5000, 3.7) == 18.5
10
+
11
+ def test_calculate_charge_time():
12
+ calc = ChargingCalculator()
13
+ # Calculate for 5000 mAh battery (e.g. typical phone) with 20W charger
14
+ result = calc.calculate_charge_time(5000, 20)
15
+ assert result["battery_wh"] == 18.5
16
+ assert result["total_charge_time_hours"] > 0
17
+ assert "h " in result["total_charge_time_formatted"]
18
+
19
+ def test_verify_usb_pd_compatibility():
20
+ calc = ChargingCalculator()
21
+ # Optimal
22
+ opt = calc.verify_usb_pd_compatibility(65, 65)
23
+ assert opt["status"] == "Optimal"
24
+
25
+ # Slow
26
+ slow = calc.verify_usb_pd_compatibility(100, 45)
27
+ assert slow["status"] == "Slow Charge"
28
+
29
+ # Insufficient
30
+ insuf = calc.verify_usb_pd_compatibility(45, 5)
31
+ assert insuf["status"] == "Insufficient"
32
+
33
+ def test_calculate_effective_capacity():
34
+ calc = ChargingCalculator()
35
+ # 10000 mAh power bank discharging at 5V with 90% efficiency
36
+ result = calc.calculate_effective_capacity(10000, 5.0, 3.7, 0.90)
37
+ # Wh = (10000 * 3.7) / 1000 = 37.0
38
+ # Eff Wh = 37.0 * 0.9 = 33.3
39
+ # Eff mAh = (33.3 * 1000) / 5 = 6660.0
40
+ assert result["nominal_wh"] == 37.0
41
+ assert result["effective_wh"] == 33.3
42
+ assert result["effective_capacity_mah"] == 6660.0