Metadata-Version: 2.1
Name: pyectool
Version: 0.2.0
Summary: Pyectool provides Python bindings for interacting with the Embedded Controller (EC) on ChromeOS and Framework devices, enabling seamless integration with other applications
Keywords: ectool,embedded controller,EC,pybind11,bindings
Author-Email: Ahmed Gamea <ahmed.gamea@ejust.edu.eg>
License: Copyright 2010 The ChromiumOS Authors
         Additions copyright 2024 Dustin L. Howett
         
         Redistribution and use in source and binary forms, with or without
         modification, are permitted provided that the following conditions are
         met:
         
            * Redistributions of source code must retain the above copyright
         notice, this list of conditions and the following disclaimer.
            * Redistributions in binary form must reproduce the above
         copyright notice, this list of conditions and the following disclaimer
         in the documentation and/or other materials provided with the
         distribution.
            * Neither the name of Google LLC nor the names of its
         contributors may be used to endorse or promote products derived from
         this software without specific prior written permission.
         
         THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
         "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
         LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
         A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
         OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
         SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
         LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
         DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
         THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
         OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
         
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: C++
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: POSIX :: Linux
Project-URL: Homepage, https://github.com/CCExtractor/libectool
Project-URL: Issues, https://github.com/CCExtractor/libectool/issues
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# Pyectool

**Pyectool** provides Python bindings for interacting with the Embedded Controller (EC) on ChromeOS and Framework devices.  
It is extracted from and based on [Dustin Howett's `ectool`](https://gitlab.howett.net/DHowett/ectool) and exposes EC control functions directly to Python via a native C++ extension built with `pybind11`.

Pyectool also provides a simple way to build the original `ectool` CLI tool, or to build `libectool`—a standalone C library that wrap most of ectool’s functionality, making it reusable in C/C++ projects or accessible from other languages. Both the CLI binary and the library are built automatically during installation.

## Features
- Python-native interface to low-level EC functionality via `pybind11`
- Supports fan duty control, temperature reading, AC power status, and more.
- Designed for hardware monitoring, thermal management, and fan control tooling.
- Bundles the native `ectool` CLI and `libectool` C library alongside the Python package:
  * `pyectool/bin/ectool`  (ectool CLI)
  * `pyectool/lib/libectool.a` (libectool static library)
  * `pyectool/include/libectool.h` (libectool C header)

---

## Installation

### Prerequisites

Install system dependencies:

```sh
sudo apt update
sudo apt install -y libusb-1.0-0-dev libftdi1-dev pkg-config
````
### Clone the repository

### Install the package

#### Option 1: System-wide (not recommended unless you know what you're doing)
```sh
sudo pip install .
```
Or:

```bash
sudo env "PIP_BREAK_SYSTEM_PACKAGES=1" pip install .
```
(Required on modern distros like Ubuntu 24.04 due to PEP 668.)

#### Option 2: Isolated virtual environment (recommended)
```bash
python3 -m venv ~/.venv/pyectool
source ~/.venv/pyectool/bin/activate
pip install .
```

### ⚠️ Important Note

After installation, **do not run Python from inside the `libectool/` directory**. It contains a `pyectool/` folder that may shadow the installed package.

Instead, test from a different directory:

```bash
cd ..
python -c "from pyectool import ECController; ec = ECController(); print(ec.is_on_ac())"
```

If you're using a virtual environment and want to preserve its `PATH`, use:
```bash
cd ..
sudo env "PATH=$PATH" python -c "from pyectool import ECController; ec = ECController(); print(ec.is_on_ac())"
```
This ensures the correct Python from your virtual environment is used even with `sudo`.

---

## Usage

### Create an EC controller instance

```python
from pyectool import ECController

ec = ECController()
```

### Available Methods


| Method                                                  | Description                                                               |
| ------------------------------------------------------- | ------------------------------------------------------------------------- |
| `ec.is_on_ac() -> bool`                                 | Returns `True` if the system is on AC power, else `False`.                |
| `ec.get_num_fans() -> int`                              | Returns the number of fan devices detected.                               |
| `ec.enable_fan_auto_ctrl(fan_idx: int) -> None`         | Enables automatic fan control for a specific fan.                         |
| `ec.enable_all_fans_auto_ctrl() -> None`                | Enables automatic control for all fans.                                   |
| `ec.set_fan_duty(percent: int, fan_idx: int) -> None`   | Sets fan duty (speed) as a percentage for a specific fan.                 |
| `ec.set_all_fans_duty(percent: int) -> None`            | Sets the same duty percentage for all fans.                               |
| `ec.set_fan_rpm(target_rpm: int, fan_idx: int) -> None` | Sets a specific RPM target for a specific fan.                            |
| `ec.set_all_fans_rpm(target_rpm: int) -> None`          | Sets the same RPM target for all fans.                                    |
| `ec.get_fan_rpm(fan_idx: int) -> int`                   | Returns current RPM of a specific fan.                                    |
| `ec.get_all_fans_rpm() -> list[int]`                    | Returns a list of current RPM values for all fans.                        |
| `ec.get_num_temp_sensors() -> int`                      | Returns the total number of temperature sensors detected.                 |
| `ec.get_temp(sensor_idx: int) -> int`                   | Returns the temperature (in °C) for the given sensor index.               |
| `ec.get_all_temps() -> list[int]`                       | Returns a list of all sensor temperatures (in °C).                        |
| `ec.get_max_temp() -> int`                              | Returns the highest temperature across all sensors.                       |
| `ec.get_max_non_battery_temp() -> int`                  | Returns the highest temperature excluding battery-related sensors.        |
| `ec.get_temp_info(sensor_idx: int) -> ECTempInfo`       | Returns detailed info for a sensor, including name, type, and thresholds. |

---

### `ECTempInfo`

Returned by `get_temp_info()`, acts like a `dict` with:

* `sensor_name`: str
* `sensor_type`: int
* `temp`: int
* `temp_fan_off`: int
* `temp_fan_max`: int

---

## License

BSD 3-Clause License
See the `LICENSE` file for full terms.
