From d46ba5be12719c3f70fb6b007a07f7de911698e9 Mon Sep 17 00:00:00 2001 From: William Deren Date: Thu, 31 Oct 2024 10:10:20 +0100 Subject: [PATCH] Scene: Add Pilot Wire Mode in trigger & device set value action (#2149) --- .../components/device/SelectPilotWireMode.jsx | 62 +++++++++++++++++++ front/src/config/i18n/de.json | 10 +++ front/src/config/i18n/en.json | 10 +++ front/src/config/i18n/fr.json | 10 +++ .../edit-scene/actions/DeviceSetValue.jsx | 12 ++++ .../triggers/DeviceFeatureState.jsx | 9 ++- .../PilotWireModeDeviceState.jsx | 53 ++++++++++++++++ 7 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 front/src/components/device/SelectPilotWireMode.jsx create mode 100644 front/src/routes/scene/edit-scene/triggers/device-states/PilotWireModeDeviceState.jsx diff --git a/front/src/components/device/SelectPilotWireMode.jsx b/front/src/components/device/SelectPilotWireMode.jsx new file mode 100644 index 0000000000..3a3d8ecf3a --- /dev/null +++ b/front/src/components/device/SelectPilotWireMode.jsx @@ -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 ( + + + + + ); + } +} + +export default withIntlAsProp(PilotWireModeDeviceState);