From b6d3f13db2631d6c7a7a7c149043e9fa3b74a776 Mon Sep 17 00:00:00 2001 From: atrovato <1839717+atrovato@users.noreply.github.com> Date: Thu, 19 Oct 2023 12:01:51 +0200 Subject: [PATCH] Revert "Add mandatory traits" This reverts commit 59ed28f20cdc244d1f6e9610070d123d43f3f11e. --- .../deviceTypes/googleActions.curtain.type.js | 1 - .../deviceTypes/googleActions.light.type.js | 1 - .../deviceTypes/googleActions.shutter.type.js | 1 - .../deviceTypes/googleActions.switch.type.js | 1 - .../lib/deviceTypes/googleActions.tv.type.js | 8 -------- .../lib/smarthome/googleActions.onExecute.js | 10 +++------- .../traits/googleActions.appSelector.trait.js | 18 ----------------- .../googleActions.inputSelector.trait.js | 18 ----------------- .../google-actions/lib/traits/index.js | 4 ---- .../lib/utils/googleActions.determineTrait.js | 2 +- .../googleActions.determineTypeAndTraits.js | 8 -------- ...ogleActions.brightness.trait.light.test.js | 2 +- ...gleActions.brightness.trait.switch.test.js | 2 +- .../googleActions.channel.trait.tv.test.js | 20 ++----------------- ...leActions.colorSetting.trait.color.test.js | 2 +- ...tions.colorSetting.trait.colorTemp.test.js | 2 +- .../googleActions.onOff.trait.tv.test.js | 9 +-------- ...eActions.transportControl.trait.tv.test.js | 9 +-------- .../googleActions.volume.trait.tv.test.js | 18 ++--------------- .../smarthome/googleActions.onExecute.test.js | 2 -- 20 files changed, 14 insertions(+), 124 deletions(-) delete mode 100644 server/services/google-actions/lib/traits/googleActions.appSelector.trait.js delete mode 100644 server/services/google-actions/lib/traits/googleActions.inputSelector.trait.js diff --git a/server/services/google-actions/lib/deviceTypes/googleActions.curtain.type.js b/server/services/google-actions/lib/deviceTypes/googleActions.curtain.type.js index 12908c4b2f..7a28948e4a 100644 --- a/server/services/google-actions/lib/deviceTypes/googleActions.curtain.type.js +++ b/server/services/google-actions/lib/deviceTypes/googleActions.curtain.type.js @@ -6,7 +6,6 @@ const { DEVICE_FEATURE_CATEGORIES } = require('../../../../utils/constants'); const curtainType = { key: 'action.devices.types.CURTAIN', category: DEVICE_FEATURE_CATEGORIES.CURTAIN, - mandatoryTraits: ['action.devices.traits.OpenClose'], }; module.exports = { diff --git a/server/services/google-actions/lib/deviceTypes/googleActions.light.type.js b/server/services/google-actions/lib/deviceTypes/googleActions.light.type.js index 44fbf3232f..71aa2d33c5 100644 --- a/server/services/google-actions/lib/deviceTypes/googleActions.light.type.js +++ b/server/services/google-actions/lib/deviceTypes/googleActions.light.type.js @@ -6,7 +6,6 @@ const { DEVICE_FEATURE_CATEGORIES } = require('../../../../utils/constants'); const lightType = { key: 'action.devices.types.LIGHT', category: DEVICE_FEATURE_CATEGORIES.LIGHT, - mandatoryTraits: ['action.devices.traits.OnOff'], }; module.exports = { diff --git a/server/services/google-actions/lib/deviceTypes/googleActions.shutter.type.js b/server/services/google-actions/lib/deviceTypes/googleActions.shutter.type.js index e025204994..f276c4148f 100644 --- a/server/services/google-actions/lib/deviceTypes/googleActions.shutter.type.js +++ b/server/services/google-actions/lib/deviceTypes/googleActions.shutter.type.js @@ -6,7 +6,6 @@ const { DEVICE_FEATURE_CATEGORIES } = require('../../../../utils/constants'); const shutterType = { key: 'action.devices.types.SHUTTER', category: DEVICE_FEATURE_CATEGORIES.SHUTTER, - mandatoryTraits: ['action.devices.traits.OpenClose'], }; module.exports = { diff --git a/server/services/google-actions/lib/deviceTypes/googleActions.switch.type.js b/server/services/google-actions/lib/deviceTypes/googleActions.switch.type.js index 05c5221c2a..4b4aad0866 100644 --- a/server/services/google-actions/lib/deviceTypes/googleActions.switch.type.js +++ b/server/services/google-actions/lib/deviceTypes/googleActions.switch.type.js @@ -6,7 +6,6 @@ const { DEVICE_FEATURE_CATEGORIES } = require('../../../../utils/constants'); const switchType = { key: 'action.devices.types.SWITCH', category: DEVICE_FEATURE_CATEGORIES.SWITCH, - mandatoryTraits: ['action.devices.traits.OnOff'], }; module.exports = { diff --git a/server/services/google-actions/lib/deviceTypes/googleActions.tv.type.js b/server/services/google-actions/lib/deviceTypes/googleActions.tv.type.js index 2b1184a0a6..2586146df2 100644 --- a/server/services/google-actions/lib/deviceTypes/googleActions.tv.type.js +++ b/server/services/google-actions/lib/deviceTypes/googleActions.tv.type.js @@ -6,14 +6,6 @@ const { DEVICE_FEATURE_CATEGORIES } = require('../../../../utils/constants'); const televisionType = { key: 'action.devices.types.TV', category: DEVICE_FEATURE_CATEGORIES.TELEVISION, - mandatoryTraits: [ - 'action.devices.traits.AppSelector', - 'action.devices.traits.InputSelector', - 'action.devices.traits.MediaState', - 'action.devices.traits.OnOff', - 'action.devices.traits.TransportControl', - 'action.devices.traits.Volume', - ], }; module.exports = { diff --git a/server/services/google-actions/lib/smarthome/googleActions.onExecute.js b/server/services/google-actions/lib/smarthome/googleActions.onExecute.js index 374234f09e..56d802a65d 100644 --- a/server/services/google-actions/lib/smarthome/googleActions.onExecute.js +++ b/server/services/google-actions/lib/smarthome/googleActions.onExecute.js @@ -41,14 +41,13 @@ async function onExecute(body) { // Command key not found logger.error(`GoogleActions "${exec.command}" command is not managed.`); // All devices are failure - commands.push({ ids: [selector], status: 'ERROR', errorCode: 'functionNotSupported' }); + commands.push({ ids: [selector], status: 'ERROR' }); } else { const commandExecutor = trait.commands[exec.command]; - const deviceStatus = { ids: [selector] }; + const deviceStatus = { ids: [selector], status: 'ERROR' }; // Build related feature events according incomping attributes - // errorCodes : see https://developers.home.google.com/cloud-to-cloud/intents/errors-exceptions - const { events = [], errorCode } = await commandExecutor(gladysDevice, exec.params, this.gladys); + const { events = [] } = await commandExecutor(gladysDevice, exec.params, this.gladys); if (events.length > 0) { events.forEach((eventMessage) => { @@ -61,9 +60,6 @@ async function onExecute(body) { this.gladys.event.emit(EVENTS.ACTION.TRIGGERED, action); }); deviceStatus.status = 'PENDING'; - } else { - deviceStatus.status = 'ERROR'; - deviceStatus.errorCode = errorCode || 'functionNotSupported'; } commands.push(deviceStatus); diff --git a/server/services/google-actions/lib/traits/googleActions.appSelector.trait.js b/server/services/google-actions/lib/traits/googleActions.appSelector.trait.js deleted file mode 100644 index 4b00379ee7..0000000000 --- a/server/services/google-actions/lib/traits/googleActions.appSelector.trait.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * @see https://developers.google.com/assistant/smarthome/traits/appselector - */ -const appSelectorTrait = { - key: 'action.devices.traits.AppSelector', - features: [], - generateAttributes: () => { - return { - availableApplications: [], - }; - }, - states: [], - commands: {}, -}; - -module.exports = { - appSelectorTrait, -}; diff --git a/server/services/google-actions/lib/traits/googleActions.inputSelector.trait.js b/server/services/google-actions/lib/traits/googleActions.inputSelector.trait.js deleted file mode 100644 index 48a9a731a5..0000000000 --- a/server/services/google-actions/lib/traits/googleActions.inputSelector.trait.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * @see https://developers.google.com/assistant/smarthome/traits/inputselector - */ -const inputSelectorTrait = { - key: 'action.devices.traits.InputSelector', - features: [], - generateAttributes: () => { - return { - availableInputs: [], - }; - }, - states: [], - commands: {}, -}; - -module.exports = { - inputSelectorTrait, -}; diff --git a/server/services/google-actions/lib/traits/index.js b/server/services/google-actions/lib/traits/index.js index 066c2cd5b7..aa71eb161c 100644 --- a/server/services/google-actions/lib/traits/index.js +++ b/server/services/google-actions/lib/traits/index.js @@ -1,19 +1,15 @@ -const { appSelectorTrait } = require('./googleActions.appSelector.trait'); const { brightnessTrait } = require('./googleActions.brightness.trait'); const { channelTrait } = require('./googleActions.channel.trait'); const { colorSettingTrait } = require('./googleActions.colorSetting.trait'); -const { inputSelectorTrait } = require('./googleActions.inputSelector.trait'); const { onOffTrait } = require('./googleActions.onOff.trait'); const { openCloseTrait } = require('./googleActions.openClose.trait'); const { transportControl } = require('./googleActions.transportControl.trait'); const { volumeTrait } = require('./googleActions.volume.trait'); const TRAITS = [ - appSelectorTrait, brightnessTrait, channelTrait, colorSettingTrait, - inputSelectorTrait, onOffTrait, openCloseTrait, transportControl, diff --git a/server/services/google-actions/lib/utils/googleActions.determineTrait.js b/server/services/google-actions/lib/utils/googleActions.determineTrait.js index 7b9fe58c6a..69e8170a1e 100644 --- a/server/services/google-actions/lib/utils/googleActions.determineTrait.js +++ b/server/services/google-actions/lib/utils/googleActions.determineTrait.js @@ -23,7 +23,7 @@ const exploreTrait = (trait, feature) => { * @param {object} feature - Gladys device feature. * @returns {object} GoogleActions device type and traits. * @example - * determineTrait(device); + * determineTypeAndTraits(device); */ function determineTrait(feature) { // Matching feature trait diff --git a/server/services/google-actions/lib/utils/googleActions.determineTypeAndTraits.js b/server/services/google-actions/lib/utils/googleActions.determineTypeAndTraits.js index ebc336baa5..8fed4e10f6 100644 --- a/server/services/google-actions/lib/utils/googleActions.determineTypeAndTraits.js +++ b/server/services/google-actions/lib/utils/googleActions.determineTypeAndTraits.js @@ -43,14 +43,6 @@ function determineTypeAndTraits(device) { if (nbFeatureTypeMatch > nbFeatureTypeMatches) { type = deviceType.key; nbFeatureTypeMatches = nbFeatureTypeMatch; - - const mandatoryTraits = deviceType.mandatoryTraits || []; - mandatoryTraits.forEach((trait) => { - // Add mandatory trait only if missing - if (!traits.includes(trait)) { - traits.push(trait); - } - }); } }); diff --git a/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.brightness.trait.light.test.js b/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.brightness.trait.light.test.js index f763bcea08..dc6053f50c 100644 --- a/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.brightness.trait.light.test.js +++ b/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.brightness.trait.light.test.js @@ -103,7 +103,7 @@ describe('GoogleActions Handler - onSync - brightness (light)', () => { { id: 'device-1', type: 'action.devices.types.LIGHT', - traits: ['action.devices.traits.Brightness', 'action.devices.traits.OnOff'], + traits: ['action.devices.traits.Brightness'], attributes: {}, name: { name: 'Device 1', diff --git a/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.brightness.trait.switch.test.js b/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.brightness.trait.switch.test.js index ed2b1863d9..f4602523fd 100644 --- a/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.brightness.trait.switch.test.js +++ b/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.brightness.trait.switch.test.js @@ -103,7 +103,7 @@ describe('GoogleActions Handler - onSync - brightness (switch)', () => { { id: 'device-1', type: 'action.devices.types.SWITCH', - traits: ['action.devices.traits.Brightness', 'action.devices.traits.OnOff'], + traits: ['action.devices.traits.Brightness'], attributes: {}, name: { name: 'Device 1', diff --git a/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.channel.trait.tv.test.js b/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.channel.trait.tv.test.js index bebdb7ca9f..9745d173e3 100644 --- a/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.channel.trait.tv.test.js +++ b/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.channel.trait.tv.test.js @@ -103,15 +103,7 @@ describe('GoogleActions Handler - onSync - channel (tv)', () => { { id: 'device-1', type: 'action.devices.types.TV', - traits: [ - 'action.devices.traits.Channel', - 'action.devices.traits.AppSelector', - 'action.devices.traits.InputSelector', - 'action.devices.traits.MediaState', - 'action.devices.traits.OnOff', - 'action.devices.traits.TransportControl', - 'action.devices.traits.Volume', - ], + traits: ['action.devices.traits.Channel'], attributes: { commandOnlyChannels: true, }, @@ -154,15 +146,7 @@ describe('GoogleActions Handler - onSync - channel (tv)', () => { { id: 'device-1', type: 'action.devices.types.TV', - traits: [ - 'action.devices.traits.Channel', - 'action.devices.traits.AppSelector', - 'action.devices.traits.InputSelector', - 'action.devices.traits.MediaState', - 'action.devices.traits.OnOff', - 'action.devices.traits.TransportControl', - 'action.devices.traits.Volume', - ], + traits: ['action.devices.traits.Channel'], attributes: { commandOnlyChannels: false, }, diff --git a/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.colorSetting.trait.color.test.js b/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.colorSetting.trait.color.test.js index 8558c4304e..9e7b2e6a5f 100644 --- a/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.colorSetting.trait.color.test.js +++ b/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.colorSetting.trait.color.test.js @@ -101,7 +101,7 @@ describe('GoogleActions Handler - onSync - color', () => { { id: 'device-1', type: 'action.devices.types.LIGHT', - traits: ['action.devices.traits.ColorSetting', 'action.devices.traits.OnOff'], + traits: ['action.devices.traits.ColorSetting'], attributes: { colorModel: 'rgb', }, diff --git a/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.colorSetting.trait.colorTemp.test.js b/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.colorSetting.trait.colorTemp.test.js index 0618bf6979..5c481b410e 100644 --- a/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.colorSetting.trait.colorTemp.test.js +++ b/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.colorSetting.trait.colorTemp.test.js @@ -106,7 +106,7 @@ describe('GoogleActions Handler - onSync - color', () => { { id: 'device-1', type: 'action.devices.types.LIGHT', - traits: ['action.devices.traits.ColorSetting', 'action.devices.traits.OnOff'], + traits: ['action.devices.traits.ColorSetting'], attributes: { colorTemperatureRange: { temperatureMinK: 2203, diff --git a/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.onOff.trait.tv.test.js b/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.onOff.trait.tv.test.js index 168c27c06a..d19bbfef80 100644 --- a/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.onOff.trait.tv.test.js +++ b/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.onOff.trait.tv.test.js @@ -101,14 +101,7 @@ describe('GoogleActions Handler - onSync - onOff (tv)', () => { { id: 'device-1', type: 'action.devices.types.TV', - traits: [ - 'action.devices.traits.OnOff', - 'action.devices.traits.AppSelector', - 'action.devices.traits.InputSelector', - 'action.devices.traits.MediaState', - 'action.devices.traits.TransportControl', - 'action.devices.traits.Volume', - ], + traits: ['action.devices.traits.OnOff'], attributes: {}, name: { name: 'Device 1', diff --git a/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.transportControl.trait.tv.test.js b/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.transportControl.trait.tv.test.js index 3d1efbdd01..211ffced1f 100644 --- a/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.transportControl.trait.tv.test.js +++ b/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.transportControl.trait.tv.test.js @@ -103,14 +103,7 @@ describe('GoogleActions Handler - onSync - TransportControl (tv)', () => { { id: 'device-1', type: 'action.devices.types.TV', - traits: [ - 'action.devices.traits.TransportControl', - 'action.devices.traits.AppSelector', - 'action.devices.traits.InputSelector', - 'action.devices.traits.MediaState', - 'action.devices.traits.OnOff', - 'action.devices.traits.Volume', - ], + traits: ['action.devices.traits.TransportControl'], attributes: { transportControlSupportedCommands: ['PAUSE', 'RESUME', 'STOP', 'NEXT', 'PREVIOUS'], }, diff --git a/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.volume.trait.tv.test.js b/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.volume.trait.tv.test.js index 0776f3fd65..7939363c6c 100644 --- a/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.volume.trait.tv.test.js +++ b/server/test/services/google-actions/lib/smarthome/devices_and_traits/googleActions.volume.trait.tv.test.js @@ -114,14 +114,7 @@ describe('GoogleActions Handler - onSync - volume (tv)', () => { { id: 'device-1', type: 'action.devices.types.TV', - traits: [ - 'action.devices.traits.Volume', - 'action.devices.traits.AppSelector', - 'action.devices.traits.InputSelector', - 'action.devices.traits.MediaState', - 'action.devices.traits.OnOff', - 'action.devices.traits.TransportControl', - ], + traits: ['action.devices.traits.Volume'], attributes: { volumeMaxLevel: 45, volumeCanMuteAndUnmute: false, @@ -166,14 +159,7 @@ describe('GoogleActions Handler - onSync - volume (tv)', () => { { id: 'device-1', type: 'action.devices.types.TV', - traits: [ - 'action.devices.traits.Volume', - 'action.devices.traits.AppSelector', - 'action.devices.traits.InputSelector', - 'action.devices.traits.MediaState', - 'action.devices.traits.OnOff', - 'action.devices.traits.TransportControl', - ], + traits: ['action.devices.traits.Volume'], attributes: { volumeMaxLevel: 30, volumeCanMuteAndUnmute: true, diff --git a/server/test/services/google-actions/lib/smarthome/googleActions.onExecute.test.js b/server/test/services/google-actions/lib/smarthome/googleActions.onExecute.test.js index 13424611ee..d56b6b209c 100644 --- a/server/test/services/google-actions/lib/smarthome/googleActions.onExecute.test.js +++ b/server/test/services/google-actions/lib/smarthome/googleActions.onExecute.test.js @@ -202,7 +202,6 @@ describe('GoogleActions Handler - onExecute', () => { { ids: ['device-1'], status: 'ERROR', - errorCode: 'functionNotSupported', }, ], }, @@ -255,7 +254,6 @@ describe('GoogleActions Handler - onExecute', () => { { ids: ['device-1'], status: 'ERROR', - errorCode: 'functionNotSupported', }, ], },