Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Pilot Wire Mode to scene #2149

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions front/src/components/device/SelectPilotWireMode.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Component } from 'preact';
import { Text } from 'preact-i18n';
import Select from 'react-select';
import get from 'get-value';

import { PILOT_WIRE_MODE } from '../../../../server/utils/constants';
import withIntlAsProp from '../../utils/withIntlAsProp';

class SelectPilotWireMode extends Component {
handleValueChange = ({ value }) => {
this.props.updateValue(value);
};

getOptions = () => {
const deviceFeatureOptions = Object.keys(PILOT_WIRE_MODE).map(key => {
const value = PILOT_WIRE_MODE[key];
return {
label: get(this.props.intl.dictionary, `deviceFeatureValue.category.heater.pilot-wire-mode.${value}`, {
default: value
}),
value
};
});

this.setState({ deviceFeatureOptions });
};

getSelectedOption = () => {
const value = this.props.value;

if (value !== undefined) {
return {
label: get(this.props.intl.dictionary, `deviceFeatureValue.category.heater.pilot-wire-mode.${value}`, {
default: value
}),
value
};
} else {
return;
}
};

componentDidMount() {
this.getOptions();
}

render(props, { deviceFeatureOptions }) {
const selectedOption = this.getSelectedOption();
return (
<Select
class="select-device-feature"
defaultValue={''}
value={selectedOption}
onChange={this.handleValueChange}
options={deviceFeatureOptions}
placeholder={<Text id="global.selectPlaceholder" />}
/>
);
}
}

export default withIntlAsProp(SelectPilotWireMode);
10 changes: 10 additions & 0 deletions front/src/config/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -2842,6 +2842,16 @@
"51": "Doppeltes Drücken"
}
},
"heater": {
"pilot-wire-mode": {
"0": "Aus",
"1": "Frostschutz",
"2": "Öko",
"3": "Komfort -1°C",
"4": "Komfort -2°C",
"5": "Komfort"
}
},
"opening-sensor": {
"binary": {
"other": "Kein Wert empfangen",
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 @@ -2842,6 +2842,16 @@
"51": "Double press"
}
},
"heater": {
"pilot-wire-mode": {
"0": "Off",
"1": "Frost Protection",
"2": "Eco",
"3": "Comfort -1°C",
"4": "Comfort -2°C",
"5": "Comfort"
}
},
"opening-sensor": {
"binary": {
"other": "No value received",
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 @@ -2842,6 +2842,16 @@
"51": "Pression double"
}
},
"heater": {
"pilot-wire-mode": {
"0": "Off",
"1": "Hors Gel",
"2": "Eco",
"3": "Confort -1°C",
"4": "Confort -2°C",
"5": "Confort"
}
},
"opening-sensor": {
"binary": {
"other": "Aucune valeur reçue",
Expand Down
12 changes: 12 additions & 0 deletions front/src/routes/scene/edit-scene/actions/DeviceSetValue.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import TextWithVariablesInjected from '../../../../components/scene/TextWithVari
import '../../../../components/boxs/device-in-room/device-features/style.css';
import style from './DeviceSetValue.css';
import ShutterButtons from '../../../../components/device/ShutterButtons';
import SelectPilotWireMode from '../../../../components/device/SelectPilotWireMode';

class DeviceSetValue extends Component {
constructor(props) {
Expand Down Expand Up @@ -144,6 +145,17 @@ class DeviceSetValue extends Component {
);
}

if (this.state.deviceFeature.type === DEVICE_FEATURE_TYPES.HEATER.PILOT_WIRE_MODE) {
return (
<SelectPilotWireMode
category={this.state.deviceFeature.category}
type={this.state.deviceFeature.type}
updateValue={this.handleNewPureValue}
value={this.props.action.value}
/>
);
}

return (
<div>
<div className={style.explanationText}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import PresenceSensorDeviceState from './device-states/PresenceSensorDeviceState
import ThresholdDeviceState from './device-states/ThresholdDeviceState';
import DefaultDeviceState from './device-states/DefaultDeviceState';
import ButtonClickDeviceState from './device-states/ButtonClickDeviceState';
import PilotWireModeDeviceState from './device-states/PilotWireModeDeviceState';

class TurnOnLight extends Component {
onDeviceFeatureChange = deviceFeature => {
Expand All @@ -27,17 +28,20 @@ class TurnOnLight extends Component {
let binaryDevice = false;
let presenceDevice = false;
let buttonClickDevice = false;
let pilotWireModeDevice = false;

if (selectedDeviceFeature) {
const { category, type } = selectedDeviceFeature;

binaryDevice = type === DEVICE_FEATURE_TYPES.SWITCH.BINARY;
presenceDevice = category === DEVICE_FEATURE_CATEGORIES.PRESENCE_SENSOR;
buttonClickDevice = category === DEVICE_FEATURE_CATEGORIES.BUTTON;
pilotWireModeDevice = category === DEVICE_FEATURE_CATEGORIES.HEATER;
}

const defaultDevice = selectedDeviceFeature && !binaryDevice && !presenceDevice && !buttonClickDevice;
const thresholdDevice = selectedDeviceFeature && !presenceDevice && !buttonClickDevice;
const defaultDevice =
selectedDeviceFeature && !binaryDevice && !presenceDevice && !buttonClickDevice && !pilotWireModeDevice;
const thresholdDevice = selectedDeviceFeature && !presenceDevice && !buttonClickDevice && !pilotWireModeDevice;

return (
<div>
Expand All @@ -53,6 +57,7 @@ class TurnOnLight extends Component {
{binaryDevice && <BinaryDeviceState {...props} selectedDeviceFeature={selectedDeviceFeature} />}
{presenceDevice && <PresenceSensorDeviceState {...props} />}
{buttonClickDevice && <ButtonClickDeviceState {...props} />}
{pilotWireModeDevice && <PilotWireModeDeviceState {...props} />}
{defaultDevice && <DefaultDeviceState {...props} selectedDeviceFeature={selectedDeviceFeature} />}
</div>
{thresholdDevice && <ThresholdDeviceState {...props} />}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Component, Fragment } from 'preact';
import Select from 'react-select';
import get from 'get-value';

import { PILOT_WIRE_MODE } from '../../../../../../../server/utils/constants';
import withIntlAsProp from '../../../../../utils/withIntlAsProp';

class PilotWireModeDeviceState extends Component {
handleValueChange = ({ value }) => {
this.props.updateTriggerProperty(this.props.index, 'value', value);
};

getOptions = () => {
const options = Object.keys(PILOT_WIRE_MODE).map(key => {
const value = PILOT_WIRE_MODE[key];
return {
label: get(this.props.intl.dictionary, `deviceFeatureValue.category.heater.pilot-wire-mode.${value}`, {
default: value
}),
value
};
});

this.setState({ options });
};

componentWillMount() {
this.props.updateTriggerProperty(this.props.index, 'operator', '=');

this.getOptions();
}

render({ trigger }, { options }) {
const defaultValue = options.find(option => trigger.value === option.value);

return (
<Fragment>
<div class="col-2 col-md-1">
<div class="text-center" style={{ marginTop: '10px' }}>
<i class="fe fe-arrow-right" style={{ fontSize: '20px' }} />
</div>
</div>
<div class="col-10 col-md-5">
<div class="form-group">
<Select defaultValue={defaultValue || ''} onChange={this.handleValueChange} options={options} />
</div>
</div>
</Fragment>
);
}
}

export default withIntlAsProp(PilotWireModeDeviceState);
Loading