0.8.2 • Published 5 months ago

lib-comfoair v0.8.2

Weekly downloads
-
License
GPL-2.0
Repository
github
Last release
5 months ago

lib-comfoair 🌬️

lib-comfoair is a TypeScript library for interacting with Zehnder ComfoAirQ ventilation units through the ComfoConnect LAN C gateway. It enables you to discover these gateways on your local network, read and write device properties, and subscribe to property change notifications.

This library is completely written in TypeScript and strongly typed, making development more reliable and maintainable.

Features ✨

  • 🔍 Discover Zehnder ComfoConnect LAN C gateways on your network.
  • 📖 Read and write properties of Zehnder ComfoAirQ ventilation units.
  • 🔄 Listen for real-time updates of changing properties.
  • ⚙️ Strong typing ensures reliable code and easy maintainability.

Installation 📦

NPM

npm i lib-comfoair

PNPM

pnpm add lib-comfoair

Usage 🚀

Below are basic usage examples. The library can discover devices, start sessions to communicate with ventilation units, and request property updates.

Discovering Devices

Use the discovery feature to find Zehnder ComfoConnect LAN C gateways on the same network. You can await the discovery process or attach event listeners.

import { ComfoControlClient } from 'lib-comfoair';

// Discover a gateway with an optional limit:
ComfoControlClient.discover({ limit: 1 })
  .then(devices => {
    console.log('Discovered devices:', devices);
    // If desired, create a client and make requests:
    // const client = new ComfoControlClient(devices[0]);
    // await client.getServerTime();
  });

// Or listen for discovery events:
const discovery = ComfoControlClient.discover({ limit: 10 });
discovery.on('discover', device => {
  console.log('Discovered device:', device);
});
discovery.on('completed', () => {
  console.log('Discovery finished');
});

How Device Discovery Works 🕵️‍♂️

Discovery sends a broadcast message and waits for devices to respond. This works only if the gateway is on the same subnet as the host running the discovery. Most routers do not forward broadcast messages to other subnets by default.

Listening for Property Changes

After obtaining the device’s info, you can register property listeners that trigger when values change:

import { ComfoControlClient, ComfoAirProperties } from 'lib-comfoair';

// Example usage (simplified):
const client = new ComfoControlClient({
  address: '192.168.1.10',
  uuid: 'your-device-uuid-here',
});

// Register a listener for OUTDOOR_AIR_TEMPERATURE:
await client.registerPropertyListener(ComfoAirProperties.OUTDOOR_AIR_TEMPERATURE, ({ value }) => {
  console.log(`Outdoor air temperature: ${value / 10} °C`);
});

// You may then connect or make a request:
console.log(await client.getServerTime());

Available Opcodes

OpcodeDescription
NO_OPERATIONNo operation (placeholder).
SET_ADDRESS_REQUESTSets the device address.
REGISTER_DEVICE_REQUESTRegisters a device/client.
START_SESSION_REQUESTInitiates a session.
CLOSE_SESSION_REQUESTEnds an existing session.
LIST_REGISTERED_APPS_REQUESTLists registered apps/clients.
UNREGISTER_DEVICE_REQUESTUnregisters a device/client.
CHANGE_PIN_REQUESTChanges the device PIN code.
GET_REMOTE_ACCESS_ID_REQUESTRetrieves the remote access ID.
SET_REMOTE_ACCESS_ID_REQUESTSets the remote access ID.
GET_SUPPORT_ID_REQUESTRetrieves the support ID.
SET_SUPPORT_ID_REQUESTSets the support ID.
GET_WEB_ID_REQUESTRetrieves the web ID.
SET_WEB_ID_REQUESTSets the web ID.
SET_PUSH_ID_REQUESTSets the push message ID.
DEBUG_REQUESTDebug request.
UPGRADE_REQUESTInitiates firmware upgrade.
SET_DEVICE_SETTINGS_REQUESTAdjusts device settings.
VERSION_REQUESTQueries version information.
SET_ADDRESS_CONFIRMConfirms address setup.
REGISTER_DEVICE_CONFIRMAcknowledges registration.
START_SESSION_CONFIRMConfirms session initiation.
CLOSE_SESSION_CONFIRMConfirms session closure.
LIST_REGISTERED_APPS_CONFIRMConfirms list of registered apps.
UNREGISTER_DEVICE_CONFIRMConfirms device unregistration.
CHANGE_PIN_CONFIRMConfirms PIN change.
GET_REMOTE_ACCESS_ID_CONFIRMRemote access ID confirmation.
SET_REMOTE_ACCESS_ID_CONFIRMRemote access ID setup confirmed.
GET_SUPPORT_ID_CONFIRMSupport ID confirmation.
SET_SUPPORT_ID_CONFIRMSupport ID setup confirmed.
GET_WEB_ID_CONFIRMWeb ID confirmation.
SET_WEB_ID_CONFIRMWeb ID setup confirmed.
SET_PUSH_ID_CONFIRMPush ID setup confirmed.
DEBUG_CONFIRMDebug request confirmation.
UPGRADE_CONFIRMConfirms firmware upgrade.
SET_DEVICE_SETTINGS_CONFIRMConfirms device settings update.
VERSION_CONFIRMConfirms version request.
GATEWAY_NOTIFICATIONNotification from the gateway.
KEEP_ALIVEKeeps the session alive.
FACTORY_RESETResets the device to factory defaults.
CN_TIME_REQUESTRequests current time.
CN_TIME_CONFIRMConfirms time update.
CN_NODE_REQUESTNode-related request (internal).
CN_NODE_NOTIFICATIONNode status/update notification.
CN_RMI_REQUESTRemote method invocation request.
CN_RMI_RESPONSEResponse to RMI request.
CN_RMI_ASYNC_REQUESTAsynchronous RMI request.
CN_RMI_ASYNC_CONFIRMAcknowledges async RMI.
CN_RMI_ASYNC_RESPONSEResponse to async RMI.
CN_RPDO_REQUESTRequests updates for a property.
CN_RPDO_CONFIRMConfirms property update subscription.
CN_RPDO_NOTIFICATIONNotifies of a property update.
CN_ALARM_NOTIFICATIONNotifies of alarms from the device.
CN_FUP_READ_REGISTER_REQUESTFirmware update read register request.
CN_FUP_READ_REGISTER_CONFIRMConfirms read register request.
CN_FUP_PROGRAM_BEGIN_REQUESTBegins firmware update programming.
CN_FUP_PROGRAM_BEGIN_CONFIRMConfirms program begin.
CN_FUP_PROGRAM_REQUESTFirmware update programming data request.
CN_FUP_PROGRAM_CONFIRMConfirms firmware programming data request.
CN_FUP_PROGRAM_END_REQUESTEnds firmware update programming.
CN_FUP_PROGRAM_END_CONFIRMConfirms end of firmware programming.
CN_FUP_READ_REQUESTRequests firmware read.
CN_FUP_READ_CONFIRMConfirms firmware read request.
CN_FUP_RESET_REQUESTRequests firmware reset.
CN_FUP_RESET_CONFIRMConfirms firmware reset.

Strongly Typed Library

This library is strongly typed, ensuring that you benefit from autocompletion and reduced runtime errors. It adds clarity when dealing with ComfoAirQ properties and messages by leveraging TypeScript’s type system.

Credits 🙏

This project is based on the protocol specifications documented by Michaël Arnauts. Thank you to Michaël for making this information available.

0.8.2

5 months ago

0.8.1

5 months ago

0.8.0

5 months ago

0.7.1

5 months ago

0.7.0

5 months ago

0.6.2

5 months ago

0.6.1

5 months ago