Skip to content

Commit

Permalink
Add scheduled trigger in scenes (#673)
Browse files Browse the repository at this point in the history
* Scheduled Trigger front part

* Add default value for interval unit + change timeIntervals in UI

* First version of backend working

* Add a way to select multiple days in week view

* Fix tests & add some

* Fix post /api/v1/scene test

* Add tests on cancelTriggers function

* Add more tests to scene.addScene
  • Loading branch information
Pierre-Gilles authored Mar 7, 2020
1 parent 46238ea commit 1631d3c
Show file tree
Hide file tree
Showing 24 changed files with 884 additions and 34 deletions.
75 changes: 60 additions & 15 deletions front/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"identity-obj-proxy": "^3.0.0",
"jest": "^21.2.1",
"per-env": "^1.0.2",
"preact-cli": "^2.1.0",
"preact-cli": "^2.2.1",
"preact-render-spy": "^1.2.1",
"prettier": "^1.17.1"
},
Expand All @@ -30,6 +30,7 @@
"axios": "^0.18.0",
"classnames": "^2.2.6",
"cropperjs": "^1.5.1",
"date-fns": "^2.10.0",
"dayjs": "^1.8.14",
"debounce": "^1.2.0",
"dotenv": "^6.2.0",
Expand All @@ -44,6 +45,7 @@
"preact-router": "^3.2.1",
"qrcode": "^1.4.2",
"react-big-calendar": "^0.22.1",
"react-datepicker": "^2.13.0",
"react-select": "^3.0.8",
"react-stripe-elements": "^5.0.1",
"set-value": "^3.0.0",
Expand Down
32 changes: 32 additions & 0 deletions front/src/config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,9 @@
"triggers": {
"device": {
"new-state": "Device state change"
},
"time": {
"changed": "Scheduled trigger"
}
},
"triggersCard": {
Expand All @@ -521,6 +524,35 @@
"valuePlaceholder": "Value",
"on": "On",
"off": "Off"
},
"scheduledTrigger": {
"everyMonth": "Every month",
"everyWeek": "Every week",
"everyDay": "Every day",
"interval": "Interval",
"customTime": "On a specific day",
"dateLabel": "Date",
"timeLabel": "Time",
"unitLabel": "Unit",
"intervalLabel": "Interval",
"daysOfTheWeekLabel": "Days of the week",
"dayOfTheMonthLabel": "Day of the month",
"dateFormat": "MM-dd-yyyy",
"timeCaption": "Time",
"units": {
"second": "seconds",
"minute": "minutes",
"hour": "hours"
},
"daysOfTheWeek": {
"monday": "Monday",
"tuesday": "Tuesday",
"wednesday": "Wednesday",
"thursday": "Thursday",
"friday": "Friday",
"saturday": "Saturday",
"sunday": "Sunday"
}
}
}
},
Expand Down
15 changes: 13 additions & 2 deletions front/src/routes/scene/edit-scene/TriggerCard.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { h } from 'preact';
import { Text } from 'preact-i18n';
import DeviceFeatureState from './triggers/DeviceFeatureState';
import ScheduledTrigger from './triggers/ScheduledTrigger';
import ChooseTriggerType from './triggers/ChooseTriggerTypeCard';

import { EVENTS } from '../../../../../server/utils/constants';

const deleteTriggerFromList = (deleteTrigger, index) => () => {
deleteTrigger(index);
};

const TriggerCard = ({ children, ...props }) => (
<div class="card">
<div class="card-header">
{props.trigger.type === 'device.new-state' && <i class="fe fe-activity" />}
{props.trigger.type === EVENTS.DEVICE.NEW_STATE && <i class="fe fe-activity" />}
{props.trigger.type === EVENTS.TIME.CHANGED && <i class="fe fe-watch" />}
{props.trigger.type === null && <i class="fe fe-plus-circle" />}
<div class="card-title">
<i
Expand All @@ -37,13 +41,20 @@ const TriggerCard = ({ children, ...props }) => (
{props.trigger.type === null && (
<ChooseTriggerType updateTriggerProperty={props.updateTriggerProperty} index={props.index} />
)}
{props.trigger.type === 'device.new-state' && (
{props.trigger.type === EVENTS.DEVICE.NEW_STATE && (
<DeviceFeatureState
updateTriggerProperty={props.updateTriggerProperty}
index={props.index}
trigger={props.trigger}
/>
)}
{props.trigger.type === EVENTS.TIME.CHANGED && (
<ScheduledTrigger
updateTriggerProperty={props.updateTriggerProperty}
index={props.index}
trigger={props.trigger}
/>
)}
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Component } from 'preact';
import { connect } from 'unistore/preact';
import { Text } from 'preact-i18n';
const TRIGGER_LIST = ['device.new-state'];
import Select from 'react-select';

import { EVENTS } from '../../../../../../server/utils/constants';

const TRIGGER_LIST = [EVENTS.DEVICE.NEW_STATE, EVENTS.TIME.CHANGED];

@connect('httpClient', {})
class ChooseTriggerType extends Component {
state = {
Expand Down
Loading

0 comments on commit 1631d3c

Please sign in to comment.