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.6.0.tar.gz (40.7 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.6.0-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: homecom_alt-1.6.0.tar.gz
  • Upload date:
  • Size: 40.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for homecom_alt-1.6.0.tar.gz
Algorithm Hash digest
SHA256 e6a2f60e8b7cfdb3ec51497fe8ffc213c4057872ef3e323175ac24328ba62b24
MD5 ff12586394ed49305fe9408800d247e3
BLAKE2b-256 c68148790baa596d8d984177d6bd2abea76e2f35133dbb09fd5562b31e28b360

See more details on using hashes here.

File details

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

File metadata

  • Download URL: homecom_alt-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 25.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for homecom_alt-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 31f62bc26792f9c9a7626be0cd397863c48df60e7b3e4abeb7476eed6f6ba654
MD5 66277d1d9af9ffc1c1c0c5a5c5a04923
BLAKE2b-256 95f776353ff3e6fb8bdeb1936586ab5bb34b03d8b04f70f9bf8a97d20475fe52

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