UNPKG

homebridge-hilo

Version:

Plugin Homebridge (non officiel) pour la passerelle et les appareils Hilo de Hydro-Québec | Unofficial Homebridge plugin for Hydro-Québec Hilo bridge and devices

168 lines 4.34 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.setupSubscription = void 0; const logger_1 = require("./logger"); const hiloApi_1 = require("./hiloApi"); const graphql_ws_1 = require("graphql-ws"); const types_1 = require("./devices/types"); const gql_1 = require("./graphql/gql"); const ws_1 = __importDefault(require("ws")); const SUBSCRIPTION_QUERY = (0, gql_1.graphql)(/* GraphQL */ ` subscription onAnyDeviceUpdated($locationHiloId: String!) { onAnyDeviceUpdated(locationHiloId: $locationHiloId) { deviceType locationHiloId transmissionTime operationId status device { __typename ... on BasicSwitch { deviceType hiloId physicalAddress connectionStatus state power { value kind } } ... on BasicLight { deviceType hiloId physicalAddress connectionStatus state hue level saturation colorTemperature lightType } ... on HeatingFloorThermostat { deviceType hiloId physicalAddress connectionStatus ambientHumidity gDState version zigbeeVersion thermostatType physicalAddress floorMode power { value kind } ambientTemperature { value kind } ambientTempSetpoint { value kind } maxAmbientTempSetpoint { value kind } minAmbientTempSetpoint { value kind } floorLimit { value } } ... on BasicDimmer { deviceType hiloId physicalAddress connectionStatus state level power { value kind } } ... on BasicThermostat { deviceType hiloId physicalAddress connectionStatus ambientHumidity gDState version zigbeeVersion ambientTemperature { value kind } ambientTempSetpoint { value kind } maxAmbientTempSetpoint { value kind } minAmbientTempSetpoint { value kind } maxAmbientTempSetpointLimit { value kind } minAmbientTempSetpointLimit { value kind } heatDemand power { value kind } mode allowedModes } } } } `); const setupSubscription = async (locationHiloId, onUpdate) => { var _a; const logger = (0, logger_1.getLogger)(); try { logger.debug("Setting up subscription"); const client = (0, graphql_ws_1.createClient)({ url: `wss://platform.hiloenergie.com/api/digital-twin/v3/graphql?access_token=${(0, hiloApi_1.getAccessToken)()}`, retryAttempts: Infinity, webSocketImpl: ws_1.default, }); const subscription = client.iterate({ query: SUBSCRIPTION_QUERY.toString(), variables: { locationHiloId }, }); for await (const event of subscription) { logger.debug("GraphQL subscription event: ", event); if ((_a = event.data) === null || _a === void 0 ? void 0 : _a.onAnyDeviceUpdated) { if (types_1.SUPPORTED_DEVICES.includes(event.data.onAnyDeviceUpdated.device.__typename)) { onUpdate(event.data.onAnyDeviceUpdated.device); } } } return subscription; } catch (error) { logger.error("Error setting up subscription:", error); } }; exports.setupSubscription = setupSubscription; //# sourceMappingURL=subscription.js.map