Skip to content

Commit

Permalink
feat(z2m): Move pilot-wire-mode to select box
Browse files Browse the repository at this point in the history
  • Loading branch information
cicoub13 committed Aug 8, 2024
1 parent 5e2ca5d commit 794d0f9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
import get from 'get-value';
import { Text } from 'preact-i18n';
import cx from 'classnames';

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

const PilotWireModeDeviceFeature = ({ children, ...props }) => {
const { deviceFeature } = props;
const { category, type, last_value: lastValue } = deviceFeature;
const { category, type } = deviceFeature;

function updateValue(value) {
props.updateValueWithDebounce(deviceFeature, value);
}

function comfort() {
updateValue(PILOT_WIRE_MODE.COMFORT);
}

function eco() {
updateValue(PILOT_WIRE_MODE.ECO);
}

function frost_protection() {
updateValue(PILOT_WIRE_MODE.FROST_PROTECTION);
}

function off() {
updateValue(PILOT_WIRE_MODE.OFF);
function updateValue(e) {
props.updateValueWithDebounce(deviceFeature, e.currentTarget.value);
}

return (
Expand All @@ -37,43 +20,22 @@ const PilotWireModeDeviceFeature = ({ children, ...props }) => {
<td>{props.rowName}</td>

<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 === PILOT_WIRE_MODE.COMFORT
})}
onClick={comfort}
>
<Text id={`deviceFeatureAction.category.${category}.${type}.comfort`} plural={PILOT_WIRE_MODE.COMFORT} />
</button>
<button
class={cx('btn btn-sm btn-secondary', {
active: lastValue === PILOT_WIRE_MODE.ECO
})}
onClick={eco}
>
<Text id={`deviceFeatureAction.category.${category}.${type}.eco`} plural={PILOT_WIRE_MODE.ECO} />
</button>
<button
class={cx('btn btn-sm btn-secondary', {
active: lastValue === PILOT_WIRE_MODE.FROST_PROTECTION
})}
onClick={frost_protection}
>
<Text
id={`deviceFeatureAction.category.${category}.${type}.frost_protection`}
plural={PILOT_WIRE_MODE.FROST_PROTECTION}
/>
</button>
<button
class={cx('btn btn-sm', 'btn-secondary', {
active: lastValue === PILOT_WIRE_MODE.OFF
})}
onClick={off}
>
<Text id={`deviceFeatureAction.category.${category}.${type}.off`} plural={PILOT_WIRE_MODE.OFF} />
</button>
<div class="justify-content-end">
<div class="form-group mb-0">
<select value={props.deviceFeature.last_value} onChange={updateValue} class="form-control">
<option value={PILOT_WIRE_MODE.COMFORT}>
<Text id={`deviceFeatureAction.category.${category}.${type}.comfort`} />
</option>
<option value={PILOT_WIRE_MODE.ECO}>
<Text id={`deviceFeatureAction.category.${category}.${type}.eco`} />
</option>
<option value={PILOT_WIRE_MODE.FROST_PROTECTION}>
<Text id={`deviceFeatureAction.category.${category}.${type}.frost-protection`} />
</option>
<option value={PILOT_WIRE_MODE.OFF}>
<Text id={`deviceFeatureAction.category.${category}.${type}.off`} />
</option>
</select>
</div>
</div>
</td>
Expand Down
42 changes: 21 additions & 21 deletions front/src/config/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ const data = {
'main-presence-sensor',
'main-signal-sensor',
'air-conditioning',
'button-click',
'pilot-wire-mode'
'button-click'
]
}
],
Expand All @@ -188,7 +187,8 @@ const data = {
'thermostat',
'water-leak',
'smoke-sensor',
'light-sensor'
'light-sensor',
'pilot-wire-mode'
]
}
]
Expand Down Expand Up @@ -2643,7 +2643,7 @@ const data = {
]
}
],
'get /api/v1/device?device_feature_selectors=main-tv-binary,main-tv-volume,main-tv-channel,main-presence-sensor,main-signal-sensor,air-conditioning,button-click,pilot-wire-mode': [
'get /api/v1/device?device_feature_selectors=main-tv-binary,main-tv-volume,main-tv-channel,main-presence-sensor,main-signal-sensor,air-conditioning,button-click': [
{
id: '20deebe6-57df-4940-afd1-11c189a407c2',
name: 'TV',
Expand Down Expand Up @@ -2886,25 +2886,9 @@ const data = {
unit: 'celsius'
}
]
},
{
id: 'db3e81b6-00d4-4f9b-8aa6-0e50e719a729',
name: 'Heater',
selector: 'pilot-wire-mode',
features: [
{
name: 'Pilot Wire mode',
selector: 'pilot-wire-mode',
category: 'heater',
type: 'pilot-wire-mode',
read_only: false,
last_value: 'off',
last_value_changed: '2022-10-10 07:49:07.556 +00:00'
}
]
}
],
'get /api/v1/device?device_feature_selectors=curtain-actions,shutter-actions,shutter-position,thermostat,water-leak,smoke-sensor,light-sensor': [
'get /api/v1/device?device_feature_selectors=curtain-actions,shutter-actions,shutter-position,thermostat,water-leak,smoke-sensor,light-sensor,pilot-wire-mode': [
{
id: 'f131fbf2-445a-4c2c-9426-83abaf534662',
name: 'Room sensors',
Expand Down Expand Up @@ -3022,6 +3006,22 @@ const data = {
unit: 'celsius'
}
]
},
{
id: 'db3e81b6-00d4-4f9b-8aa6-0e50e719a729',
name: 'Chauffage Salon',
selector: 'pilot-wire-mode',
features: [
{
name: 'Pilot Wire mode',
selector: 'pilot-wire-mode',
category: 'heater',
type: 'pilot-wire-mode',
read_only: false,
last_value: 'frost-protection',
last_value_changed: '2022-10-10 07:49:07.556 +00:00'
}
]
}
],
'get /api/v1/device?device_feature_selectors=main-lamp-binary,tv-lamp-binary,tv-lamp-color,tv-lamp-brightness,mqtt-living-room-switch,mqtt-living-room-dimmer,mqtt-living-room-temp,co-living-room': [
Expand Down
4 changes: 2 additions & 2 deletions front/src/config/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -2734,10 +2734,10 @@
},
"heater": {
"pilot-wire-mode": {
"comfort": "Komf.",
"comfort": "Komfort",
"eco": "Öko",
"off": "Aus",
"frost_protection": "Frostschutzmittel"
"frost-protection": "Frostschutzmittel"
}
},
"siren": {
Expand Down
4 changes: 2 additions & 2 deletions front/src/config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2734,10 +2734,10 @@
},
"heater": {
"pilot-wire-mode": {
"comfort": "Comf.",
"comfort": "Comfort",
"eco": "Eco",
"off": "Off",
"frost_protection": "Anti-Frost"
"frost-protection": "Anti-Frost"
}
},
"siren": {
Expand Down
4 changes: 2 additions & 2 deletions front/src/config/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -2734,10 +2734,10 @@
},
"heater": {
"pilot-wire-mode": {
"comfort": "Conf.",
"comfort": "Confort",
"eco": "Eco",
"off": "Off",
"frost_protection": "Anti Gel"
"frost-protection": "Anti Gel"
}
},
"siren": {
Expand Down

0 comments on commit 794d0f9

Please sign in to comment.