### Quick Reference: Initial Setup Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Command to install all project dependencies using pnpm, ensuring the lockfile is respected for consistent installations. ```bash pnpm install --frozen-lockfile ``` -------------------------------- ### Install pnpm and dependencies Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/README.md Installs pnpm globally and then installs project dependencies using a frozen lockfile. This is a prerequisite for local development. ```sh npm install -g pnpm pnpm install --frozen-lockfile ``` -------------------------------- ### Install pnpm and Project Dependencies Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Installs pnpm globally if not present, then installs project dependencies using pnpm. It's required to use --frozen-lockfile for consistent installations. ```bash # Install pnpm globally if not already installed npm install -g pnpm # Install dependencies (REQUIRED: use --frozen-lockfile) pnpm install --frozen-lockfile ``` -------------------------------- ### Logging Examples Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Shows how to use the logger utility for different log levels (debug, info, warning, error). Always include the namespace for context. ```typescript const NS = "zhc:modulename"; import {logger} from "../lib/logger"; logger.debug(`Message`, NS); logger.info(`Message`, NS); logger.warning(`Message`, NS); logger.error(`Message`, NS); ``` -------------------------------- ### Quick Reference: Clean Slate Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Command to clean the project, removing build artifacts and temporary files to start from a clean state. ```bash pnpm run clean ``` -------------------------------- ### Quick Reference: Development Watch Mode Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Command to start the build process in watch mode, automatically recompiling code when changes are detected during development. ```bash pnpm run build:watch ``` -------------------------------- ### Error Handling Examples Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Demonstrates best practices for error handling, including using node:assert for assertions, throwing descriptive errors, and validating inputs with utility functions. Always provide clear error messages. ```typescript // Use node:assert for assertions import assert from "node:assert"; assert(condition, "Error message"); // Throw descriptive errors throw new Error("The on_time value must be a number!"); // Validate inputs utils.assertNumber(value, "property_name"); utils.validateValue(state, ["on", "off", "toggle"]); ``` -------------------------------- ### State Management Utilities Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Illustrates state management functions for interacting with a global store. These utilities allow getting, putting, checking for, and clearing values associated with a device. ```typescript import * as globalStore from "../lib/store"; globalStore.getValue(device, "key", defaultValue); globalStore.putValue(device, "key", value); globalStore.hasValue(device, "key"); globalStore.clearValue(device, "key"); ``` -------------------------------- ### Modern Extends for Device Definitions Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Utilizes modern extends for defining device capabilities, which is the preferred method. This example shows common extends like light, battery, identify, onOff, temperature, and humidity. ```typescript extend: [ m.light({colorTemp: {range: [153, 500]}, color: true}), m.battery(), m.identify(), m.onOff(), m.temperature(), m.humidity(), ] ``` -------------------------------- ### Validation Utilities Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Provides examples of validation utilities for ensuring data integrity. These functions help assert types, validate values against allowed sets, and check data types. ```typescript import * as utils from "../lib/utils"; utils.assertNumber(value, "property_name"); utils.assertString(value, "property_name"); utils.validateValue(state, ["on", "off", "toggle"]); utils.isNumber(value); utils.isString(value); utils.isObject(value); ``` -------------------------------- ### Pull Request Pre-computation Steps Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Outlines the steps to perform before creating a Pull Request, including code formatting, building the project, and running tests. Ensure all checks pass before submitting. ```bash # 1. Format code pnpm run check --fix # 2. Build pnpm run build # 3. Run tests pnpm test ``` -------------------------------- ### Import and prepare device definitions Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/README.md Imports default device definitions from zigbee-herdsman-converters and prepares them using `zhc.prepareDefinition`. This is the recommended way to access definitions after version 22.0.0. ```js (await import('zigbee-herdsman-converters/devices/index')).default.forEach((baseDefinition) => { const d = zhc.prepareDefinition(baseDefinition); }); ``` -------------------------------- ### Build Project Artifacts Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Commands to build the project, including a full build, a watch mode for continuous compilation, and cleaning build artifacts. ```bash # Full build (compile TypeScript + generate device index) pnpm run build # Watch mode (auto-rebuild on changes) pnpm run build:watch # Clean build artifacts pnpm run clean ``` -------------------------------- ### Troubleshooting: Clean and Rebuild Command Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Command to clean the project and rebuild, useful for resolving build errors. Ensure the correct pnpm version is used. ```bash pnpm run clean && pnpm run build ``` -------------------------------- ### Run Benchmarks Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Executes benchmark tests for performance analysis. ```bash pnpm bench ``` -------------------------------- ### Pre-commit Hooks Commands Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Lists the commands executed by pre-commit hooks to ensure code quality and consistency before committing. Run these commands to verify your changes. ```bash pnpm run build pnpm run check pnpm run test ``` -------------------------------- ### Run Tests with Coverage Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Executes all tests and generates a code coverage report. ```bash pnpm run test:coverage ``` -------------------------------- ### Troubleshooting: Run Single Test Command Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Command to run a single test case using Vitest. Useful for isolating and debugging specific test failures. ```bash pnpm vitest run -t "test name" ``` -------------------------------- ### Pre-commit Checks Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Commands to run before committing to ensure code quality and test coverage. This includes building, checking code formatting, and running tests. ```bash pnpm run build pnpm run check pnpm test ``` -------------------------------- ### Vendor-Specific Extends Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Demonstrates how to use vendor-specific extends by importing modules for Philips, IKEA, and Tuya devices. This allows for tailored device integrations. ```typescript import * as philips from "../lib/philips"; import * as ikea from "../lib/ikea"; import * as tuya from "../lib/tuya"; extend: [ philips.m.light({colorTemp: true, color: true}), ikea.ikeaBattery(), tuya.modernExtend.tuyaLight(), ] ``` -------------------------------- ### Run checks, build, and test Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/README.md Runs code checks with auto-fixing, builds the project, and executes tests. These commands ensure changes meet project standards before submission. ```sh pnpm run check --fix pnpm run build pnpm test ``` -------------------------------- ### Run All Tests Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Executes all tests within the project using the Vitest test runner. ```bash pnpm test ``` -------------------------------- ### Troubleshooting: Manual Linting Check Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Command to perform a manual linting check without attempting to fix errors. Use this to identify issues that require manual intervention. ```bash pnpm run check ``` -------------------------------- ### Basic Vitest Test Structure Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md A standard structure for writing tests using Vitest, including imports for testing utilities and a describe/it block for organizing tests. ```typescript import {describe, expect, it} from "vitest"; describe("Feature Name", () => { it("should describe expected behavior", () => { // Arrange // Act // Assert expect(result).toStrictEqual(expected); }); }); ``` -------------------------------- ### Troubleshooting: Rebuild Device Index Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Command to rebuild the device index, necessary after adding or modifying device files. This ensures the system recognizes new or updated devices. ```bash pnpm run build ``` -------------------------------- ### Device Definition Structure Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Illustrates the structure for defining a new Zigbee device, including its model, vendor, description, and the extends to be applied. Use modern extends for new device definitions. ```typescript export const definitions: DefinitionWithExtend[] = [ { zigbeeModel: ["model_id"], model: "PRODUCT_CODE", vendor: "Vendor Name", description: "Product description", extend: [ m.light({colorTemp: true, color: true}), m.battery(), m.identify(), ], }, ]; ``` -------------------------------- ### Troubleshooting: Auto-fix Linting Errors Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Command to automatically fix linting errors. Run this command to resolve common code style and potential issues. ```bash pnpm run check --fix ``` -------------------------------- ### ToZigbee Converter Structure Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Defines the structure for a ToZigbee converter, used to send commands to Zigbee devices. Implement convertSet for setting states and convertGet for reading states. ```typescript export const converter_name: Tz.Converter = { key: ["property_name"], convertSet: async (entity, key, value, meta) => { utils.assertNumber(value, "property_name"); await entity.command("clusterName", "commandName", {param: value}, utils.getOptions(meta.mapped, entity) ); return {state: {property_name: value}}; }, convertGet: async (entity, key, meta) => { await entity.read("clusterName", ["attributeName"]); }, }; ``` -------------------------------- ### FromZigbee Converter Structure Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Defines the structure for a FromZigbee converter, used to process incoming Zigbee messages. Specify the cluster, message types, and implement the convert function to extract and transform data. ```typescript export const converter_name: Fz.Converter< "clusterName", undefined, ["attributeReport", "readResponse"] > = { cluster: "clusterName", type: ["attributeReport", "readResponse"], convert: (model, msg, publish, options, meta) => { // Extract and transform data return {property: value}; }, }; ``` -------------------------------- ### Import Patterns in TypeScript Source: https://github.com/koenkk/zigbee-herdsman-converters/blob/master/AGENTS.md Defines standard import patterns for converters, exposes, modern extends, and vendor-specific modules. Ensure all necessary modules are imported for converter functionality. ```typescript import * as fz from "../converters/fromZigbee"; import * as tz from "../converters/toZigbee"; import * as exposes from "../lib/exposes"; import * as m from "../lib/modernExtend"; import * as [vendor] from "../lib/[vendor]"; // e.g., philips, ikea, tuya import type {DefinitionWithExtend} from "../lib/types"; const e = exposes.presets; const ea = exposes.access; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.