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.5.tar.gz (40.1 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.5-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.5-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.5-cp313-cp313-macosx_14_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

e7_switcher-1.0.5-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.5-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.5-cp312-cp312-macosx_14_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

e7_switcher-1.0.5-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.5-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.5-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.5.tar.gz.

File metadata

  • Download URL: e7_switcher-1.0.5.tar.gz
  • Upload date:
  • Size: 40.1 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.5.tar.gz
Algorithm Hash digest
SHA256 7a6813e4070c4330430d0c3fb8f943ca4c9e2c02c85d8ef9b8ac98465bb808db
MD5 b36d88eb9caa616c3e668730df3cfb10
BLAKE2b-256 185efd2ab3cf9951bce61240f39c34091ad48a6668efeb74c6886a1265ae3903

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for e7_switcher-1.0.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 94195a85b7011dabb26620bb5ed8abf3d114f70a17cc729b97217be1a51412b0
MD5 b590d47b3b99fea13d71a2ee6e19896b
BLAKE2b-256 63c94958df8182e20eaa6590b049ce8993bc54419e84d46a41b8332d34c5624d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for e7_switcher-1.0.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3aa655b81ff46f7720a56062342bc5c58381f4473044c2a3bddf07653eff4a5a
MD5 afe45854747d30e6d85dde8bd3ffebd8
BLAKE2b-256 9497890da23c3e019b59446d30eed56e656a4bd09eda1d422c829ca1d4e7a0c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for e7_switcher-1.0.5-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 8d8c416479f95370aef3a8db0ed11f660a2596828f40807846d030d24410fcc7
MD5 a87393d943b0cad0b93e44469a1616b9
BLAKE2b-256 1f2de53b1de8908024a050deaec8f2b9fff344e13ad51cb787e1322429f88c82

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for e7_switcher-1.0.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5560b19c4406acb9f5cc29032bb4ae35b85cd3df15fdc8a82e7e31fdc6b9b8cc
MD5 57e52def937cdf851df90fe67d85da94
BLAKE2b-256 97a6f3f032475532eb409515a1ba2579e55c7f01fa48c4aa1205eb2c50419be9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for e7_switcher-1.0.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d032c9a07bd4a04c77844d567912727525c5395958bfdbd5a1dc82b7a0b0f828
MD5 4bd28507c75d73cd1f69349f63126edd
BLAKE2b-256 0d1be918071a890b69511bfa27d22f587e8ff7637a5cfba444e5cc883ec97e8a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for e7_switcher-1.0.5-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 2963bc7d422e8899062ff16e8a8f268db12be50a32c80ae93fad83afbd332108
MD5 c1351fa7d7034bccb77fa29180426a38
BLAKE2b-256 a9959add6f9744910cc3e499efffc11aca77074cefa1f83b19d47ee47204a059

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for e7_switcher-1.0.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 deb6506abe0c83e91ca0a949d5b25930ffd693d8e92dea85cad60802199b19d4
MD5 fcafe9788b4f7cff77cadd5d82205fa0
BLAKE2b-256 26af1bdfb9fb5bd16435697e258dd4df0c3c4c1f69fb4f749114ba5710b7dc5d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for e7_switcher-1.0.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 be6ea2feee265aea45e2473597783a9a17615f7f4763b489c9c17f7d143ebcbc
MD5 27117357e2708ba6299f4675055ada0c
BLAKE2b-256 6df380cb4ce25733e295210edc0862049cc22f584d22b23b1902a85f10b60e70

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for e7_switcher-1.0.5-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 63ff5e9c8bedf841e9a9caa672a23c0cac38cd5da43c0a035b815ed79b864e65
MD5 7125da2e2fa112e6c566c00d973f621f
BLAKE2b-256 5e0cec7a46ba5f4e57e4ce7eb17b60e0907b5808b848282ca98ea0256cbb2cf9

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