Skip to content

Commit

Permalink
Merge gladys 4.48.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ngeissel committed Nov 7, 2024
2 parents 0b77be5 + 216f637 commit 5b500fa
Show file tree
Hide file tree
Showing 21 changed files with 328 additions and 57 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);
21 changes: 21 additions & 0 deletions front/src/config/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -2932,6 +2932,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 Expand Up @@ -2967,6 +2977,13 @@
"one": "Ja"
}
},
"input": {
"binary": {
"other": "Kein Wert empfangen",
"zero": "Aus",
"one": "An"
}
},
"risk": {
"integer": {
"no-risk": "Kein Risiko",
Expand Down Expand Up @@ -3273,6 +3290,10 @@
"shortCategoryName": "Risiko",
"integer": "Risikostufe"
},
"input": {
"shortCategoryName": "Eingang",
"binary": "Status des Eingangs"
},
"unknown": {
"shortCategoryName": "Unbekannt",
"unknown": "Unbekannt"
Expand Down
21 changes: 21 additions & 0 deletions front/src/config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2932,6 +2932,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 Expand Up @@ -2967,6 +2977,13 @@
"one": "Yes"
}
},
"input": {
"binary": {
"other": "No value received",
"zero": "Off",
"one": "On"
}
},
"risk": {
"integer": {
"no-risk": "No Risk",
Expand Down Expand Up @@ -3273,6 +3290,10 @@
"shortCategoryName": "Risk",
"integer": "Risk Level"
},
"input": {
"shortCategoryName": "Input",
"binary": "State of input"
},
"unknown": {
"shortCategoryName": "Unknown",
"unknown": "Unknown"
Expand Down
21 changes: 21 additions & 0 deletions front/src/config/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -2932,6 +2932,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 Expand Up @@ -2967,6 +2977,13 @@
"one": "Oui"
}
},
"input": {
"binary": {
"other": "Aucune valeur reçue",
"zero": "Off",
"one": "On"
}
},
"risk": {
"integer": {
"no-risk": "Pas de risque",
Expand Down Expand Up @@ -3273,6 +3290,10 @@
"shortCategoryName": "Risque",
"integer": "Niveau de risque"
},
"input": {
"shortCategoryName": "Entrée",
"binary": "Etat de l'entrée"
},
"unknown": {
"shortCategoryName": "Inconnu",
"unknown": "Inconnu"
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);
3 changes: 3 additions & 0 deletions front/src/utils/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,8 @@ export const DeviceFeatureCategoriesIcon = {
},
[DEVICE_FEATURE_CATEGORIES.RISK]: {
[DEVICE_FEATURE_TYPES.RISK.INTEGER]: 'alert-circle'
},
[DEVICE_FEATURE_CATEGORIES.INPUT]: {
[DEVICE_FEATURE_TYPES.INPUT.BINARY]: 'arrow-right'
}
};
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gladys",
"version": "4.47.0",
"version": "4.48.0",
"description": "A privacy-first, open-source home assistant",
"main": "index.js",
"engines": {
Expand Down
18 changes: 15 additions & 3 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,25 @@ const closeSQLite = async () => {
}
};

// Close properly all DuckDB connections & database
const closeDuckDB = async () => {
try {
await db.duckDb.close();
logger.info('DuckDB closed.');
return new Promise((resolve) => {
db.duckDbReadConnection.close((err1) => {
db.duckDbWriteConnection.close((err2) => {
db.duckDb.close((err3) => {
if (err1 || err2 || err3) {
logger.error(err1, err2, err3);
}
logger.info('DuckDB closed.');
resolve();
});
});
});
});
} catch (e) {
logger.info('DuckDB database is probably already closed');
logger.warn(e);
return null;
}
};

Expand Down
Loading

0 comments on commit 5b500fa

Please sign in to comment.