Skip to main content

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.

System also exposes HVAC capability helpers:

  • supports_heat()
  • supports_cool()
  • supports_fan()
  • supported_hvac_capabilities()

These helpers prefer Carrier's energy configuration flags, then use known equipment hints from Carrier's indoor and outdoor unit types to supplement.

For zone-level profile resolution, call ConfigZone.current_status_activity(status_zone) with matching zones from the same system. This uses Carrier's reported current activity type from live status data. Use ConfigZone.current_scheduled_activity() when you want the activity implied by schedule and hold configuration instead.

Deprecated compatibility aliases:

  • StatusZone.current_activity is an alias for StatusZone.current_status_activity_type. It returns Carrier's live status-derived activity type/name.
  • ConfigZone.current_activity() is an alias for ConfigZone.current_scheduled_activity(). It returns the schedule/configuration-derived activity.

To get both activity sources together, use ConfigZone.as_dict(status_zone)["current_activity"] or System.as_dict()["config"]["zones"][...]["current_activity"]. That object has from_schedule and from_status keys. System.as_dict() performs the status/config pairing for the aggregate system.

System.as_dict() includes supported_hvac_capabilities and passes status-zone context into config serialization so each zone dictionary includes current_activity.from_schedule and current_activity.from_status.

Reusing an aiohttp session

Pass client_session to share an existing aiohttp.ClientSession, for example Home Assistant's shared session:

api = ApiConnectionGraphql(
    username="your-account@example.com",
    password="your-password",
    client_session=session,
)

The websocket connects through that session, and GraphQL requests share its connection pool: gql builds each request's session on the shared connector without taking ownership of it. cleanup() stops the websocket tasks but leaves a session you passed in open, so the owner of that session closes it. A session the connection created itself is closed by cleanup().

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(...)
  • set_program_day(...)

set_program_day(...) replaces one day of a zone's program (updateInfinityProgramDay). Send every period of the day, enabled or not, with the etag the systems query returns (load_data() now reads the program's and each day's etag). It has not yet been verified against a live system.

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.

If a callback raises ValueError, KeyError, TypeError, IndexError or AttributeError for a message, the error is logged and the message is dropped; the connection stays open and later callbacks still run. WebsocketDataUpdater skips messages for devices and zones that load_data() did not return.

When the connection drops, the listener reconnects with exponential backoff and jitter, starting at 1 second and capped at 5 minutes. A connection that stays up for a minute resets the delay. Call api.api_websocket.stop(), or api.cleanup(), to cancel the listener and heartbeat tasks and close the websocket.

Authentication

The access token is refreshed 60 seconds before it expires. If Carrier rejects a request with HTTP 401 or 403, the token is refreshed and the request is retried once before CarrierApiAuthError is raised. If the refresh token itself is rejected, the connection logs in again with the stored password.

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

mypy runs in strict mode (strict = true in pyproject.toml) over src/carrier_api and tests. The Lint workflow runs the same check on every push and pull request.

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.

Metadata

Release files for carrier-api 3.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for carrier-api 3.12.0
File Size Uploaded Provenance Actions
carrier_api-3.12.0.tar.gz 81.9 kB Without provenance Details for carrier_api-3.12.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for carrier-api 3.12.0
File Interpreter ABI Platform Actions
carrier_api-3.12.0-py3-none-any.whl Python 3 none any Details for carrier_api-3.12.0-py3-none-any.whl

Total release size: 129.4 kB

Release files / carrier_api-3.12.0.tar.gz

Download URL carrier_api-3.12.0.tar.gz
Size 81.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0bbbfe9042ac8e17b66c4d432b09977da877686c8fc54682a3760ab9419f039e
BLAKE2b-256 checksum
How to use checksums
ad3f06b09f6e99259377feca8f2e4d17f679c4544a2a9f69fa437177113d5cd0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / carrier_api-3.12.0-py3-none-any.whl

Download URL carrier_api-3.12.0-py3-none-any.whl
Size 47.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dbc58773ce0f426cdec5f3c94cc52e6bdd7d8a9a35b2c7d72fbde1086d39ea59
BLAKE2b-256 checksum
How to use checksums
8047782cffa9b0f658460b9732a31556389ce797d94dea0900a460f08406f579
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for carrier-api 3.12.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.12.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page