diff --git a/front/src/routes/scene/edit-scene/triggers/ScheduledTrigger.jsx b/front/src/routes/scene/edit-scene/triggers/ScheduledTrigger.jsx index 74d8edb1c0..e18fdb4378 100644 --- a/front/src/routes/scene/edit-scene/triggers/ScheduledTrigger.jsx +++ b/front/src/routes/scene/edit-scene/triggers/ScheduledTrigger.jsx @@ -27,10 +27,28 @@ class TurnOnLight extends Component { this.resetForm(); if (schedulerType === 'every-month') { this.props.updateTriggerProperty(this.props.index, 'day_of_the_month', 1); + this.props.updateTriggerProperty(this.props.index, 'time', '12:00'); } else if (schedulerType === 'every-week') { - this.props.updateTriggerProperty(this.props.index, 'days_of_the_week', []); + this.props.updateTriggerProperty(this.props.index, 'days_of_the_week', [ + 'monday', + 'tuesday', + 'wednesday', + 'thursday', + 'friday', + 'saturday', + 'sunday' + ]); + this.props.updateTriggerProperty(this.props.index, 'time', '12:00'); + } else if (schedulerType === 'every-day') { + this.props.updateTriggerProperty(this.props.index, 'time', '12:00'); + } else if (schedulerType === 'custom-time') { + let tomorrow = new Date(); + tomorrow.setDate(tomorrow.getDate() + 1); + this.props.updateTriggerProperty(this.props.index, 'time', '12:00'); + this.props.updateTriggerProperty(this.props.index, 'date', format(tomorrow, 'yyyy-MM-dd')); } else if (schedulerType === 'interval') { this.props.updateTriggerProperty(this.props.index, 'unit', 'second'); + this.props.updateTriggerProperty(this.props.index, 'interval', 30); } }; handleDateChange = date => { diff --git a/server/index.js b/server/index.js index 82bd676c4a..b9c3b526d1 100644 --- a/server/index.js +++ b/server/index.js @@ -45,6 +45,7 @@ process.on('SIGINT', () => shutdown('SIGINT')); // create Gladys object const gladys = Gladys({ jwtSecret: process.env.JWT_SECRET, + disableDeviceStateAggregation: true, }); // start Gladys diff --git a/server/lib/scene/scene.addScene.js b/server/lib/scene/scene.addScene.js index 277e9d9f5b..36af10f277 100644 --- a/server/lib/scene/scene.addScene.js +++ b/server/lib/scene/scene.addScene.js @@ -48,6 +48,17 @@ function addScene(sceneRaw) { break; case 'every-week': rule.dayOfWeek = trigger.days_of_the_week.map((day) => nodeScheduleDaysOfWeek[day]); + if (rule.dayOfWeek.length === 0) { + rule.dayOfWeek = [ + nodeScheduleDaysOfWeek.monday, + nodeScheduleDaysOfWeek.tuesday, + nodeScheduleDaysOfWeek.wednesday, + nodeScheduleDaysOfWeek.thursday, + nodeScheduleDaysOfWeek.friday, + nodeScheduleDaysOfWeek.saturday, + nodeScheduleDaysOfWeek.sunday, + ]; + } rule.hour = parseInt(trigger.time.substr(0, 2), 10); rule.minute = parseInt(trigger.time.substr(3, 2), 10); rule.second = 0; diff --git a/server/lib/scene/scene.init.js b/server/lib/scene/scene.init.js index 97e2c03842..cf5e280421 100644 --- a/server/lib/scene/scene.init.js +++ b/server/lib/scene/scene.init.js @@ -19,8 +19,16 @@ async function init() { const scenes = await db.Scene.findAll(); const plainScenes = scenes.map((scene) => { const plainScene = scene.get({ plain: true }); - this.addScene(plainScene); - this.brain.addNamedEntity('scene', plainScene.selector, plainScene.name); + logger.debug(`Loading scene ${plainScene.name}`); + try { + this.addScene(plainScene); + this.brain.addNamedEntity('scene', plainScene.selector, plainScene.name); + logger.debug(`Scene loaded with success`); + } catch (e) { + logger.warn(`Unable to load scene ${plainScene.name}`); + logger.warn(e); + } + return plainScene; }); diff --git a/server/test/lib/scene/scene.init.test.js b/server/test/lib/scene/scene.init.test.js index 60a1dc81e9..74d69a20e4 100644 --- a/server/test/lib/scene/scene.init.test.js +++ b/server/test/lib/scene/scene.init.test.js @@ -1,5 +1,6 @@ const { expect } = require('chai'); const sinon = require('sinon'); +const db = require('../../../models'); const SceneManager = require('../../../lib/scene'); const { fake, assert } = sinon; @@ -58,4 +59,35 @@ describe('scene.init', () => { scheduler.scheduleJob.getCall(3).callback(); assert.calledOnceWithExactly(event.emit, 'calendar.check-if-event-is-coming'); }); + it('should init scene with failure but not crash', async () => { + await db.Scene.create({ + name: 'broken-scene', + icon: 'activity', + triggers: [ + { + type: 'time.changed', + scheduler_type: 'every-month', + day_of_the_month: 1, + }, + ], + actions: [[]], + }); + await sceneManager.init(); + }); + it('should init scheduled scene with with no days of the week specified, but prevent node-schedule from blocking forever', async () => { + await db.Scene.create({ + name: 'broken-scene', + icon: 'activity', + triggers: [ + { + type: 'time.changed', + scheduler_type: 'every-week', + days_of_the_week: [], + time: '12:00', + }, + ], + actions: [[]], + }); + await sceneManager.init(); + }); });