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.1.tar.gz (43.6 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.1-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for homecom_alt-1.6.1.tar.gz
Algorithm Hash digest
SHA256 81ce376e44e127810a3f295b7a81e54a856501c6adfc6dea4d99686002681d0e
MD5 72fe0033ebeee9097c9a6cdf3613b730
BLAKE2b-256 400f23b0401c7b0eca501c479df72a7daddda29fb1d613f9152aae91978a0bc1

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for homecom_alt-1.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cc1c88f63407c8a99896acfb1ae1b8fc4f5e567c2e1bdd25b23a60cb2b2d4a11
MD5 18f5aa57f526982c99035a9db2d7966f
BLAKE2b-256 9b205f5c541e4c4f12fcc98b41f214cc61d28bdfba3e21f4ae6178273f978654

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