Skip to main content

Python bindings for the e7-switcher C++ client

Project description

E7 Switcher Library

A cross-platform library for controlling Switcher smart home devices from both ESP32 and desktop platforms (Mac/Linux).

Features

  • Control Switcher devices (switches, AC units, etc.)
  • Cross-platform compatibility (ESP32 and Mac/Linux)
  • Easy integration with PlatformIO and CMake projects
  • Python bindings for easy integration with Python projects

Installation

Using PlatformIO

Add the library to your platformio.ini file:

lib_deps = 
    https://github.com/elhanan7/e7-switcher.git

Using CMake

There are multiple ways to include this library in your CMake project:

Option 1: Using FetchContent

include(FetchContent)
FetchContent_Declare(
    e7-switcher
    GIT_REPOSITORY https://github.com/elhanan7/e7-switcher.git
    GIT_TAG main  # or specific tag/commit
)
FetchContent_MakeAvailable(e7-switcher)

# Link with your target
target_link_libraries(your_target PRIVATE e7-switcher)

Option 2: Using find_package

First, install the library:

git clone https://github.com/elhanan7/e7-switcher.git
cd e7-switcher
mkdir build && cd build
cmake ..
make
sudo make install

Then in your CMakeLists.txt:

find_package(e7-switcher REQUIRED)
target_link_libraries(your_target PRIVATE e7-switcher::e7-switcher)

Using Python Bindings

The library provides Python bindings using pybind11, allowing you to control Switcher devices from Python.

Installation

# From the repository root
cd python
pip install .

# To specify a Python version
PYTHON_VERSION=3.9 pip install .

Alternatively, you can use the provided build script:

# From the repository root
cd python
./build_bindings.sh --install

# To specify a Python version
./build_bindings.sh --python-version 3.9 --install

You can also build the Python bindings using CMake:

mkdir build && cd build
cmake .. -DBUILD_PYTHON_BINDINGS=ON
make

Dependencies

For ESP32

  • Arduino framework
  • ArduinoJson (v7.0.4 or higher)
  • zlib-PIO

For Desktop

  • CMake 3.10 or higher
  • C++17 compatible compiler
  • OpenSSL development libraries
  • nlohmann_json library (v3.11.2 or higher)
  • zlib

For Python Bindings

  • Python 3.6 or higher
  • pybind11 (automatically fetched during build)
  • pip and setuptools

Usage

Basic Usage

#include "e7-switcher/e7_switcher_client.h"
#include "e7-switcher/logger.h"

// Initialize the logger (debug messages are disabled by default)
e7_switcher::Logger::initialize(); // Default log level is INFO
auto& logger = e7_switcher::Logger::instance();

// To enable debug messages:
// e7_switcher::Logger::initialize(e7_switcher::LogLevel::DEBUG);

// Create client with your credentials
e7_switcher::E7SwitcherClient client{"your_account", "your_password"};

// List all devices
const auto& devices = client.list_devices();
for (const auto& device : devices) {
    logger.infof("Device: %s (Type: %s)", device.name.c_str(), device.type.c_str());
}

// Control a switch
client.control_switch("Your Switch Name", "on");  // or "off"

// Get switch status
e7_switcher::SwitchStatus status = client.get_switch_status("Your Switch Name");
logger.infof("Switch status: %s", status.to_string().c_str());

// Control an AC unit
client.control_ac(
    "Your AC Name",
    "on",                        // "on" or "off"
    e7_switcher::ACMode::COOL,  // COOL, HEAT, FAN, DRY, AUTO
    22,                          // temperature
    e7_switcher::ACFanSpeed::FAN_MEDIUM,  // FAN_LOW, FAN_MEDIUM, FAN_HIGH, FAN_AUTO
    e7_switcher::ACSwing::SWING_ON        // SWING_OFF, SWING_ON, SWING_HORIZONTAL, SWING_VERTICAL
);

Python Usage

from e7_switcher import E7SwitcherClient, ACMode, ACFanSpeed, ACSwing

# Create client with your credentials
client = E7SwitcherClient("your_account", "your_password")

# List all devices
devices = client.list_devices()
for device in devices:
    print(f"Device: {device['name']}, Type: {device['type']}")

# Control a switch
client.control_switch("Your Switch Name", True)  # Turn on
client.control_switch("Your Switch Name", False)  # Turn off

# Get switch status
status = client.get_switch_status("Your Switch Name")
print(f"Switch is {'ON' if status['switch_state'] else 'OFF'}")

# Control an AC unit
client.control_ac(
    "Your AC Name",
    True,                  # Turn on
    ACMode.COOL,           # Mode
    22,                    # Temperature
    ACFanSpeed.FAN_MEDIUM, # Fan speed
    ACSwing.SWING_ON       # Swing
)

# Get AC status
status = client.get_ac_status("Your AC Name")
print(f"AC is {'ON' if status['power_status'] == 1 else 'OFF'}")

Examples

The library includes examples for both ESP32 desktop and Python platforms:

ESP32 Example

A simple example showing how to connect to WiFi and control Switcher devices from an ESP32.

cd examples/esp32_example
pio run -t upload

Desktop Example

A command-line example for controlling devices from desktop platforms.

cd examples/desktop_example
pio run
# Or with CMake:
mkdir build && cd build
cmake .. -DBUILD_EXAMPLES=ON
make
./e7-switcher-desktop-example status  # Get device status
./e7-switcher-desktop-example on      # Turn device on
./e7-switcher-desktop-example off     # Turn device off

Python Example

A Python example for controlling devices using the Python bindings:

# First install the Python package
cd python
pip install .

# Then run the example
python examples/example_usage.py --account your_account --password your_password list
python examples/example_usage.py --account your_account --password your_password switch-status --device "Your Switch Name"
python examples/example_usage.py --account your_account --password your_password ac-on --device "Your AC Name" --mode cool --temp 22 --fan medium --swing on

License

This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

e7_switcher-1.0.4.tar.gz (40.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

e7_switcher-1.0.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

e7_switcher-1.0.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

e7_switcher-1.0.4-cp313-cp313-macosx_14_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

e7_switcher-1.0.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

e7_switcher-1.0.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

e7_switcher-1.0.4-cp312-cp312-macosx_14_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

e7_switcher-1.0.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

e7_switcher-1.0.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

e7_switcher-1.0.4-cp311-cp311-macosx_14_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

File details

Details for the file e7_switcher-1.0.4.tar.gz.

File metadata

  • Download URL: e7_switcher-1.0.4.tar.gz
  • Upload date:
  • Size: 40.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for e7_switcher-1.0.4.tar.gz
Algorithm Hash digest
SHA256 862636a550e016ded7aa424895250b0a5f3264b9ff3ee823340c0927cf715fd3
MD5 287e1db154de982f0c9551bafb86ae4c
BLAKE2b-256 fa5b67ed22dc1f292f5469835dbf184a8be967b5586818d9a6282daff2bf75f8

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c04377628855f52acad48c9c37303249d634f15e8c1a774e73b3c24daa4c2e41
MD5 b5ec868a3c30cfc9cbdd0096b787d5c6
BLAKE2b-256 c1a4ac518d562a11579c504f8f95c6ca7126cf288b23fd8de9d7759104cfaf0f

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 59e8fd853208be6bc65ae2eb2419c859197509463c74c284850af5faf96f5d1c
MD5 1079c0a3eb234b73f48b7037c5485617
BLAKE2b-256 d67c6669871b038a841e78e45b8a9d65ca481486849d9effef839fce00a4e6dd

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.4-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.4-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 aef3d7f56dfaa8294e34edd82a709d6ce64c4f1a51f9b38406b1e03231ba8cfe
MD5 68ec1f7d9ad8f63347a29fa8fbeb4e85
BLAKE2b-256 c6768ed108af0db9f200e138e2a35f2716ff9e1cc99019108235ba53eca9f21d

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 435326a505b8af146f3d139c1a4fed66e08ca7bac69108688e45611863fdd1b9
MD5 33014635d7c173b19d44d06c705a1060
BLAKE2b-256 65661ff4b67ee8da30e0fddb20afa6347763bf2191538c39624a1ac3da70b9d2

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2a9a0777422b294fec36410bd60920d1b19a6abb8c26d0bedc1fc71595467b99
MD5 9c8b3caa8c6ce8b07df4d8029244069a
BLAKE2b-256 5cc69c96444a86f9630bc4a7188e330fd79bc2f06424fd4ab3fefd93830fb99f

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.4-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.4-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 28f6898f607dc68bd8874664fbc649ec996c1af11f5129bbae9f02cadfd69ca9
MD5 d2902f22929e9aba0363e44d165c7cc1
BLAKE2b-256 75344288c815e46e3921d59e705a79f3b4dd22491d1b43237c8a2b9d161f962b

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6a890d8437a639b5a0d01547b3c95f63faa1b00c0dfac2f492611f0532851afa
MD5 d1da74767e413865f2566d48a70b1aec
BLAKE2b-256 e6b2effe5c62d7d00ea806df39e5f1fd3dc0e03531e05c8e5c6d3b38feb3bdbf

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 321308024ee9045f673c546d891a741fb388ff30e59a59a80d9f0e2f97d0c2f2
MD5 91c1fa5235812cf6bd28f80f60492b07
BLAKE2b-256 b47427e17b24d616ac7b20040e3befa9c442df4b658609ea43eb8d08c9b7bb75

See more details on using hashes here.

File details

Details for the file e7_switcher-1.0.4-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for e7_switcher-1.0.4-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 3282bb0b609016e0f2ef5855a0b92bc5fc24c59da1bf76344f68a1627be42247
MD5 d414ec2edd2480f06ef2458f310341d3
BLAKE2b-256 0c640582812938e67919d7b6bd90b3e62a29a1fe3f2bf81c311abb411d8b7bbf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page