diff --git a/front/src/routes/calendar/index.js b/front/src/routes/calendar/index.js
index 24d5427f8c..5bf551fd3b 100644
--- a/front/src/routes/calendar/index.js
+++ b/front/src/routes/calendar/index.js
@@ -64,7 +64,6 @@ class Map extends Component {
render(props, {}) {
const noCalendarConnected = props.calendars && props.calendars.length === 0;
- console.log(noCalendarConnected, props.calendars);
return (
diff --git a/front/src/routes/scene/edit-scene/ActionCard.jsx b/front/src/routes/scene/edit-scene/ActionCard.jsx
index e175b0e4dc..5ad60becaa 100644
--- a/front/src/routes/scene/edit-scene/ActionCard.jsx
+++ b/front/src/routes/scene/edit-scene/ActionCard.jsx
@@ -251,6 +251,8 @@ const ActionCard = ({ children, ...props }) => (
columnIndex={props.columnIndex}
index={props.index}
updateActionProperty={props.updateActionProperty}
+ variables={props.variables}
+ setVariables={props.setVariables}
/>
)}
diff --git a/front/src/routes/scene/edit-scene/actions/CalendarIsEventRunning.jsx b/front/src/routes/scene/edit-scene/actions/CalendarIsEventRunning.jsx
index fd9d421dc1..aac9b9bb89 100644
--- a/front/src/routes/scene/edit-scene/actions/CalendarIsEventRunning.jsx
+++ b/front/src/routes/scene/edit-scene/actions/CalendarIsEventRunning.jsx
@@ -6,6 +6,8 @@ import { Text, Localizer } from 'preact-i18n';
import cx from 'classnames';
import get from 'get-value';
+import withIntlAsProp from '../../../../utils/withIntlAsProp';
+
import style from './CalendarIsEventRunning.css';
const isNullOrUndefined = variable => variable === null || variable === undefined;
@@ -66,6 +68,14 @@ class CheckTime extends Component {
);
};
+ initVariables = action => {
+ if (action.stop_scene_if_event_found === false) {
+ this.setVariables();
+ } else {
+ this.removeVariables();
+ }
+ };
+
refreshSelectedOptions = action => {
const selectedCalendarsOptions = [];
if (action.calendars && this.state.calendarsOptions) {
@@ -76,6 +86,10 @@ class CheckTime extends Component {
}
});
}
+ if (get(this.props, 'action.stop_scene_if_event_found') !== action.stop_scene_if_event_found) {
+ this.initVariables(action);
+ }
+
this.setState({ selectedCalendarsOptions });
};
@@ -99,9 +113,53 @@ class CheckTime extends Component {
}
};
+ setVariables = () => {
+ const { columnIndex, index } = this.props;
+ const EVENT_NAME_VARIABLE = get(this.props.intl.dictionary, 'editScene.variables.calendar.eventName');
+ const EVENT_LOCATION_VARIABLE = get(this.props.intl.dictionary, 'editScene.variables.calendar.eventLocation');
+ const EVENT_START_VARIABLE = get(this.props.intl.dictionary, 'editScene.variables.calendar.eventStart');
+ const EVENT_END_VARIABLE = get(this.props.intl.dictionary, 'editScene.variables.calendar.eventEnd');
+ this.props.setVariables(columnIndex, index, [
+ {
+ name: 'calendarEvent.name',
+ type: 'calendar',
+ ready: true,
+ label: EVENT_NAME_VARIABLE,
+ data: {}
+ },
+ {
+ name: 'calendarEvent.location',
+ type: 'calendar',
+ ready: true,
+ label: EVENT_LOCATION_VARIABLE,
+ data: {}
+ },
+ {
+ name: 'calendarEvent.start',
+ type: 'calendar',
+ ready: true,
+ label: EVENT_START_VARIABLE,
+ data: {}
+ },
+ {
+ name: 'calendarEvent.end',
+ type: 'calendar',
+ ready: true,
+ label: EVENT_END_VARIABLE,
+ data: {}
+ }
+ ]);
+ };
+
+ removeVariables = () => {
+ const { columnIndex, index } = this.props;
+ this.props.setVariables(columnIndex, index, []);
+ };
+
componentDidMount() {
this.initActionIfNeeded();
this.getCalendars();
+ this.initVariables(this.props.action);
}
componentWillReceiveProps(nextProps) {
@@ -218,4 +276,4 @@ class CheckTime extends Component {
}
}
-export default connect('user,httpClient', {})(CheckTime);
+export default connect('user,httpClient', {})(withIntlAsProp(CheckTime));
diff --git a/server/lib/scene/scene.actions.js b/server/lib/scene/scene.actions.js
index ab45f73473..6301109861 100644
--- a/server/lib/scene/scene.actions.js
+++ b/server/lib/scene/scene.actions.js
@@ -271,7 +271,7 @@ const actionsFunc = {
await self.house.userLeft(action.house, action.user);
}
},
- [ACTIONS.CALENDAR.IS_EVENT_RUNNING]: async (self, action) => {
+ [ACTIONS.CALENDAR.IS_EVENT_RUNNING]: async (self, action, scope, columnIndex, rowIndex) => {
// find if one event match the condition
const events = await self.calendar.findCurrentlyRunningEvent(
action.calendars,
@@ -288,6 +288,26 @@ const actionsFunc = {
if (!atLeastOneEventFound && action.stop_scene_if_event_not_found === true) {
throw new AbortScene('EVENT_NOT_FOUND');
}
+
+ // set variable
+ if (atLeastOneEventFound) {
+ const eventRaw = events[0];
+ const eventFormatted = {
+ name: eventRaw.name,
+ location: eventRaw.location,
+ start: dayjs(eventRaw.start)
+ .tz(self.timezone)
+ .locale(eventRaw.calendar.creator.language)
+ .format('LLL'),
+ end: dayjs(eventRaw.end)
+ .tz(self.timezone)
+ .locale(eventRaw.calendar.creator.language)
+ .format('LLL'),
+ };
+ set(scope, `${columnIndex}.${rowIndex}`, {
+ calendarEvent: eventFormatted,
+ });
+ }
},
};
diff --git a/server/lib/scene/scene.checkCalendarTriggers.js b/server/lib/scene/scene.checkCalendarTriggers.js
index 81199355af..3be4e13e64 100644
--- a/server/lib/scene/scene.checkCalendarTriggers.js
+++ b/server/lib/scene/scene.checkCalendarTriggers.js
@@ -114,7 +114,7 @@ async function checkCalendarTriggers() {
.tz(this.timezone)
.locale(eventRaw.calendar.creator.language)
.format('LLL'),
- end: dayjs(eventRaw.start)
+ end: dayjs(eventRaw.end)
.tz(this.timezone)
.locale(eventRaw.calendar.creator.language)
.format('LLL'),
diff --git a/server/test/lib/scene/actions/scene.action.isEventRunnning.test.js b/server/test/lib/scene/actions/scene.action.isEventRunnning.test.js
index 98cffcd36f..adb27cb745 100644
--- a/server/test/lib/scene/actions/scene.action.isEventRunnning.test.js
+++ b/server/test/lib/scene/actions/scene.action.isEventRunnning.test.js
@@ -1,7 +1,9 @@
const { assert, fake, useFakeTimers } = require('sinon');
const chaiAssert = require('chai').assert;
+const { expect } = require('chai');
const dayjs = require('dayjs');
const EventEmitter = require('events');
+
const { ACTIONS } = require('../../../../utils/constants');
const { AbortScene } = require('../../../../utils/coreErrors');
const { executeActions } = require('../../../../lib/scene/scene.executeActions');
@@ -36,11 +38,12 @@ describe('scene.action.isEventRunning', () => {
await calendar.createEvent('test-calendar', {
id: 'a2b57b0a-7148-4961-8540-e493104bfd7c',
name: 'my test event',
+ location: 'school',
start: startDate,
end: endDate,
});
await executeActions(
- { stateManager, event, message, calendar },
+ { stateManager, event, message, calendar, timezone: 'Europe/Paris' },
[
[
{
@@ -62,6 +65,24 @@ describe('scene.action.isEventRunning', () => {
scope,
);
assert.calledWith(message.sendToUser, 'pepper', 'hello');
+ expect(scope).to.deep.equal({
+ '0': {
+ '0': {
+ calendarEvent: {
+ name: 'my test event',
+ location: 'school',
+ start: dayjs(startDate)
+ .tz('Europe/Paris')
+ .locale('en')
+ .format('LLL'),
+ end: dayjs(endDate)
+ .tz('Europe/Paris')
+ .locale('en')
+ .format('LLL'),
+ },
+ },
+ },
+ });
});
it('should execute condition is-event-running, and not send message because scene should stop', async () => {
const stateManager = new StateManager(event);
diff --git a/server/test/lib/scene/scene.checkCalendarTriggers.test.js b/server/test/lib/scene/scene.checkCalendarTriggers.test.js
index 15d07b67d7..a5378f8cbc 100644
--- a/server/test/lib/scene/scene.checkCalendarTriggers.test.js
+++ b/server/test/lib/scene/scene.checkCalendarTriggers.test.js
@@ -75,7 +75,7 @@ describe('scene.checkCalendarTriggers', () => {
.tz('Europe/Paris')
.locale('en')
.format('LLL'),
- end: dayjs(startDate)
+ end: dayjs(endDate)
.tz('Europe/Paris')
.locale('en')
.format('LLL'),