Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ewelink websocket #1977

Closed
wants to merge 11 commits into from
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions front/src/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ import EweLinkPage from '../routes/integration/all/ewelink/device-page';
import EweLinkEditPage from '../routes/integration/all/ewelink/edit-page';
import EweLinkDiscoverPage from '../routes/integration/all/ewelink/discover-page';
import EweLinkSetupPage from '../routes/integration/all/ewelink/setup-page';
import EweLinkSetupLoginPage from '../routes/integration/all/ewelink/setup-page/login';

// OpenAI integration
import OpenAIPage from '../routes/integration/all/openai/index';
Expand Down Expand Up @@ -281,6 +282,7 @@ const AppRouter = connect(
<EweLinkEditPage path="/dashboard/integration/device/ewelink/edit/:deviceSelector" />
<EweLinkDiscoverPage path="/dashboard/integration/device/ewelink/discover" />
<EweLinkSetupPage path="/dashboard/integration/device/ewelink/setup" />
<EweLinkSetupLoginPage path="/dashboard/integration/device/ewelink/setup/login" />
<HomeKitPage path="/dashboard/integration/communication/homekit" />
<OpenAIPage path="/dashboard/integration/communication/openai" />

Expand Down
3 changes: 2 additions & 1 deletion front/src/components/header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const PAGES_WITHOUT_HEADER = [
'/confirm-email',
'/dashboard/integration/device/google-home/authorize',
'/dashboard/integration/device/alexa/authorize',
'/locked'
'/locked',
'/dashboard/integration/device/ewelink/setup/login'
];

const Header = ({ ...props }) => {
Expand Down
15 changes: 15 additions & 0 deletions front/src/config/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3752,6 +3752,21 @@ const data = {
]
}
],
'get /api/v1/service/ewelink/status': {
configured: true,
connected: true
},
'get /api/v1/service/ewelink/config': {
application_id: 'ewelink_APPID',
application_secret: 'ewelink_APP_SECRET',
application_region: 'eu'
},
'post /api/v1/service/ewelink/config': {
application_id: 'ewelink_APPID',
application_secret: 'ewelink_APP_SECRET',
application_region: 'eu'
},
'post /api/v1/service/ewelink/token': {},
'get /api/v1/service/tp-link': {
id: 'c9fe2705-35dc-417b-b6fc-c4bbb9c69886',
pod_id: null,
Expand Down
33 changes: 23 additions & 10 deletions front/src/config/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"degreeValue": "{{value}}°",
"workInProgress": "In Arbeit …",
"save": "Sichern",
"edit": "Bearbeiten",
"cancel": "Abbrechen",
"celsius": "C",
"fahrenheit": "F",
"metersPerSec": "m/s",
Expand Down Expand Up @@ -1582,16 +1584,27 @@
"setup": {
"title": "eWeLink-Einrichtung",
"eweLinkDescription": "Du kannst Gladys mit deinem eWeLink-Cloud-Account verbinden, um die zugehörigen Geräte zu steuern.",
"userLabel": "Benutzername",
"userPlaceholder": "eWeLink-Benutzernamen eingeben",
"passwordLabel": "Passwort",
"passwordPlaceholder": "eWeLink-Passwort eingeben",
"saveLabel": "Konfiguration sichern",
"error": "Beim Sichern der Konfiguration ist ein Fehler aufgetreten.",
"connecting": "Konfiguration gesichert. Die Verbindung mit deinem eWeLink-Cloud-Account wird jetzt aufgebaut …",
"connected": "Erfolgreich mit dem eWeLink-Cloud-Account verbunden!",
"connectionError": "Verbinden fehlgeschlagen. Überprüfe deine Konfiguration.",
"ewelinkIntegrationDeprecated": "September 2023: Leider scheint diese Integration aufgrund von Änderungen an der eWeLink-API nicht mehr zu funktionieren."
"applicationSetupLabel": "eWeLink-Anwendung einrichten",
"applicationIdLabel": "Anwendungskennzeichen (APPID)",
"applicationIdPlaceholder": "APPID-Wert eingeben",
"applicationSecretLabel": "Bewerbung Geheim (APP SECRET)",
"applicationSecretPlaceholder": "APP SECRET-Wert eingeben",
"applicationRegionLabel": "Region",
"userConnectedLabel": "Verbunden",
"userNotConnectedLabel": "Kein Benutzer verbunden",
"connectLabel": "Verbinden Sie",
"disconnectLabel": "Trennen Sie die Verbindung",
"loadStatusError": "Beim Abrufen des eWeLink-Integrationsstatus ist ein Fehler aufgetreten. Gladys ist möglicherweise nicht erreichbar.",
"saveConfigError": "Die Konfiguration der eWeLink-Anwendung kann nicht gespeichert werden. Gladys ist möglicherweise nicht erreichbar.",
"loginRedirectError": "Bei der Verbindung zu eWeLink ist ein Fehler aufgetreten. Bitte kontaktieren Sie Gladys Community.",
"exchangeTokenError": "Beim Verbindungsaufbau zum Austausch des eWeLink-Benutzer-Tokens ist ein Fehler aufgetreten. Bitte wenden Sie sich an die Gladys Community.",
"exchangeTokenSuccess": "Authentifizierung erfolgreich, aktuelle Registerkarte kann geschlossen werden.",
"regions": {
"cn": "Festland China",
"as": "Asien",
"us": "Amerikas",
"eu": "Europa"
}
},
"error": {
"defaultError": "Beim Sichern des Geräts ist ein Fehler aufgetreten.",
Expand Down
33 changes: 23 additions & 10 deletions front/src/config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"degreeValue": "{{value}}°",
"workInProgress": "Work in progress...",
"save": "Save",
"edit": "Edit",
"cancel": "Cancel",
"celsius": "C",
"fahrenheit": "F",
"metersPerSec": "m/s",
Expand Down Expand Up @@ -1584,16 +1586,27 @@
"setup": {
"title": "eWeLink configuration",
"eweLinkDescription": "You can connect Gladys to your eWeLink cloud account to command the associated devices.",
"userLabel": "Username",
"userPlaceholder": "Enter eWeLink username",
"passwordLabel": "Password",
"passwordPlaceholder": "Enter eWeLink password",
"saveLabel": "Save configuration",
"error": "An error occured while saving configuration.",
"connecting": "Configuration saved. Now connecting to your eWeLink cloud account...",
"connected": "Connected to the eWeLink cloud account with success !",
"connectionError": "Error while connecting, please check your configuration.",
"ewelinkIntegrationDeprecated": "September 2023: Unfortunately, this integration no longer seems to work due to changes in the eWeLink API."
"applicationSetupLabel": "eWeLink application setup",
"applicationIdLabel": "Application Identifier (APPID)",
"applicationIdPlaceholder": "Enter APPID value",
"applicationSecretLabel": "Application Secret (APP SECRET)",
"applicationSecretPlaceholder": "Enter APP SECRET value",
"applicationRegionLabel": "Region",
"userConnectedLabel": "Connected",
"userNotConnectedLabel": "No user connected",
"connectLabel": "Connect",
"disconnectLabel": "Disconnect",
"loadStatusError": "An error occured while fetching eWeLink integration status. Gladys may be not reachable.",
"saveConfigError": "Unable to save eWeLink application configuration. Gladys may be not reachable.",
"loginRedirectError": "An error occured while connecting to eWeLink, please contact Gladys community.",
"exchangeTokenError": "An error occured while connecting to exchanging eWeLink user token, please contact Gladys community.",
"exchangeTokenSuccess": "Authentication succeed, current tab can be closed.",
"regions": {
"cn": "Mainland China",
"as": "Asia",
"us": "Americas",
"eu": "Europe"
}
},
"error": {
"defaultError": "There was an error saving the device.",
Expand Down
33 changes: 23 additions & 10 deletions front/src/config/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"degreeValue": "{{value}}°",
"workInProgress": "Travail en cours...",
"save": "Enregistrer",
"edit": "Modifier",
"cancel": "Annuler",
"celsius": "C",
"fahrenheit": "F",
"metersPerSec": "m/s",
Expand Down Expand Up @@ -1586,16 +1588,27 @@
"setup": {
"title": "Configuration eWeLink",
"eweLinkDescription": "Vous pouvez connecter Gladys à votre compte cloud eWeLink pour commander les appareils associés.",
"userLabel": "Nom d'utilisateur",
"userPlaceholder": "Entrez le nom d'utilisateur eWeLink",
"passwordLabel": "Mot de passe",
"passwordPlaceholder": "Entrez le mot de passe utilisateur eWeLink",
"saveLabel": "Enregistrer la configuration",
"error": "Une erreur s'est produite lors de la sauvegarde de la configuration.",
"connecting": "Configuration sauvegardée. Connexion à votre compte cloud eWeLink...",
"connected": "Connexion réussie au compte cloud eWeLink !",
"connectionError": "Erreur lors de la connexion, veuillez vérifier votre configuration.",
"ewelinkIntegrationDeprecated": "Septembre 2023: Cette intégration ne semble malheureusement plus fonctionner suite à des changements côté API eWeLink. Discussion <a href=\"https://community.gladysassistant.com/t/service-ewelink-en-erreur/8323/17\" target=\"_blank\" rel=\"noopener noreferrer\">sur le forum ici</a>."
"applicationSetupLabel": "Configuration de l'application eWeLink",
"applicationIdLabel": "Identifiant de l'application (APPID)",
"applicationIdPlaceholder": "Entrez la valeur de APPID",
"applicationSecretLabel": "Secret de l'application (APP SECRET)",
"applicationSecretPlaceholder": "Entrez la valeur de APP SECRET",
"applicationRegionLabel": "Region",
"userConnectedLabel": "Connecté",
"userNotConnectedLabel": "Aucun utilisateur connecté",
"connectLabel": "Connexion",
"disconnectLabel": "Déconnexion",
"loadStatusError": "Impossible de remonter les informations sur l'état de l'intégration eWeLink. Gladys ne semble pas joignable.",
"saveConfigError": "Impossible d'enregistrer la configuration de l'application eWeLink. Gladys ne semble pas joignable.",
"loginRedirectError": "Une erreur est survenue lors de la connexion à eWeLink, merci de contacter la communauté.",
"exchangeTokenError": "Une erreur est survenue lors de la génération du jeton utilisateur eWeLink, merci de contacter la communauté.",
"exchangeTokenSuccess": "L'authentification est un succès, cette page peut être fermée.",
"regions": {
"cn": "Chine",
"as": "Asie",
"us": "Ameriques",
"eu": "Europe"
}
},
"error": {
"defaultError": "Une erreur s'est produite lors de l'enregistrement de l'appareil.",
Expand Down
8 changes: 4 additions & 4 deletions front/src/routes/integration/all/ewelink/EweLinkDeviceBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import cx from 'classnames';
import { Link } from 'preact-router';
import get from 'get-value';

import { DEVICE_FIRMWARE, DEVICE_ONLINE } from '../../../../../../server/services/ewelink/lib/utils/constants';
import { DEVICE_PARAMS } from '../../../../../../server/services/ewelink/lib/utils/constants';
import DeviceFeatures from '../../../../components/device/view/DeviceFeatures';

class EweLinkDeviceBox extends Component {
Expand Down Expand Up @@ -68,8 +68,8 @@ class EweLinkDeviceBox extends Component {
{ loading, errorMessage, tooMuchStatesError, statesNumber }
) {
const validModel = device.features && device.features.length > 0;
const online = device.params.find(param => param.name === DEVICE_ONLINE).value === '1';
const firmware = device.params.find(param => param.name === DEVICE_FIRMWARE).value;
const online = device.params.find(param => param.name === DEVICE_PARAMS.ONLINE).value === '1';
const firmware = (device.params.find(param => param.name === DEVICE_PARAMS.FIRMWARE) || { value: '?.?.?' }).value;

return (
<div class="col-md-6">
Expand All @@ -82,7 +82,7 @@ class EweLinkDeviceBox extends Component {
</div>
</Localizer>
<div class="page-options d-flex">
{device.params.find(param => param.name === DEVICE_FIRMWARE) && (
{device.params.find(param => param.name === DEVICE_PARAMS.FIRMWARE) && (
<div class="tag tag-blue">{`Firmware: ${firmware}`}</div>
)}
</div>
Expand Down
94 changes: 0 additions & 94 deletions front/src/routes/integration/all/ewelink/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,83 +6,6 @@ import createActionsIntegration from '../../../../actions/integration';
function createActions(store) {
const integrationActions = createActionsIntegration(store);
const actions = {
async loadProps(state) {
let eweLinkUsername;
let eweLinkPassword;
try {
eweLinkUsername = await state.httpClient.get('/api/v1/service/ewelink/variable/EWELINK_EMAIL');
if (eweLinkUsername.value) {
eweLinkPassword = '*********'; // this is just used so that the field is filled
}
} finally {
store.setState({
eweLinkUsername: (eweLinkUsername || { value: '' }).value,
eweLinkPassword,
passwordChanges: false,
connected: false
});
}
},
updateConfigration(state, e) {
const data = {};
data[e.target.name] = e.target.value;
if (e.target.name === 'eweLinkPassword') {
data.passwordChanges = true;
}
store.setState(data);
},
async saveConfiguration(state) {
event.preventDefault();
store.setState({
connectEweLinkStatus: RequestStatus.Getting,
eweLinkConnected: false,
eweLinkConnectionError: undefined
});
try {
await state.httpClient.post('/api/v1/service/ewelink/variable/EWELINK_EMAIL', {
value: state.eweLinkUsername
});
if (state.passwordChanges) {
await state.httpClient.post('/api/v1/service/ewelink/variable/EWELINK_PASSWORD', {
value: state.eweLinkPassword
});
}
await state.httpClient.post(`/api/v1/service/ewelink/connect`);

store.setState({
connectEweLinkStatus: RequestStatus.Success
});

setTimeout(() => store.setState({ connectEweLinkStatus: undefined }), 3000);
} catch (e) {
store.setState({
connectEweLinkStatus: RequestStatus.Error,
passwordChanges: false
});
}
},
displayConnectedMessage() {
// display 3 seconds a message "EweLink connected"
store.setState({
eweLinkConnected: true,
eweLinkConnectionError: undefined
});
setTimeout(
() =>
store.setState({
eweLinkConnected: false,
connectEweLinkStatus: undefined
}),
3000
);
},
displayEweLinkError(state, error) {
store.setState({
eweLinkConnected: false,
connectEweLinkStatus: undefined,
eweLinkConnectionError: error
});
},
async getEweLinkDevices(state) {
store.setState({
getEweLinkStatus: RequestStatus.Getting
Expand Down Expand Up @@ -155,23 +78,6 @@ function createActions(store) {
[listName]: devices
});
},
updateFeatureProperty(state, listName, deviceIndex, featureIndex, property, value) {
const devices = update(state[listName], {
[deviceIndex]: {
features: {
[featureIndex]: {
[property]: {
$set: value
}
}
}
}
});

store.setState({
[listName]: devices
});
},
async saveDevice(state, listName, index) {
const device = state[listName][index];
const savedDevice = await state.httpClient.post(`/api/v1/device`, device);
Expand Down
Loading
Loading