Skip to main content

Python wrapper for controlling devices managed by HomeCom Easy APP.

Project description

homecom-alt

Python wrapper for controlling devices managed by HomeCom Easy APP.

How to use package

Check example.py

or

"""An example of using HomeCom alt package."""
import asyncio
import logging

from aiohttp import ClientConnectorError, ClientError, ClientSession

from homecom_alt import (
    ApiError,
    AuthFailedError,
    ConnectionOptions,
    InvalidSensorDataError,
    HomeComAlt,
    BHCDevice,
)

logging.basicConfig(level=logging.DEBUG)

USERNAME = "user"
PASSWORD = "password"

def print_status(data: BHCDevice):
    print("firmware: {data.firmware}")
    print("notifications: {data.notifications}")
    for ref in data.stardard_functions:
        normalized_id = ref["id"].split("/", 2)[-1]

        match normalized_id:
            case "operationMode":
                print(f"operationMode current_value: {ref["value"]}, allowed_values: {ref["allowedValues"]}")
            case "acControl":
                print(f"acControl current_value: {ref["value"]}, allowed_values: {ref["allowedValues"]}")
            case "fanSpeed":
                print(f"fanSpeed current_value: {ref["value"]}, allowed_values: {ref["allowedValues"]}")
            case "airFlowHorizontal":
                print(f"airFlowHorizontal current_value: {ref["value"]}, allowed_values: {ref["allowedValues"]}")
            case "airFlowVertical":
                print(f"airFlowVertical current_value: {ref["value"]}, allowed_values: {ref["allowedValues"]}")
            case "temperatureSetpoint":
                print(f"temperatureSetpoint current_value: {ref["value"]}{ref["unitOfMeasure"]}")
                print(f"temperatureSetpoint min_value: {ref["minValue"]} max_value: {ref["maxValue"]}")
            case "roomTemperature":
                print(f"roomTemperature current_value: {ref["value"]}{ref["unitOfMeasure"]}")
            case _:
                pass

    for ref in data.advanced_functions:
        normalized_id = ref["id"].split("/", 2)[-1]

        match normalized_id:
            case "airPurificationMode":
                print(f"plasmacluster current_value: {ref["value"]}")
            case "fullPowerMode":
                print(f"boost current_value: {ref["value"]}")
            case "ecoMode":
                print(f"eco mode current_value: {ref["value"]}")
            case "timers/on":
                print(f"timer turn on current_value: {ref["value"]} {ref["unitOfMeasure"]}")
                print(f"timer turn on min_value: {ref["minValue"]} max_value: {ref["maxValue"]}")
            case "timers/off":
                print(f"timer turn off current_value: {ref["value"]} {ref["unitOfMeasure"]}")
                print(f"timer turn off min_value: {ref["minValue"]} max_value: {ref["maxValue"]}")
            case _:
                pass

    for ref in data.switch_programs:
        normalized_id = ref["id"].split("/", 2)[-1]

        match normalized_id:
            case "switchPrograms/enabled":
                print(f"programs current_value: {ref["value"]}")
            case "switchPrograms/activeProgram":
                print(f"program current_value: {ref["value"]}, allowed_values: {ref["allowedValues"]}")
            case _:
                pass

async def main():
    """Run main function."""
    options = ConnectionOptions(username=USERNAME, password=PASSWORD)

    async with ClientSession() as websession:
        bhc = await HomeComAlt.create(websession, options)

        try:
            data: dict[str, BHCDevice] = {}
            device_ids: list[str] = []
            # get devices synced with homecom easy
            devices = await bhc.async_get_devices()
            # get status for each device discovered
            for device in await devices:
                print(f"Device={device["deviceId"]}, type={device["deviceType"]}")
                device_ids.append(device["deviceId"])
            while True:
                device_id = input(f"Enter the device you want to control: {', '.join(device_ids)}")
                if device_id not in device_ids:
                    print("device_id not in the list of devices")
                    continue
                data: BHCDevice = await bhc.async_update(device_id)
                print_status(data)
                break

loop = asyncio.new_event_loop()
loop.run_until_complete(main())
loop.close()

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

homecom_alt-1.2.1.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

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

homecom_alt-1.2.1-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file homecom_alt-1.2.1.tar.gz.

File metadata

  • Download URL: homecom_alt-1.2.1.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for homecom_alt-1.2.1.tar.gz
Algorithm Hash digest
SHA256 842ea96d43a3021e89214f105c7f5eba28a77d6b5ad56120bc1a9137e09e0259
MD5 04c932a7349c30da45ecffc1ec8cea50
BLAKE2b-256 54d607d582975f091f25c3b8c756bbf345589fa4b52f1d5964512b979b1acc98

See more details on using hashes here.

File details

Details for the file homecom_alt-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: homecom_alt-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for homecom_alt-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 134d588f93f77f8058211e5ea6fe187c72d11da9e4a9e8211773bbe893de96c6
MD5 1eccb6981a7f4e45582d7346e2dd623d
BLAKE2b-256 8aaf78cf7648fd9c94c58af7f52bf140a63fe9fca0f754d9343ab17e97878142

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