Skip to main content

Carrier Api Wrapper

Project description

GitHub Release GitHub Activity Coverage License

Project Maintenance BuyMeCoffee

PyPI

carrier_api

Async Python client for Carrier Infinity and Bryant Evolution HVAC systems.

This package wraps the Carrier Infinity GraphQL API, exposes typed model objects for system profile, status, configuration, and energy data, and includes helper methods for common thermostat updates. It is intended for integrations and local automation code that need a lightweight API client rather than a full application.

The client is unofficial and depends on Carrier's private web and mobile API behavior. Carrier can change that API without notice.

Requirements

  • Python 3.14 or newer
  • A Carrier or Bryant account that works in the official app
  • Network access to Carrier's cloud API

Installation

Install the published package in a virtual environment:

python3.14 -m venv .venv
.venv/bin/python -m pip install carrier_api

Live Smoke Test

The live smoke test connects to a real Carrier account, prints loaded system state, starts websocket listeners, and sends one sample manual activity update to the first available zone.

scripts/live_smoke_test

Use it only when you want to exercise the live Carrier API. It can change thermostat settings.

To run non-interactively, put credentials in a local env file and pass it with --credentials-file. Supported keys are CARRIER_USERNAME/CARRIER_PASSWORD.

scripts/live_smoke_test --credentials-file scripts/carrier_api.env --output-file /private/tmp/carrier_api.txt --schema-output-file /private/tmp/carrier_api_schema.json --read-only

Use --output-file when you want a full transcript for later API debugging or fixture updates. Use --schema-output-file to also capture the authenticated GraphQL introspection schema without temporarily editing the client. Use --read-only to skip the sample thermostat mutation while still loading systems, capturing schema, and listening for websocket messages.

Basic Usage

import asyncio

from carrier_api import ApiConnectionGraphql


async def main() -> None:
    api = ApiConnectionGraphql(
        username="your-account@example.com",
        password="your-password",
    )
    try:
        systems = await api.load_data()
        for system in systems:
            print(system.profile.name)
            print(system.status.mode)
            print(system.as_dict())
    finally:
        await api.cleanup()


asyncio.run(main())

load_data() authenticates when needed and returns a list of System objects. Each System includes:

  • profile: system identity and location metadata
  • status: current mode, temperature, humidity, zone, and equipment state
  • config: configured zones, activities, schedules, and holds
  • energy: reported energy usage data

Model objects provide as_dict() for structured serialization. Their string and repr forms are intended for readable debugging output.

Updating Thermostat Settings

Mutation helpers send Carrier configuration updates and then request websocket reconciliation when a websocket manager is available.

import asyncio

from carrier_api import ActivityTypes, ApiConnectionGraphql, FanModes, SystemModes


async def main() -> None:
    api = ApiConnectionGraphql(
        username="your-account@example.com",
        password="your-password",
    )
    try:
        systems = await api.load_data()
        system = systems[0]
        zone = system.config.zones[0]

        await api.set_config_mode(system.profile.serial, SystemModes.AUTO)
        await api.update_fan(
            system_serial=system.profile.serial,
            zone_id=zone.api_id,
            activity_type=ActivityTypes.HOME,
            fan_mode=FanModes.LOW,
        )
        await api.set_config_manual_activity(
            system_serial=system.profile.serial,
            zone_id=zone.api_id,
            heat_set_point="68",
            cool_set_point="74",
            fan_mode=FanModes.LOW,
        )
    finally:
        await api.cleanup()


asyncio.run(main())

Available update helpers include:

  • set_config_mode(...)
  • set_config_heat_humidity(...)
  • set_heat_source(...)
  • set_humidifier(...)
  • update_fan(...)
  • set_config_hold(...)
  • resume_schedule(...)
  • set_config_manual_activity(...)

These methods can change real HVAC settings. Validate the selected system, zone, mode, and set points before calling them from automation.

Realtime Updates

ApiWebsocket manages Carrier realtime messages. WebsocketDataUpdater can merge incoming websocket messages into the System objects returned by load_data().

import asyncio

from carrier_api import ApiConnectionGraphql, WebsocketDataUpdater


async def main() -> None:
    api = ApiConnectionGraphql(
        username="your-account@example.com",
        password="your-password",
    )
    try:
        systems = await api.load_data()
        updater = WebsocketDataUpdater(systems)

        if api.api_websocket is None:
            raise RuntimeError("websocket manager was not initialized")

        api.api_websocket.callback_add(updater.message_handler)
        await api.api_websocket.create_task_listener()
    finally:
        await api.cleanup()


asyncio.run(main())

Callbacks receive the raw websocket message text. Register WebsocketDataUpdater.message_handler first when later callbacks need to read the updated in-memory system state.

Development

Clone this repository and install the development environment:

git clone https://github.com/dahlb/carrier_api.git
cd carrier_api
scripts/setup

Use the repository scripts so commands run through the local .venv.

scripts/setup
scripts/test
scripts/lint

The underlying commands are:

./.venv/bin/pytest
./.venv/bin/prek run --all-files
./.venv/bin/mypy .

Add or update deterministic pytest coverage for behavior changes. Fixture data for GraphQL and websocket responses lives under tests/graphql and tests/messages.

Updating the Captured Schema

To refresh captured GraphQL schema data, run the live smoke test with --schema-output-file:

scripts/live_smoke_test --credentials-file scripts/carrier_api.env --schema-output-file /private/tmp/carrier_api_schema.json --read-only

The command authenticates with Carrier, runs the GraphQL introspection query, and writes the schema JSON to the path you provide. Add --output-file /private/tmp/carrier_api.txt when you also want the full live smoke-test transcript.

Contributing

See CONTRIBUTING.md for contribution guidance. Please open bugs and feature requests in the issue tracker.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

carrier_api-3.1.0.tar.gz (52.7 kB view details)

Uploaded Source

Built Distribution

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

carrier_api-3.1.0-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

Details for the file carrier_api-3.1.0.tar.gz.

File metadata

  • Download URL: carrier_api-3.1.0.tar.gz
  • Upload date:
  • Size: 52.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for carrier_api-3.1.0.tar.gz
Algorithm Hash digest
SHA256 b4aae4563ed21c74d222e2e5628e4175e4a56f1a8c5c3631a33892550b1fbb4b
MD5 94b9c6ca7f62f3da92e9a4a9254fe50a
BLAKE2b-256 d1a29470db5ac67a1123f7fcca7fc8798ed38b05f3eb9c9678801e61e6ee4ec4

See more details on using hashes here.

File details

Details for the file carrier_api-3.1.0-py3-none-any.whl.

File metadata

  • Download URL: carrier_api-3.1.0-py3-none-any.whl
  • Upload date:
  • Size: 32.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for carrier_api-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 edfb8131cdf77a30ded55aa082f18affaaa6fde887c23aabfdf4635b5dc5c2d5
MD5 6a8db92485211707436ed52bdc34c5ce
BLAKE2b-256 ea3952815c00cd63ab561916b63d1ddbdb435a066a810776c009a252d9828de8

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