Skip to content

Commit

Permalink
Scene: Add shutter value selector to control device action (#2085)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles authored May 20, 2024
1 parent 10287b5 commit 09a7987
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import get from 'get-value';
import { Text } from 'preact-i18n';
import cx from 'classnames';

import { DeviceFeatureCategoriesIcon } from '../../../../utils/consts';
import { COVER_STATE } from '../../../../../../server/utils/constants';
import ShutterButtons from '../../../device/ShutterButtons';

const CoverDeviceFeature = ({ children, ...props }) => {
const { deviceFeature } = props;
Expand All @@ -13,18 +10,6 @@ const CoverDeviceFeature = ({ children, ...props }) => {
props.updateValueWithDebounce(deviceFeature, value);
}

function open() {
updateValue(COVER_STATE.OPEN);
}

function close() {
updateValue(COVER_STATE.CLOSE);
}

function stop() {
updateValue(COVER_STATE.STOP);
}

return (
<tr>
<td>
Expand All @@ -34,30 +19,7 @@ const CoverDeviceFeature = ({ children, ...props }) => {

<td class="py-0">
<div class="d-flex justify-content-end">
<div class="btn-group" role="group">
<button
class={cx('btn btn-sm btn-secondary', {
active: lastValue === COVER_STATE.OPEN
})}
onClick={open}
>
<Text id={`deviceFeatureAction.category.${category}.${type}`} plural={COVER_STATE.OPEN} />
</button>
<button
class={cx('btn btn-sm btn-secondary', 'fe', 'fe-pause', {
active: lastValue === COVER_STATE.STOP
})}
onClick={stop}
/>
<button
class={cx('btn btn-sm', 'btn-secondary', {
active: lastValue === COVER_STATE.CLOSE
})}
onClick={close}
>
<Text id={`deviceFeatureAction.category.${category}.${type}`} plural={COVER_STATE.CLOSE} />
</button>
</div>
<ShutterButtons category={category} type={type} updateValue={updateValue} value={lastValue} isLive />
</div>
</td>
</tr>
Expand Down
58 changes: 58 additions & 0 deletions front/src/components/device/ShutterButtons.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Component } from 'preact';
import { Text } from 'preact-i18n';
import cx from 'classnames';

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

class ShutterButtons extends Component {
open = () => {
this.props.updateValue(COVER_STATE.OPEN);
};

close = () => {
this.props.updateValue(COVER_STATE.CLOSE);
};

stop = () => {
this.props.updateValue(COVER_STATE.STOP);
};

render({ value, category, type, isLive = false }, {}) {
return (
<div class="btn-group" role="group">
<button
class={cx('btn btn-sm btn-secondary', {
active: value === COVER_STATE.OPEN
})}
onClick={this.open}
>
{value === COVER_STATE.OPEN && isLive ? (
<Text id={`deviceFeatureAction.category.${category}.stateLiveFinished`} plural={COVER_STATE.OPEN} />
) : (
<Text id={`deviceFeatureAction.category.${category}.${type}`} plural={COVER_STATE.OPEN} />
)}
</button>
<button
class={cx('btn btn-sm btn-secondary', 'fe', 'fe-pause', {
active: value === COVER_STATE.STOP
})}
onClick={this.stop}
/>
<button
class={cx('btn btn-sm', 'btn-secondary', {
active: value === COVER_STATE.CLOSE
})}
onClick={this.close}
>
{value === COVER_STATE.CLOSE && isLive ? (
<Text id={`deviceFeatureAction.category.${category}.stateLiveFinished`} plural={COVER_STATE.CLOSE} />
) : (
<Text id={`deviceFeatureAction.category.${category}.${type}`} plural={COVER_STATE.CLOSE} />
)}
</button>
</div>
);
}
}

export default ShutterButtons;
10 changes: 10 additions & 0 deletions front/src/config/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -2667,13 +2667,23 @@
"deviceFeatureAction": {
"category": {
"shutter": {
"stateLiveFinished": {
"zero": "Stoppen",
"one": "Offen",
"other": "Geschlossen"
},
"state": {
"zero": "Stopp",
"one": "Öffnen",
"other": "Schließen"
}
},
"curtain": {
"stateLiveFinished": {
"zero": "Stoppen",
"one": "Offen",
"other": "Geschlossen"
},
"state": {
"zero": "Stopp",
"one": "Öffnen",
Expand Down
10 changes: 10 additions & 0 deletions front/src/config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2667,13 +2667,23 @@
"deviceFeatureAction": {
"category": {
"shutter": {
"stateLiveFinished": {
"zero": "Stop",
"one": "Open",
"other": "Closed"
},
"state": {
"zero": "Stop",
"one": "Open",
"other": "Close"
}
},
"curtain": {
"stateLiveFinished": {
"zero": "Stop",
"one": "Open",
"other": "Closed"
},
"state": {
"zero": "Stop",
"one": "Open",
Expand Down
10 changes: 10 additions & 0 deletions front/src/config/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -2667,13 +2667,23 @@
"deviceFeatureAction": {
"category": {
"shutter": {
"stateLiveFinished": {
"zero": "Arrêter",
"one": "Ouvert",
"other": "Fermé"
},
"state": {
"zero": "Arrêter",
"one": "Ouvrir",
"other": "Fermer"
}
},
"curtain": {
"stateLiveFinished": {
"zero": "Arrêter",
"one": "Ouvert",
"other": "Fermé"
},
"state": {
"zero": "Arrêter",
"one": "Ouvrir",
Expand Down
25 changes: 21 additions & 4 deletions front/src/routes/scene/edit-scene/actions/DeviceSetValue.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import ColorPicker from '../../../../components/device/ColorPicker';
import SelectDeviceFeature from '../../../../components/device/SelectDeviceFeature';
import withIntlAsProp from '../../../../utils/withIntlAsProp';

import { DEVICE_FEATURE_TYPES } from '../../../../../../server/utils/constants';
import { DEVICE_FEATURE_CATEGORIES, DEVICE_FEATURE_TYPES } from '../../../../../../server/utils/constants';
import TextWithVariablesInjected from '../../../../components/scene/TextWithVariablesInjected';

import '../../../../components/boxs/device-in-room/device-features/style.css';
import style from './DeviceSetValue.css';
import ShutterButtons from '../../../../components/device/ShutterButtons';

class DeviceSetValue extends Component {
constructor(props) {
Expand Down Expand Up @@ -50,9 +51,9 @@ class DeviceSetValue extends Component {
this.props.updateActionProperty(columnIndex, index, 'evaluate_value', undefined);
};

handleNewColorValue = color => {
handleNewPureValue = value => {
const { columnIndex, index } = this.props;
this.props.updateActionProperty(columnIndex, index, 'value', color);
this.props.updateActionProperty(columnIndex, index, 'value', value);
this.props.updateActionProperty(columnIndex, index, 'evaluate_value', undefined);
};

Expand Down Expand Up @@ -124,7 +125,23 @@ class DeviceSetValue extends Component {
}

if (this.state.deviceFeature.type === DEVICE_FEATURE_TYPES.LIGHT.COLOR) {
return <ColorPicker value={this.props.action.value} updateValue={this.handleNewColorValue} />;
return <ColorPicker value={this.props.action.value} updateValue={this.handleNewPureValue} />;
}

if (
[DEVICE_FEATURE_TYPES.SHUTTER.STATE, DEVICE_FEATURE_TYPES.CURTAIN.STATE].includes(
this.state.deviceFeature.type
) &&
[DEVICE_FEATURE_CATEGORIES.SHUTTER, DEVICE_FEATURE_CATEGORIES.CURTAIN].includes(this.state.deviceFeature.category)
) {
return (
<ShutterButtons
value={this.props.action.value}
category={this.state.deviceFeature.category}
type={this.state.deviceFeature.type}
updateValue={this.handleNewPureValue}
/>
);
}

return (
Expand Down

0 comments on commit 09a7987

Please sign in to comment.