UNPKG

homebridge-http-sensors-switches

Version:

This plugin communicates with your devices over HTTP or MQTT. Currently it supports Light Bulb, Switches, Outlets, Fan, Garage Door, Shades / Blinds, Temperature/Humidity, Motion, Contact and Occupancy sensor, Door, Sprinkler, Valve, Air Quality, Smoke, C

22 lines (21 loc) 1.23 kB
/** * Retrieves the value of a nested property from a JSON object based on a dot-separated key path. * Converts the retrieved value into the specified return type (number, string, or boolean). * * @param {Record<string, unknown>} obj - The source object containing nested key-value pairs. * @param {string} key - Dot-separated path to the desired property (e.g., 'temperature.tC'). * @param {'number' | 'string' | 'boolean'} returnType - The type to convert the retrieved value into. * @returns {number | string | boolean | null} - The converted value or null if the property doesn't exist. * * Example usage: * const value = getNestedValue(data, 'temperature.tC', 'number'); // Returns 47.1 */ export declare function getNestedValue(obj: Record<string, unknown>, key: string, returnType: 'number' | 'string' | 'boolean'): number | string | boolean | null; /** * Checks if a nested key exists in the given object. * * @param obj - The object to search within. * @param key - The nested key path, specified as a dot-separated string (e.g., "level1.level2"). * @returns {boolean} - True if the key exists, otherwise false. */ export declare function hasNestedKey(obj: Record<string, unknown>, key: string): boolean;