From ed9c73429fca6b298b714b80376b64254d993c33 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 13 Jul 2018 15:31:22 +0200 Subject: [PATCH] Allow managing users (#1436) * Allow managing users * Address comments * table -> card-content * Don't close dialog on error --- src/entrypoints/app.js | 25 +++ .../config/dashboard/ha-config-dashboard.js | 9 +- .../config/dashboard/ha-config-users-menu.js | 47 +++++ src/panels/config/ha-panel-config.js | 9 + src/panels/config/users/ha-config-users.js | 100 +++++++++++ src/panels/config/users/ha-dialog-add-user.js | 169 ++++++++++++++++++ src/panels/config/users/ha-user-editor.js | 99 ++++++++++ src/panels/config/users/ha-user-picker.js | 110 ++++++++++++ src/translations/en.json | 14 ++ 9 files changed, 580 insertions(+), 2 deletions(-) create mode 100644 src/panels/config/dashboard/ha-config-users-menu.js create mode 100644 src/panels/config/users/ha-config-users.js create mode 100644 src/panels/config/users/ha-dialog-add-user.js create mode 100644 src/panels/config/users/ha-user-editor.js create mode 100644 src/panels/config/users/ha-user-picker.js diff --git a/src/entrypoints/app.js b/src/entrypoints/app.js index 3aaf3fac62..8f64cd4a46 100644 --- a/src/entrypoints/app.js +++ b/src/entrypoints/app.js @@ -173,6 +173,8 @@ class HomeAssistant extends LocalizeMixin(PolymerElement) { moreInfoEntityId: null, callService: null, callApi: null, + sendWS: null, + callWS: null, }); return; } @@ -243,6 +245,29 @@ class HomeAssistant extends LocalizeMixin(PolymerElement) { return await hassCallApi(host, auth, method, path, parameters); } }, + // For messages that do not get a response + sendWS: (msg) => { + // eslint-disable-next-line + if (__DEV__) console.log('Sending', msg); + conn.sendMessage(msg); + }, + // For messages that expect a response + callWS: (msg) => { + /* eslint-disable no-console */ + if (__DEV__) console.log('Sending', msg); + + const resp = conn.sendMessagePromise(msg); + + if (__DEV__) { + resp.then( + result => console.log('Received', result), + err => console.log('Error', err), + ); + } + // In the future we'll do this as a breaking change + // inside home-assistant-js-websocket + return resp.then(result => result.result); + }, }, this.$.storage.getStoredState()); var reconnected = () => { diff --git a/src/panels/config/dashboard/ha-config-dashboard.js b/src/panels/config/dashboard/ha-config-dashboard.js index 2919d63b5c..e426b89677 100644 --- a/src/panels/config/dashboard/ha-config-dashboard.js +++ b/src/panels/config/dashboard/ha-config-dashboard.js @@ -9,6 +9,7 @@ import '../../../components/ha-menu-button.js'; import '../ha-config-section.js'; import './ha-config-cloud-menu.js'; import './ha-config-entries-menu.js'; +import './ha-config-users-menu.js'; import './ha-config-navigation.js'; import isComponentLoaded from '../../../common/config/is_component_loaded.js'; @@ -39,14 +40,18 @@ class HaConfigDashboard extends LocalizeMixin(PolymerElement) { [[localize('ui.panel.config.header')]] [[localize('ui.panel.config.introduction')]] -