Skip to content

Commit

Permalink
Dashboard: Add push button feature (GladysAssistant#2165)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles authored Nov 11, 2024
1 parent 2540927 commit 68cdb6c
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 9 deletions.
4 changes: 3 additions & 1 deletion front/src/components/boxs/device-in-room/DeviceRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ThermostatDeviceFeature from './device-features/ThermostatDeviceFeature';
import AirConditioningModeDeviceFeature from './device-features/AirConditioningModeDeviceFeature';
import PilotWireModeDeviceFeature from './device-features/PilotWireModeDeviceFeature';
import LMHVolumeDeviceFeature from './device-features/LMHVolumeDeviceFeature';
import PushDeviceFeature from './device-features/PushDeviceFeature';

const ROW_TYPE_BY_FEATURE_TYPE = {
[DEVICE_FEATURE_TYPES.LIGHT.BINARY]: BinaryDeviceFeature,
Expand All @@ -33,7 +34,8 @@ const ROW_TYPE_BY_FEATURE_TYPE = {
[DEVICE_FEATURE_TYPES.HEATER.PILOT_WIRE_MODE]: PilotWireModeDeviceFeature,
[DEVICE_FEATURE_TYPES.SIREN.LMH_VOLUME]: LMHVolumeDeviceFeature,
[DEVICE_FEATURE_TYPES.SIREN.MELODY]: NumberDeviceFeature,
[DEVICE_FEATURE_TYPES.DURATION.DECIMAL]: MultiLevelDeviceFeature
[DEVICE_FEATURE_TYPES.DURATION.DECIMAL]: MultiLevelDeviceFeature,
[DEVICE_FEATURE_TYPES.BUTTON.PUSH]: PushDeviceFeature
};

const DeviceRow = ({ children, ...props }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const SUPPORTED_FEATURE_TYPES = [
DEVICE_FEATURE_TYPES.HEATER.PILOT_WIRE_MODE,
DEVICE_FEATURE_TYPES.SIREN.LMH_VOLUME,
DEVICE_FEATURE_TYPES.SIREN.MELODY,
DEVICE_FEATURE_TYPES.DURATION.DECIMAL
DEVICE_FEATURE_TYPES.DURATION.DECIMAL,
DEVICE_FEATURE_TYPES.BUTTON.PUSH
];

export default SUPPORTED_FEATURE_TYPES;
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Component } from 'preact';
import cx from 'classnames';
import { Text } from 'preact-i18n';
import style from './style.css';

class PushDeviceComponent extends Component {
constructor(props) {
super(props);
this.state = {
loading: false
};
}
push = async () => {
await this.setState({ loading: true });
this.props.updateValue(this.props.deviceFeature, 1);
setTimeout(() => {
this.setState({ loading: false });
}, 350);
};

render(props, { loading }) {
return (
<tr>
<td>
<i class="fe fe-circle" />
</td>
<td>{props.rowName}</td>
<td class="text-right">
<button
onClick={this.push}
type="button"
class={cx('btn', 'btn-outline-success', 'btn-sm', style.btnLoading, {
'btn-loading': loading
})}
>
<i class="fe fe-circle" /> <Text id="dashboard.boxes.devicesInRoom.pushButton" />
</button>
</td>
</tr>
);
}
}

export default PushDeviceComponent;
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ input[type='range'][class~='light-temperature']::-ms-fill-lower {
display: none;
}
}

.btnLoading {
&::after {
border: 2px solid #5eba00;
}
}
6 changes: 4 additions & 2 deletions front/src/config/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@
"deviceTitle": "{{name}} - {{type}}",
"addButton": "+",
"substractButton": "-",
"motionDetected": "Bewegung erkannt"
"motionDetected": "Bewegung erkannt",
"pushButton": "Schieben"
},
"devices": {
"editDeviceFeaturesLabel": "Wähle die Geräte aus, die du anzeigen möchtest:",
Expand Down Expand Up @@ -3017,7 +3018,8 @@
},
"button": {
"shortCategoryName": "Schaltfläche",
"click": "Schaltfläche (Klick)"
"click": "Schaltfläche (Klick)",
"push": "Druckknopf"
},
"pressure-sensor": {
"shortCategoryName": "Drucksensor",
Expand Down
6 changes: 4 additions & 2 deletions front/src/config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@
"deviceTitle": "{{name}} - {{type}}",
"addButton": "+",
"substractButton": "-",
"motionDetected": "Motion detected"
"motionDetected": "Motion detected",
"pushButton": "Push"
},
"devices": {
"editDeviceFeaturesLabel": "Select the devices you want to display:",
Expand Down Expand Up @@ -3017,7 +3018,8 @@
},
"button": {
"shortCategoryName": "Button",
"click": "Button (click)"
"click": "Button (click)",
"push": "Push button"
},
"pressure-sensor": {
"shortCategoryName": "Pressure sensor",
Expand Down
6 changes: 4 additions & 2 deletions front/src/config/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@
"deviceTitle": "{{name}} - {{type}}",
"addButton": "+",
"substractButton": "-",
"motionDetected": "Mouvement détecté"
"motionDetected": "Mouvement détecté",
"pushButton": "Appuyer"
},
"devices": {
"editDeviceFeaturesLabel": "Vous pouvez modifier le nom affiché ici :",
Expand Down Expand Up @@ -3017,7 +3018,8 @@
},
"button": {
"shortCategoryName": "Bouton",
"click": "Clic bouton"
"click": "Clic bouton",
"push": "Bouton poussoir"
},
"pressure-sensor": {
"shortCategoryName": "Capteur de pression",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class MqttDeviceSetupPage extends Component {
defaultValues.keep_history = false;
}

if (featureData[1] === DEVICE_FEATURE_TYPES.BUTTON.PUSH) {
defaultValues.min = 1;
defaultValues.max = 1;
defaultValues.read_only = false;
}

const device = update(this.state.device, {
features: {
$push: [
Expand Down
3 changes: 2 additions & 1 deletion front/src/utils/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ export const DeviceFeatureCategoriesIcon = {
[DEVICE_FEATURE_TYPES.CUBE.ROTATION]: 'rotate-cw'
},
[DEVICE_FEATURE_CATEGORIES.BUTTON]: {
[DEVICE_FEATURE_TYPES.BUTTON.CLICK]: 'circle'
[DEVICE_FEATURE_TYPES.BUTTON.CLICK]: 'circle',
[DEVICE_FEATURE_TYPES.BUTTON.PUSH]: 'circle'
},
[DEVICE_FEATURE_CATEGORIES.ENERGY_SENSOR]: {
[DEVICE_FEATURE_TYPES.ENERGY_SENSOR.BINARY]: 'power',
Expand Down
1 change: 1 addition & 0 deletions server/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ const DEVICE_FEATURE_TYPES = {
},
BUTTON: {
CLICK: 'click',
PUSH: 'push',
},
SIGNAL: {
QUALITY: 'integer',
Expand Down

0 comments on commit 68cdb6c

Please sign in to comment.