Skip to content

Commit

Permalink
ZwaveJS UI: Display Zwave location in configuration UI (GladysAssista…
Browse files Browse the repository at this point in the history
  • Loading branch information
William-De71 authored Feb 26, 2024
1 parent dd35b83 commit ce947cf
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions front/src/config/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@
"discoverDeviceDescr": "Automatisches Scannen der Z-Wave JS UI Geräte",
"nameLabel": "Gerätename",
"namePlaceholder": "Geben Sie den Namen Ihres Geräts ein",
"locationLabel": "Gerätestandort",
"noFeaturesHandled": "Dieses Gerät wird noch nicht von Gladys unterstützt. Bitte reichen Sie es ein, damit es hinzugefügt werden kann!",
"featuresLabel": "Funktionen",
"roomLabel": "Raum",
Expand Down
1 change: 1 addition & 0 deletions front/src/config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@
"discoverDeviceDescr": "Automatically scan for Z-Wave JS UI devices",
"nameLabel": "Device Name",
"namePlaceholder": "Enter your device name",
"locationLabel": "Device Location",
"noFeaturesHandled": "This device is not yet supported by Gladys; feel free to submit it for inclusion!",
"featuresLabel": "Features",
"roomLabel": "Room",
Expand Down
1 change: 1 addition & 0 deletions front/src/config/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,7 @@
"discoverDeviceDescr": "Scanner automatiquement les appareils Z-Wave JS UI",
"nameLabel": "Nom de l'appareil",
"namePlaceholder": "Entrez le nom de votre appareil",
"locationLabel": "Emplacement de l'appareil",
"noFeaturesHandled": "Cet appareil n'est pas encore géré par Gladys, n'hésitez pas à nous le soumettre pour qu'il soit ajouté !",
"featuresLabel": "Fonctionnalités",
"roomLabel": "Pièce",
Expand Down
32 changes: 32 additions & 0 deletions front/src/routes/integration/all/zwavejs-ui/ZwaveJSUIDeviceBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cx from 'classnames';
import get from 'get-value';

import DeviceFeatures from '../../../../components/device/view/DeviceFeatures';
import { PARAMS } from '../../../../../../server/services/zwavejs-ui/lib/constants';

import { connect } from 'unistore/preact';

Expand Down Expand Up @@ -95,11 +96,27 @@ class ZwaveJSUIDeviceBox extends Component {
});
};

getDeviceProperty = () => {
const device = this.state.device;
if (!device.features) {
return null;
}

let locationZwaveUi = null;
const locationZwaveUiParam = device.params.find(param => param.name === PARAMS.LOCATION);
if (locationZwaveUiParam) {
locationZwaveUi = locationZwaveUiParam.value;
}

return { locationZwaveUi };
};

render(
{ deviceIndex, editable, deleteButton, housesWithRooms },
{ device, loading, errorMessage, tooMuchStatesError, statesNumber }
) {
const validModel = device.features && device.features.length > 0;
const { locationZwaveUi } = this.getDeviceProperty();

return (
<div class="col-md-6">
Expand Down Expand Up @@ -140,6 +157,21 @@ class ZwaveJSUIDeviceBox extends Component {
</Localizer>
</div>

{locationZwaveUi && (
<div class="form-group">
<label class="form-label" for={`location_${deviceIndex}`}>
<Text id="integration.zwavejs-ui.locationLabel" />
</label>
<input
id={`location_${deviceIndex}`}
type="text"
value={locationZwaveUi}
class="form-control"
disabled="true"
/>
</div>
)}

{housesWithRooms && (
<div class="form-group">
<label class="form-label" for={`room_${deviceIndex}`}>
Expand Down
5 changes: 5 additions & 0 deletions server/services/zwavejs-ui/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const CONFIGURATION = {
ZWAVEJS_UI_MQTT_PASSWORD_KEY: 'ZWAVEJS_UI_MQTT_PASSWORD',
};

const PARAMS = {
LOCATION: `location`,
};

/**
* Convert a zWave value format to the
* Gladys format.
Expand Down Expand Up @@ -125,4 +129,5 @@ module.exports = {
CONFIGURATION,
EXPOSES,
STATES,
PARAMS,
};
5 changes: 4 additions & 1 deletion server/services/zwavejs-ui/utils/convertToGladysDevice.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const get = require('get-value');

const { EXPOSES } = require('../lib/constants');
const { EXPOSES, PARAMS } = require('../lib/constants');

const cleanNames = (text) => {
if (!text || typeof text !== 'string') {
Expand All @@ -22,6 +22,7 @@ const getDeviceFeatureId = (nodeId, commandClassName, endpoint, propertyName, pr

const convertToGladysDevice = (serviceId, device) => {
const features = [];
let params = [];

// Foreach value, we check if there is a matching feature in Gladys
Object.keys(device.values).forEach((valueKey) => {
Expand Down Expand Up @@ -51,6 +52,7 @@ const convertToGladysDevice = (serviceId, device) => {
property_key_name: propertyKeyName,
});
}
params = [{ name: PARAMS.LOCATION, value: device.loc }];
});

return {
Expand All @@ -60,6 +62,7 @@ const convertToGladysDevice = (serviceId, device) => {
service_id: serviceId,
should_poll: false,
features,
params,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ describe('zwaveJSUIHandler.onNewDeviceDiscover.js', () => {
property_key_name: 'Door state (simple)',
},
],
params: [
{
name: `location`,
value: `salon`,
},
],
},
]);
});
Expand Down

0 comments on commit ce947cf

Please sign in to comment.