From bd5204743f1e2c26c1e58e90b1b416efe7805826 Mon Sep 17 00:00:00 2001 From: Ingo Fischer Date: Mon, 5 Dec 2022 21:36:06 +0100 Subject: [PATCH] * (Apollon77) Optimize IR - now works locally and via cloud in all cases --- README.md | 8 +++++--- main.js | 15 +++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 57613d6..a0cbeba 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ The "ir-learn" state in this device is a Trigger which can be used to learn IR c The "ir-send" state can be used to send a base64 encoded IR code to the device. This can be used to send the learned code from the "ir-learn" state. -**This way to control only works on the "main IR device" and for devices with Datapoints 201/202 only when connected locally (no cloud connection) (right now).** +**This way to control only works on the "main IR device".** ### The IR Sub Devices The IR sub devices have a lot of "ir-*" states wich are all buttons to trigger the respective Button/IR code. The ir states should match the layout of the buttons in the mobile App. @@ -115,8 +115,6 @@ The IR sub devices have a lot of "ir-*" states wich are all buttons to trigger t Some devices have combi-states like "M0_T20_S3" (found by a Daikin Air conditioner) which means Mode 0, Temperature 20 and (Fan)-Speed 3. In fact you need to choose the right button. Until now we did not found a generic/automated way to find out which button is which. The mobile App itself also tries to remember these settings, so as soon you trigger anything with the adapter (or the real ir controller of the device) the information from the App is outdated. -**This way to control only works when app cloud credentials are entered. The commands will be send also out via cloud for now for devices with datapoints 201/202.** - ## Scenes features When the app cloud credentials are entered and stored then the adapter also reads out the scenes from the app and creates them as objects in the adapter. The scenes can be triggered by setting the scene state to true. @@ -143,6 +141,10 @@ When there are issues with the Tuya App Cloud synchronisation then additional lo Send the log with reference to the generated GitHub issue to iobroker@fischer-ka.de ## Changelog + +### __WORK IN PROGRESS__ +* (Apollon77) Optimize IR - now works locally and via cloud in all cases + ### 3.10.1 (2022-12-05) * (Apollon77) Make info.ip writable to allow manual setting of IP address diff --git a/main.js b/main.js index 7e1a4d6..9c7ed8f 100644 --- a/main.js +++ b/main.js @@ -593,7 +593,8 @@ async function initDeviceObjects(deviceId, data, objs, values, preserveFields) { delay: 300 }; - await sendLocallyOrCloud(deviceId, physicalDeviceId, data.dpCodes['ir_send'].id, JSON.stringify(irData), true, true); + // To send the head/key format locally we need to send it to the physical device + await sendLocallyOrCloud(physicalDeviceId, physicalDeviceId, data.dpCodes['ir_send'].id, JSON.stringify(irData), undefined, true); } else if (data.dpCodes['control'] && data.dpCodes['key_code'] && data.dpCodes['ir_code'] && data.dpCodes['type'] && data.dpCodes['delay_time']) { const keyArr = keyData.compressPulse.split(':'); const dps = {}; @@ -603,7 +604,7 @@ async function initDeviceObjects(deviceId, data, objs, values, preserveFields) { dps[data.dpCodes['type'].id.toString()] = 0; dps[data.dpCodes['delay_time'].id.toString()] = 300; - await sendLocallyOrCloud(deviceId, physicalDeviceId, 'multiple', dps, undefined, true); + await sendLocallyOrCloud(physicalDeviceId, physicalDeviceId, 'multiple', dps, undefined, true); } }; const keyId = keyData.key.replace(adapter.FORBIDDEN_CHARS, '_').replace(/[ +]/g, '_'); @@ -781,23 +782,21 @@ async function initDeviceObjects(deviceId, data, objs, values, preserveFields) { adapter.log.debug(`${deviceId} Send IR Code: ${value} with Type-Prefix 1`); value = value.toString(); if (data.dpCodes['ir_send']) { - if (value.length % 4 === 0) { - value = '1' + value; - } const irData = { control: 'send_ir', head: '', - 'key1': value, + 'key1': '1' + value, type: 0, delay: 300, }; - await sendLocallyOrCloud(deviceId, physicalDeviceId, data.dpCodes['ir_send'].id, JSON.stringify(irData), false, true); + await sendLocallyOrCloud(physicalDeviceId, physicalDeviceId, data.dpCodes['ir_send'].id, JSON.stringify(irData), undefined, true); } else if (data.dpCodes['control'] && data.dpCodes['key_study']) { const dps = {}; dps[data.dpCodes['control'].id.toString()] = 'study_key'; dps[data.dpCodes['key_study'].id.toString()] = value; + dps[data.dpCodes['type'].id.toString()] = 0; - await sendLocallyOrCloud(deviceId, physicalDeviceId, 'multiple', dps, undefined, true); + await sendLocallyOrCloud(physicalDeviceId, physicalDeviceId, 'multiple', dps, undefined, true); } }); }