Skip to content

Commit

Permalink
add new component to set pilot wire mode in scene
Browse files Browse the repository at this point in the history
  • Loading branch information
William-De71 committed Oct 30, 2024
1 parent b41977e commit c9e87df
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 12 deletions.
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
8 changes: 7 additions & 1 deletion 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 @@ -146,7 +147,12 @@ class DeviceSetValue extends Component {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class TurnOnLight extends Component {
pilotWireModeDevice = category === DEVICE_FEATURE_CATEGORIES.HEATER;
}

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

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,10 @@ class PilotWireModeDeviceState extends Component {
};

getOptions = () => {
const modeLabels = {
0: 'deviceFeatureAction.category.heater.pilot-wire-mode.off',
1: 'deviceFeatureAction.category.heater.pilot-wire-mode.frost-protection',
2: 'deviceFeatureAction.category.heater.pilot-wire-mode.eco',
3: 'deviceFeatureAction.category.heater.pilot-wire-mode.comfort_-1',
4: 'deviceFeatureAction.category.heater.pilot-wire-mode.comfort_-2',
5: 'deviceFeatureAction.category.heater.pilot-wire-mode.comfort'
};

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

0 comments on commit c9e87df

Please sign in to comment.