diff --git a/accelerator-home-ui/settings.json b/accelerator-home-ui/settings.json index b73ffb3c..f78203ff 100644 --- a/accelerator-home-ui/settings.json +++ b/accelerator-home-ui/settings.json @@ -13,6 +13,6 @@ "log": true, "enableAppSuspended": true, "showVersion": false, - "version": "5.0.24" + "version": "5.0.25" } } diff --git a/accelerator-home-ui/src/App.js b/accelerator-home-ui/src/App.js index c86832c6..b96ab0ad 100644 --- a/accelerator-home-ui/src/App.js +++ b/accelerator-home-ui/src/App.js @@ -85,6 +85,7 @@ import PackageManager from './api/PackageManagerApi.js'; import RDKWindowManager from './api/RDKWindowManagerApi.js'; import RuntimeManager from './api/RuntimeManagerApi.js'; import AppController from './AppController.js'; +import LEDController, { LEDControlState } from './api/LEDControlApi.js'; var AlexaAudioplayerActive = false; var thunder = ThunderJS(CONFIG.thunderConfig); @@ -257,7 +258,7 @@ export default class App extends Router.App { GLOBALS.powerState = PowerState.POWER_STATE_ON; this.LOG("powerState after ===>" + JSON.stringify(GLOBALS.powerState)) this.initializeInactivityEngine(); - }) + }) .catch(err => { this.ERR("Error waking device: " + JSON.stringify(err)); }) @@ -281,7 +282,7 @@ export default class App extends Router.App { } else if(GLOBALS.MiracastNotificationstatus){ this.jumpToRoute("menu"); miracast.acceptClientConnection("Reject").then(res=>{ - if(res.success){Router.focusPage()} + if(res.success){Router.focusPage()} }) } else { this.jumpToRoute("menu"); //method to exit the current app(if any) and route to home screen @@ -529,6 +530,15 @@ export default class App extends Router.App { Storage.set("deviceType", ((result.devicetype != null) ? result.devicetype : "IpTv")); }); UserSettingsApi.get().activate(); + LEDController.isSupported().then(isSupported => { + if (isSupported) { + LEDController.activate().then(() => { + LEDController.getSupportedLEDStates(); + }); + } else { + this.LOG("LEDController is not supported on this device"); + } + }); thunder.Controller.activate({ callsign: 'org.rdk.System' }).then(result => { @@ -537,10 +547,12 @@ export default class App extends Router.App { //https://github.com/rdkcentral/entservices-apis/blob/1.15.11/docs/apis/PowerManagerPlugin.md#setWakeupSrcConfig //By the above documentation we passed the Enum value sum to enable all wakeup sources expect WAKEUP_REASON_UNKNOWN //Enum indicating bit position (bit counting starts at 1) - "wakeupSources": 262143 + "wakeupSources": 262143 } appApi.setWakeupSrcConfiguration(param); - appApi.setPowerState(GLOBALS.powerState).then(res => {}); + appApi.setPowerState(GLOBALS.powerState).then(res => { + if (res === false) this.ERR("setPowerState failed: " + JSON.stringify(GLOBALS.powerState)); + }); }).catch(err => { this.ERR("App System plugin activation error: " + JSON.stringify(err)); }) @@ -839,28 +851,28 @@ export default class App extends Router.App { this._updateLanguageToDefault() // Initialize plugins using the abstraction this._activatePlugin( - "org.rdk.PackageManagerRDKEMS", - "PackageManagerRDKEMS", + "org.rdk.PackageManagerRDKEMS", + "PackageManagerRDKEMS", () => packagemangerRdkems.activate() ); - + this._activatePlugin( - "org.rdk.AppManager", - "AppManager", + "org.rdk.AppManager", + "AppManager", () => AppManager.get().activate(), () => this._SubscribeToAppManagerNotifications() ); - + this._activatePlugin( - "org.rdk.RDKWindowManager", - "RDKWindowManager", + "org.rdk.RDKWindowManager", + "RDKWindowManager", () => RDKWindowManager.get().activate(), () => this._SubscribeToRDKWindowManagerNotifications() ); - + this._activatePlugin( - "org.rdk.RuntimeManager", - "RuntimeManager", + "org.rdk.RuntimeManager", + "RuntimeManager", () => RuntimeManager.get().activate(), () => this._SubscribeToRuntimeManagerNotifications() ); @@ -961,7 +973,7 @@ export default class App extends Router.App { } else { GLOBALS.IsConnectedToInternet = false - } + } console.warn("onInternetStatusChange:", data); }); thunder.on('org.rdk.NetworkManager', 'onAvailableSSIDs', data => { @@ -2121,6 +2133,7 @@ export default class App extends Router.App { subscribeToPowerChangeNotifications() { thunder.on("org.rdk.PowerManager", "onPowerModeChanged", notification => { this.LOG(new Date().toISOString() + " onPowerModeChanged Notification: " + JSON.stringify(notification)); + LEDController.setLEDState(notification.newState === "ON" ? LEDControlState.ACTIVE : LEDControlState.STANDBY); appApi.getPowerState().then(res => { GLOBALS.powerState = res ? res.currentState : notification.newState }).catch(e => GLOBALS.powerState = notification.newState) @@ -2852,4 +2865,4 @@ export default class App extends Router.App { } } } -} \ No newline at end of file +} diff --git a/accelerator-home-ui/src/api/LEDControlApi.js b/accelerator-home-ui/src/api/LEDControlApi.js new file mode 100644 index 00000000..3225846c --- /dev/null +++ b/accelerator-home-ui/src/api/LEDControlApi.js @@ -0,0 +1,194 @@ +/** + * If not stated otherwise in this file or this component's LICENSE + * file the following copyright and licenses apply: + * + * Copyright 2026 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +import ThunderJS from 'ThunderJS'; +import { CONFIG } from '../Config/Config'; +import { Metrics } from '@firebolt-js/sdk'; +import { GLOBALS } from '../Config/Config'; + +export const LEDControlState = { + NONE: 'NONE', + ACTIVE: 'ACTIVE', + STANDBY: 'STANDBY', + WPS_CONNECTING: 'WPS_CONNECTING', + WPS_CONNECTED: 'WPS_CONNECTED', + WPS_ERROR: 'WPS_ERROR', + FACTORY_RESET: 'FACTORY_RESET', + USB_UPGRADE: 'USB_UPGRADE', + DOWNLOAD_ERROR: 'DOWNLOAD_ERROR', +}; + +class LEDControlApi { + constructor() { + this.thunder = ThunderJS(CONFIG.thunderConfig); + this.callsign = 'org.rdk.LEDControl'; + this.INFO = console.info; + this.LOG = console.log; + this.ERR = console.error; + this._isSupportedPromise = this._fetchIsSupported(); + this._supportedLEDStatesPromise = null; + } + + _fetchIsSupported() { + return this.thunder.call('Controller', `status@${this.callsign}`).then(result => { + const supported = Array.isArray(result) ? result.length > 0 : !!result; + this.LOG(this.callsign + ' isSupported result: ' + supported); + return supported; + }).catch(err => { + this.ERR(this.callsign + ' isSupported error: ' + JSON.stringify(err)); + return false; + }); + } + + isSupported() { + return this._isSupportedPromise; + } + + activate() { + return new Promise((resolve, reject) => { + this.thunder.call('Controller', 'activate', { callsign: this.callsign }).then(result => { + this.INFO(this.callsign + ' activate result: ' + JSON.stringify(result)); + resolve(true); + }).catch(err => { + this.ERR(this.callsign + ' activate error: ' + JSON.stringify(err)); + Metrics.error(Metrics.ErrorType.OTHER, 'LEDControlApiError', 'Error while Thunder Controller LEDControl activate ' + JSON.stringify(err), false, null); + reject(err); + }); + }); + } + + deactivate() { + return new Promise((resolve, reject) => { + this.thunder.call('Controller', 'deactivate', { callsign: this.callsign }).then(result => { + this.INFO(this.callsign + ' deactivate result: ' + JSON.stringify(result)); + this._supportedLEDStatesPromise = null; + resolve(true); + }).catch(err => { + this.ERR(this.callsign + ' deactivate error: ' + JSON.stringify(err)); + Metrics.error(Metrics.ErrorType.OTHER, 'LEDControlApiError', 'Error while Thunder Controller LEDControl deactivate ' + JSON.stringify(err), false, null); + reject(err); + }); + }); + } + + getLEDState() { + return new Promise((resolve, reject) => { + this.isSupported().then(isSupported => { + if (!isSupported) { + this.LOG(this.callsign + ' getLEDState skipped: plugin not supported on this platform'); + resolve(null); + return; + } + + this.thunder.call(this.callsign, 'getLEDState').then(result => { + this.LOG(this.callsign + ' getLEDState result: ' + JSON.stringify(result)); + resolve(result); + }).catch(err => { + this.ERR(this.callsign + ' getLEDState error: ' + JSON.stringify(err)); + Metrics.error(Metrics.ErrorType.OTHER, 'LEDControlApiError', 'Error while Thunder LEDControl getLEDState ' + JSON.stringify(err), false, null); + reject(err); + }); + }).catch(err => { + this.ERR(this.callsign + ' getLEDState support check failed: ' + JSON.stringify(err)); + resolve(null); + }); + }); + } + + getSupportedLEDStates(forceRefresh = false) { + if (!forceRefresh) { + return this.isSupported().then(isSupported => { + if (!isSupported) { + this.LOG(this.callsign + ' getSupportedLEDStates skipped: plugin not supported on this platform'); + return []; + } + + if (this._supportedLEDStatesPromise) { + return this._supportedLEDStatesPromise; + } + + this._supportedLEDStatesPromise = this.thunder.call(this.callsign, 'getSupportedLEDStates').then(result => { + this.LOG(this.callsign + ' getSupportedLEDStates result: ' + JSON.stringify(result)); + if (result.success) { + return result.supportedLEDStates || []; + } + throw result; + }).catch(err => { + this._supportedLEDStatesPromise = null; + this.ERR(this.callsign + ' getSupportedLEDStates error: ' + JSON.stringify(err)); + Metrics.error(Metrics.ErrorType.OTHER, 'LEDControlApiError', 'Error while Thunder LEDControl getSupportedLEDStates ' + JSON.stringify(err), false, null); + throw err; + }); + + return this._supportedLEDStatesPromise; + }).catch(() => { + this.LOG(this.callsign + ' getSupportedLEDStates skipped: support check failed'); + return []; + }); + } + + if (forceRefresh) { + this._supportedLEDStatesPromise = null; + } + + return this.getSupportedLEDStates(false); + } + + setLEDState(state) { + return new Promise((resolve) => { + this.isSupported().then(isSupported => { + if (!isSupported) { + this.LOG(this.callsign + ' setLEDState skipped: plugin not supported on this platform'); + resolve(false); + return; + } + + this.getSupportedLEDStates().then(supportedLEDStates => { + if (!Array.isArray(supportedLEDStates) || !supportedLEDStates.includes(state)) { + this.LOG(this.callsign + ' setLEDState skipped: unsupported state requested: ' + state + ', supported: ' + JSON.stringify(supportedLEDStates)); + resolve(false); + return; + } + + this.thunder.call(this.callsign, 'setLEDState', { state }).then(result => { + this.LOG(this.callsign + ' setLEDState result: ' + JSON.stringify(result)); + resolve(result.success === true); + }).catch(err => { + this.ERR(this.callsign + ' setLEDState error: ' + JSON.stringify(err)); + Metrics.error(Metrics.ErrorType.OTHER, 'LEDControlApiError', 'Error while Thunder LEDControl setLEDState ' + JSON.stringify(err), false, null); + resolve(false); + }); + }).catch(err => { + this.ERR(this.callsign + ' setLEDState failed to fetch supported states: ' + JSON.stringify(err)); + resolve(false); + }); + }).catch(err => { + this.ERR(this.callsign + ' setLEDState support check failed: ' + JSON.stringify(err)); + resolve(false); + }); + }); + } + + matchLEDStateToPowerState() { + return this.setLEDState(GLOBALS.powerState !== 'ON' ? LEDControlState.STANDBY : LEDControlState.ACTIVE); + } +} + +const ledControlApi = new LEDControlApi(); +export default ledControlApi; diff --git a/accelerator-home-ui/src/routes/otherSettingsRoutes.js b/accelerator-home-ui/src/routes/otherSettingsRoutes.js index 94477df1..d8f4f5b5 100644 --- a/accelerator-home-ui/src/routes/otherSettingsRoutes.js +++ b/accelerator-home-ui/src/routes/otherSettingsRoutes.js @@ -126,4 +126,4 @@ export default { widgets: ['Menu', 'Volume', "AppCarousel"], } ] -} \ No newline at end of file +} diff --git a/accelerator-home-ui/src/screens/FailScreen.js b/accelerator-home-ui/src/screens/FailScreen.js index 3e326202..86095522 100644 --- a/accelerator-home-ui/src/screens/FailScreen.js +++ b/accelerator-home-ui/src/screens/FailScreen.js @@ -18,6 +18,7 @@ **/ import { Language,Registry, Lightning, Router } from "@lightningjs/sdk"; import { CONFIG } from '../Config/Config' +import LEDController, { LEDControlState } from "../api/LEDControlApi"; const errorTitle = 'Error Title' const errorMsg = 'Error Message' @@ -141,6 +142,7 @@ export default class Failscreen extends Lightning.Component { if(this.timeout > 0) { this.initTimer() } + LEDController.setLEDState(LEDControlState.WPS_ERROR); } initTimer() { this.timeInterval = Registry.setInterval(() => { @@ -165,9 +167,10 @@ export default class Failscreen extends Lightning.Component { if (this.timeInterval) { Registry.clearInterval(this.timeInterval) } + LEDController.matchLEDStateToPowerState(); } _handleBack() { Router.focusPage() } -} \ No newline at end of file +} diff --git a/accelerator-home-ui/src/screens/JoinAnotherNetworkComponent.js b/accelerator-home-ui/src/screens/JoinAnotherNetworkComponent.js index 98975807..0e73f481 100644 --- a/accelerator-home-ui/src/screens/JoinAnotherNetworkComponent.js +++ b/accelerator-home-ui/src/screens/JoinAnotherNetworkComponent.js @@ -23,6 +23,7 @@ import { KEYBOARD_FORMATS } from '../ui-components/components/Keyboard' import PasswordSwitch from './PasswordSwitch'; import NetworkManager from '../api/NetworkManagerAPI'; import PersistentStoreApi from '../api/PersistentStore'; +import LEDController, { LEDControlState } from '../api/LEDControlApi' export default class JoinAnotherNetworkComponent extends Lightning.Component { @@ -44,6 +45,10 @@ export default class JoinAnotherNetworkComponent extends Lightning.Component { this.tag("Keyboard").visible = false } + _inactive() { + LEDController.matchLEDStateToPowerState(); + } + handleDone() { this.tag("Keyboard").visible = false let securityCode = this.securityCodes[this.securityCodeIndex].value; @@ -69,6 +74,7 @@ export default class JoinAnotherNetworkComponent extends Lightning.Component { } async startConnectForAnotherNetwork(device, passphrase) { + LEDController.setLEDState(LEDControlState.WPS_CONNECTING); await NetworkManager.WiFiConnect(false, { ssid: device.ssid, security: device.security }, passphrase).then(() => { NetworkManager.AddToKnownSSIDs(device.ssid, passphrase, device.security).then((response) => { if (response === true ) { diff --git a/accelerator-home-ui/src/screens/OtherSettingsScreens/FactoryResetConfirmationScreen.js b/accelerator-home-ui/src/screens/OtherSettingsScreens/FactoryResetConfirmationScreen.js index 730d7fbf..1659549f 100644 --- a/accelerator-home-ui/src/screens/OtherSettingsScreens/FactoryResetConfirmationScreen.js +++ b/accelerator-home-ui/src/screens/OtherSettingsScreens/FactoryResetConfirmationScreen.js @@ -25,6 +25,7 @@ import NetworkManager from '../../api/NetworkManagerAPI.js' import AlexaApi from '../../api/AlexaApi.js'; import RCApi from '../../api/RemoteControl' import Warehouse from '../../api/WarehouseApis.js' +import LEDController, { LEDControlState } from '../../api/LEDControlApi' const appApi = new AppApi() const _btApi = new BluetoothApi() @@ -138,7 +139,6 @@ export default class RebootConfirmationScreen extends Lightning.Component { }); } - _firstEnable() { this.AppApi.checkStatus(Warehouse.get().callsign).then(resp => { this.LOG("FactoryReset: warehouse plugin status : " + JSON.stringify(resp[0].status)); @@ -157,6 +157,7 @@ export default class RebootConfirmationScreen extends Lightning.Component { } async _performFactoryReset() { + LEDController.setLEDState(LEDControlState.FACTORY_RESET); // Deactivate SmartScreen instance to prevent overlay when Auth is revoked. AlexaApi.get().disableSmartScreen(); if(GLOBALS.AlexaAvsstatus){AlexaApi.get().resetAVSCredentials();} @@ -211,7 +212,7 @@ export default class RebootConfirmationScreen extends Lightning.Component { try { localStorage.clear(); this.LOG("localStorage cleared successfully"); - } + } catch (err) { this.ERR("Error clearing localStorage: " + JSON.stringify(err)); } diff --git a/accelerator-home-ui/src/screens/OtherSettingsScreens/FirmwareScreen.js b/accelerator-home-ui/src/screens/OtherSettingsScreens/FirmwareScreen.js index b5a101cf..b81a9a72 100644 --- a/accelerator-home-ui/src/screens/OtherSettingsScreens/FirmwareScreen.js +++ b/accelerator-home-ui/src/screens/OtherSettingsScreens/FirmwareScreen.js @@ -22,6 +22,7 @@ import { CONFIG } from '../../Config/Config' import AppApi from '../../api/AppApi'; import ThunderJS from 'ThunderJS'; import { Metrics } from '@firebolt-js/sdk'; +import LEDController, { LEDControlState } from '../../api/LEDControlApi' /** * Class for Firmware screen. @@ -148,7 +149,18 @@ export default class FirmwareScreen extends Lightning.Component { this.LOG("Downloading..."); this.getDownloadPercent(); }, 1000) + LEDController.setLEDState(LEDControlState.USB_UPGRADE); + } else if (FirmwareScreen.STATES[notification.firmwareUpdateStateChange] === "Failed") { + LEDController.matchLEDStateToPowerState(); + this.tag('DownloadedPercent.Title').visible = false; + this.showUpdateButton(notification.firmwareUpdateStateChange) + if (this.downloadInterval) { + this.LOG(""); + clearInterval(this.downloadInterval); + this.downloadInterval = null + } } else if (notification.firmwareUpdateStateChange > 3) { + LEDController.matchLEDStateToPowerState(); this.showUpdateButton(notification.firmwareUpdateStateChange) this.getDownloadFirmwareInfo() } else if (FirmwareScreen.STATES[notification.firmwareUpdateStateChange] != "Downloading") { @@ -203,6 +215,7 @@ export default class FirmwareScreen extends Lightning.Component { _disable() { if (this.onFirmwareUpdateStateChangeCB) this.onFirmwareUpdateStateChangeCB.dispose(); + LEDController.matchLEDStateToPowerState(); } async _focus() { @@ -276,4 +289,4 @@ export default class FirmwareScreen extends Lightning.Component { ] } } -FirmwareScreen.STATES = ['Uninitialized', 'Requesting', 'Downloading', 'Failed', 'Download Complete', 'Validation Complete', 'Preparing to Reboot'] \ No newline at end of file +FirmwareScreen.STATES = ['Uninitialized', 'Requesting', 'Downloading', 'Failed', 'Download Complete', 'Validation Complete', 'Preparing to Reboot'] diff --git a/accelerator-home-ui/src/screens/RcInformationScreen.js b/accelerator-home-ui/src/screens/RcInformationScreen.js index 03fe5229..c18cee2a 100644 --- a/accelerator-home-ui/src/screens/RcInformationScreen.js +++ b/accelerator-home-ui/src/screens/RcInformationScreen.js @@ -21,6 +21,7 @@ import { COLORS } from './../colors/Colors' import { CONFIG } from '../Config/Config' import ThunderJS from 'ThunderJS' import RCApi from '../api/RemoteControl'; +import LEDController, { LEDControlState } from '../api/LEDControlApi'; const _thunder = ThunderJS(CONFIG.thunderConfig) let onStatusCBhandle = null; @@ -245,6 +246,7 @@ export default class RCInformationScreen extends Lightning.Component { this.tag("BatteryPercent.Value").text.text = `N/A` this.tag("RCUName.Value").text.text = `N/A` //RCApi.get().deactivate().catch(err=> { console.error("RCInformationScreen error:", err)}); + LEDController.matchLEDStateToPowerState(); } onStatusCB(cbData) { @@ -253,7 +255,7 @@ export default class RCInformationScreen extends Lightning.Component { let cbDatastatus if (Array.isArray(cbData.status)) { cbDatastatus = cbData.status[0] || {}; - } + } else if (cbData.status && typeof cbData.status === 'object') { cbDatastatus = cbData.status; } @@ -276,6 +278,9 @@ export default class RCInformationScreen extends Lightning.Component { }) cbDatastatus.remoteData.map(item => { connectedStatus.push(item.connected) + if (item.connected === true) { + LEDController.setLEDState(LEDControlState.WPS_CONNECTED); + } }) this.tag("Status.Value").text.text = connectedStatus this.tag("MacAddress.Value").text.text = MacAddress @@ -287,7 +292,9 @@ export default class RCInformationScreen extends Lightning.Component { for(let i=0;i { + RCApi.get().startPairing(30, cbDatastatus.netTypesSupported[i]).then(() => { + LEDController.setLEDState(LEDControlState.WPS_CONNECTING); + }).catch(err => { this.ERR("RCInformationScreen startPairing error: " + JSON.stringify(err)); }); } diff --git a/accelerator-home-ui/src/screens/SplashScreens/BluetoothScreen.js b/accelerator-home-ui/src/screens/SplashScreens/BluetoothScreen.js index 847e3663..9dd0e282 100644 --- a/accelerator-home-ui/src/screens/SplashScreens/BluetoothScreen.js +++ b/accelerator-home-ui/src/screens/SplashScreens/BluetoothScreen.js @@ -23,6 +23,7 @@ import AppApi from '../../api/AppApi'; import BluetoothApi from '../../api/BluetoothApi'; import ThunderJS from 'ThunderJS' import RCApi from '../../api/RemoteControl'; +import LEDController, { LEDControlState } from '../../api/LEDControlApi'; var appApi = new AppApi(); var bluetoothApi = new BluetoothApi(); @@ -145,6 +146,7 @@ export default class BluetoothScreen extends Lightning.Component { bluetoothApi.enable().then(res => { this.LOG("SplashBluetoothScreen enable result: " + JSON.stringify(res)) bluetoothApi.startScanBluetooth().then(startScanresult => { + LEDController.setLEDState(LEDControlState.WPS_CONNECTING); this.LOG('SplashBluetoothScreen startScanresult ' + JSON.stringify(startScanresult)) var SubscribeEvent = _thunder.on('org.rdk.Bluetooth', 'onDiscoveredDevice', notification => { bluetoothApi.getDiscoveredDevices().then((getdocoveredInfo) => { @@ -158,6 +160,7 @@ export default class BluetoothScreen extends Lightning.Component { this.LOG("SplashBluetoothScreen getConnectedDevices" + JSON.stringify(getCdresult)) bluetoothApi.getPairedDevices().then(getpairedDevices => { this.LOG("SplashBluetoothScreen getpairedDevices" + JSON.stringify(getpairedDevices)) + LEDController.setLEDState(LEDControlState.WPS_CONNECTED); bluetoothApi.stopScan().then(stopScan => { this.LOG("SplashBluetoothScreen stopscan" + JSON.stringify(stopScan)) SubscribeEvent.dispose(); @@ -185,12 +188,14 @@ export default class BluetoothScreen extends Lightning.Component { }) .catch(err => { this.ERR(`SplashBluetoothScreen Can't pair device : ${JSON.stringify(err)}`) + LEDController.setLEDState(LEDControlState.WPS_ERROR); }) }) }) }) .catch(err => { this.ERR("Can't scan enable : " + JSON.stringify(err)) + LEDController.setLEDState(LEDControlState.WPS_ERROR); }) }) } @@ -202,7 +207,7 @@ export default class BluetoothScreen extends Lightning.Component { let cbDatastatus if (Array.isArray(cbData.status)) { cbDatastatus = cbData.status[0] || {}; - } + } else if (cbData.status && typeof cbData.status === 'object') { cbDatastatus = cbData.status; } @@ -210,6 +215,7 @@ export default class BluetoothScreen extends Lightning.Component { //console.log("BluetoothScreen rcPairingApis RemoteData Length ", cbData.status.remoteData.length) cbDatastatus.remoteData.map(item => { this.tag('Info').text.text = `paired with device ${item.name}` + LEDController.setLEDState(LEDControlState.WPS_CONNECTED); // Do not clear this.RCTimeout if need to run this in background to reconnect on loss. // if (this.RCTimeout) { // console.log("SplashBluetoothScreen clearTimeout(this.RCTimeout)"); @@ -230,8 +236,11 @@ export default class BluetoothScreen extends Lightning.Component { for(let i=0;i { + RCApi.get().startPairing(30,cbDatastatus.netTypesSupported[i]).then(() => { + LEDController.setLEDState(LEDControlState.WPS_CONNECTING); + }).catch(err => { this.ERR("RCInformationScreen startPairing error: " + JSON.stringify(err)); + LEDController.setLEDState(LEDControlState.WPS_ERROR); }); } } @@ -302,6 +311,7 @@ export default class BluetoothScreen extends Lightning.Component { if (this.RCTimeout) { Registry.clearTimeout(this.RCTimeout) } + LEDController.matchLEDStateToPowerState(); } static _states() { diff --git a/accelerator-home-ui/src/screens/SplashScreens/NetworkList.js b/accelerator-home-ui/src/screens/SplashScreens/NetworkList.js index 72aedb3e..a3d4b564 100644 --- a/accelerator-home-ui/src/screens/SplashScreens/NetworkList.js +++ b/accelerator-home-ui/src/screens/SplashScreens/NetworkList.js @@ -22,8 +22,8 @@ import { COLORS } from '../../colors/Colors' import { CONFIG,GLOBALS } from '../../Config/Config' import SettingsMainItem from '../../items/SettingsMainItem' import WiFiItem from '../../items/WiFiItem' -import NetworkManager,{WiFiState}from '../../api/NetworkManagerAPI' - +import NetworkManager, { WiFiState } from '../../api/NetworkManagerAPI' +import LEDController, { LEDControlState } from '../../api/LEDControlApi' export default class NetworkList extends Lightning.Component { constructor(...args) { @@ -215,6 +215,9 @@ export default class NetworkList extends Lightning.Component { NetworkManager.StopWiFiScan() } + _inactive() { + LEDController.matchLEDStateToPowerState(); + } /** * Function to render list of Wi-Fi networks. */ @@ -398,11 +401,13 @@ export default class NetworkList extends Lightning.Component { this.LOG(JSON.stringify(notification)) if (notification.state === WiFiState.WIFI_STATE_CONNECTED && ! GLOBALS.Setup) { this.tag('Info').text.text = Language.translate("Connection successful"); + LEDController.setLEDState(LEDControlState.WPS_CONNECTED); Registry.setTimeout(() => { Router.navigate('menu') }, 2000) } else if (notification.state === WiFiState.WIFI_STATE_CONNECTING || notification.state === WiFiState.WIFI_STATE_PAIRING) { this.tag('Info').text.text = Language.translate("Connecting, please wait"); + LEDController.setLEDState(LEDControlState.WPS_CONNECTING); } else if(notification.state === WiFiState.WIFI_STATE_SSID_CHANGED|| notification.state === WiFiState.WIFI_STATE_CONNECTION_LOST || notification.state === WiFiState.WIFI_STATE_CONNECTION_FAILED || @@ -411,6 +416,7 @@ export default class NetworkList extends Lightning.Component { notification.state === WiFiState.WIFI_STATE_AUTHENTICATION_FAILED || notification.state === WiFiState.WIFI_STATE_ERROR ) { + LEDController.setLEDState(LEDControlState.WPS_ERROR); if (notification.state === WiFiState.WIFI_STATE_INVALID_CREDENTIALS|| notification.state === WiFiState.WIFI_STATE_SSID_CHANGED || notification.state === WiFiState.WIFI_STATE_AUTHENTICATION_FAILED) { await NetworkManager.RemoveKnownSSID(this.selectedssid.ssid) diff --git a/accelerator-home-ui/src/screens/WiFiPairingScreen.js b/accelerator-home-ui/src/screens/WiFiPairingScreen.js index 67865cff..ef2c027e 100644 --- a/accelerator-home-ui/src/screens/WiFiPairingScreen.js +++ b/accelerator-home-ui/src/screens/WiFiPairingScreen.js @@ -23,7 +23,8 @@ import PasswordSwitch from './PasswordSwitch' import { Keyboard } from '../ui-components/index' import { KEYBOARD_FORMATS } from '../ui-components/components/Keyboard' import PersistentStoreApi from '../api/PersistentStore' -import NetworkManager,{WiFiState} from '../api/NetworkManagerAPI' +import NetworkManager, { WiFiState } from '../api/NetworkManagerAPI' +import LEDController, { LEDControlState } from '../api/LEDControlApi' let Ssid = null @@ -194,6 +195,7 @@ export default class WifiPairingScreen extends Lightning.Component { _inactive() { if (this.onWIFIStateChangedCB) this.onWIFIStateChangedCB.dispose(); if (this.waitToConnectTO) Registry.clearTimeout(this.waitToConnectTO); + LEDController.matchLEDStateToPowerState(); } async pressEnter(option) { @@ -235,10 +237,15 @@ export default class WifiPairingScreen extends Lightning.Component { this.onWIFIStateChangedCB = NetworkManager.thunder.on(NetworkManager.callsign, 'onWiFiStateChange', notification => { if (notification.state === WiFiState.WIFI_STATE_INVALID_CREDENTIALS|| notification.state === WiFiState.WIFI_STATE_SSID_CHANGED || notification.state === WiFiState.WIFI_STATE_AUTHENTICATION_FAILED) { this.LOG("INVALID_CREDENTIALS; deleting WiFi Persistence data.") + LEDController.setLEDState(LEDControlState.WPS_ERROR); NetworkManager.RemoveKnownSSID(Ssid).then(() => { PersistentStoreApi.get().deleteNamespace('wifi') }); flag = 1 + } else if (notification.state === WiFiState.WIFI_STATE_PAIRING || notification.state === WiFiState.WIFI_STATE_CONNECTING) { + LEDController.setLEDState(LEDControlState.WPS_CONNECTING); + } else if (notification.state === WiFiState.WIFI_STATE_CONNECTED) { + LEDController.setLEDState(LEDControlState.WPS_CONNECTED); } }) NetworkManager.WiFiConnect(false, this._item, password).then(() => { diff --git a/accelerator-home-ui/src/screens/WifiScreen.js b/accelerator-home-ui/src/screens/WifiScreen.js index 4ed25bad..b6a5e2c9 100644 --- a/accelerator-home-ui/src/screens/WifiScreen.js +++ b/accelerator-home-ui/src/screens/WifiScreen.js @@ -23,7 +23,8 @@ import { COLORS } from './../colors/Colors' import { CONFIG, GLOBALS } from '../Config/Config' import AppApi from './../api/AppApi' import PersistentStoreApi from '../api/PersistentStore.js' -import NetworkManager ,{WiFiState}from '../api/NetworkManagerAPI.js' +import NetworkManager, { WiFiState } from '../api/NetworkManagerAPI.js' +import LEDController, { LEDControlState } from '../api/LEDControlApi' let appApi = new AppApi() var previousFocusedItemSSid @@ -501,6 +502,7 @@ export default class WiFiScreen extends Lightning.Component { notification.state === WiFiState.WIFI_STATE_ERROR || notification.state === WiFiState.WIFI_STATE_DISCONNECTED) { if ((notification.state === WiFiState.WIFI_STATE_INVALID_CREDENTIALS) || (notification.state === WiFiState.WIFI_STATE_SSID_CHANGED) || notification.state === WiFiState.WIFI_STATE_AUTHENTICATION_FAILED) { + LEDController.setLEDState(LEDControlState.WPS_ERROR); await NetworkManager.RemoveKnownSSID(selectedssid.ssid) } if (this.renderSSIDS.length) { @@ -528,6 +530,7 @@ export default class WiFiScreen extends Lightning.Component { NetworkManager.GetInterfaceState("wlan0").then(enabled => { if (enabled) { NetworkManager.StartWiFiScan() + LEDController.setLEDState(LEDControlState.WPS_CONNECTING); this.wifiLoading.play() this.tag('Switch.Loader').visible = true } @@ -540,5 +543,6 @@ export default class WiFiScreen extends Lightning.Component { previousFocusedItemSSid = undefined this.onWIFIStateChangedCB.dispose(); this.onAvailableSSIDsCB.dispose(); + LEDController.matchLEDStateToPowerState(); } }