diff --git a/front/src/config/i18n/en.json b/front/src/config/i18n/en.json index 825a95f34b..f677766589 100644 --- a/front/src/config/i18n/en.json +++ b/front/src/config/i18n/en.json @@ -881,7 +881,7 @@ "notFound": "Requested device not found.", "backToList": "Back to device list", "saveError": "Error saving or deleting device", - "saveConflictError": "Conflict: Are you sure all device feature external IDs are unique?", + "saveConflictError": "Conflict: Are you sure all external IDs are unique?", "mostRecentValueAt": "Last value received {{mostRecentValueAt}}.", "noValueReceived": "No value received." }, diff --git a/front/src/config/i18n/fr.json b/front/src/config/i18n/fr.json index 8acf80059b..16052f2189 100644 --- a/front/src/config/i18n/fr.json +++ b/front/src/config/i18n/fr.json @@ -1009,7 +1009,7 @@ "notFound": "Appareil introuvable.", "backToList": "Retour à la liste des appareils", "saveError": "Erreur lors de l'enregistrement ou de la suppression de l'appareil", - "saveConflictError": "Conflit : êtes-vous sûr que tous les IDs externes des fonctionnalités de l'appareil sont uniques ?", + "saveConflictError": "Conflit : êtes-vous sûr que tous les IDs externes sont uniques ?", "mostRecentValueAt": "Dernière valeur reçue {{mostRecentValueAt}}.", "noValueReceived": "Aucune valeur reçue." }, diff --git a/front/src/routes/integration/all/mqtt/device-page/setup/index.js b/front/src/routes/integration/all/mqtt/device-page/setup/index.js index 11bebc459d..583fa58f5c 100644 --- a/front/src/routes/integration/all/mqtt/device-page/setup/index.js +++ b/front/src/routes/integration/all/mqtt/device-page/setup/index.js @@ -7,6 +7,7 @@ import uuid from 'uuid'; import get from 'get-value'; import update from 'immutability-helper'; import { RequestStatus } from '../../../../../../utils/consts'; +import { slugify } from '../../../../../../../../server/utils/slugify'; import withIntlAsProp from '../../../../../../utils/withIntlAsProp'; import { DEVICE_FEATURE_CATEGORIES, DEVICE_FEATURE_TYPES } from '../../../../../../../../server/utils/constants'; @@ -147,6 +148,20 @@ class MqttDeviceSetupPage extends Component { loading: true }); try { + // If we are creating a device, we check that the device doesn't already exist + if (!this.state.device.id) { + try { + await this.props.httpClient.get(`/api/v1/device/${slugify(this.state.device.selector)}`); + // if we are here, it means the device already exist + this.setState({ + saveStatus: RequestStatus.ConflictError, + loading: false + }); + return; + } catch (e) { + // If we are here, it's ok, it means the device does not exist yet + } + } const device = await this.props.httpClient.post('/api/v1/device', this.state.device); this.setState({ saveStatus: RequestStatus.Success, @@ -223,10 +238,8 @@ class MqttDeviceSetupPage extends Component { let device; if (!deviceSelector) { - const uniqueId = uuid.v4(); device = { - id: uniqueId, - name: null, + name: '', should_poll: false, external_id: 'mqtt:', service_id: this.props.currentIntegration.id,