diff --git a/front/src/routes/scene/edit-scene/ActionCard.jsx b/front/src/routes/scene/edit-scene/ActionCard.jsx index 6723defc91..73ec11775b 100644 --- a/front/src/routes/scene/edit-scene/ActionCard.jsx +++ b/front/src/routes/scene/edit-scene/ActionCard.jsx @@ -105,7 +105,7 @@ const ActionCard = ({ children, ...props }) => { 'col-lg-6': props.action.type === ACTIONS.MESSAGE.SEND || props.action.type === ACTIONS.CALENDAR.IS_EVENT_RUNNING || - props.action.type === ACTIONS.MQTT.SEND || + props.action.type === ACTIONS.MQTT.SEND || ACTIONS.ZIGBEE2MQTT.SEND || props.action.type === ACTIONS.LIGHT.BLINK, 'col-lg-4': props.action.type !== ACTIONS.CONDITION.ONLY_CONTINUE_IF && diff --git a/server/test/lib/scene/actions/scene.action.sendZigbee2MqttMessage.test.js b/server/test/lib/scene/actions/scene.action.sendZigbee2MqttMessage.test.js new file mode 100644 index 0000000000..a9b710cf60 --- /dev/null +++ b/server/test/lib/scene/actions/scene.action.sendZigbee2MqttMessage.test.js @@ -0,0 +1,87 @@ +const { fake, assert } = require('sinon'); +const EventEmitter = require('events'); + +const { ACTIONS } = require('../../../../utils/constants'); +const { executeActions } = require('../../../../lib/scene/scene.executeActions'); + +const StateManager = require('../../../../lib/state'); + +const event = new EventEmitter(); + +describe('scene.send-zigbee2mqtt-message', () => { + it('should send message with value injected from device get-value', async () => { + const stateManager = new StateManager(event); + stateManager.setState('deviceFeature', 'my-device-feature', { + category: 'light', + type: 'binary', + last_value: 15, + }); + const zigbee2MqttService = { + device: { + publish: fake.resolves(null), + }, + }; + const service = { + getService: fake.returns(zigbee2MqttService), + }; + const scope = {}; + await executeActions( + { stateManager, event, service }, + [ + [ + { + type: ACTIONS.DEVICE.GET_VALUE, + device_feature: 'my-device-feature', + }, + ], + [ + { + type: ACTIONS.ZIGBEE2MQTT.SEND, + topic: '/my/mqtt/topic', + message: 'Temperature in the living room is {{0.0.last_value}} °C.', + }, + ], + ], + scope, + ); + assert.calledWith(zigbee2MqttService.device.publish, '/my/mqtt/topic', 'Temperature in the living room is 15 °C.'); + }); + it('should send message with value injected from http-request', async () => { + const stateManager = new StateManager(event); + const http = { + request: fake.resolves({ result: [15], error: null }), + }; + const zigbee2MqttService = { + device: { + publish: fake.resolves(null), + }, + }; + const service = { + getService: fake.returns(zigbee2MqttService), + }; + const scope = {}; + await executeActions( + { stateManager, event, service, http }, + [ + [ + { + type: ACTIONS.HTTP.REQUEST, + method: 'post', + url: 'http://test.test', + body: '{"toto":"toto"}', + headers: [], + }, + ], + [ + { + type: ACTIONS.ZIGBEE2MQTT.SEND, + topic: '/my/mqtt/topic', + message: 'Temperature in the living room is {{0.0.result.[0]}} °C.', + }, + ], + ], + scope, + ); + assert.calledWith(zigbee2MqttService.device.publish, '/my/mqtt/topic', 'Temperature in the living room is 15 °C.'); + }); +});