diff options
| author | CamVan Nguyen <ctnguyen@us.ibm.com> | 2018-03-13 18:38:37 -0500 |
|---|---|---|
| committer | Gunnar Mills <gmills@us.ibm.com> | 2018-04-13 01:25:11 +0000 |
| commit | 3327583964a2b38bf2fd75f75d1d1f148f82f006 (patch) | |
| tree | 45d4413699cdc27b5b04c4c8a8ae3c2b106256fd /app/common/services | |
| parent | a72686f76759faaefc76265f56b2dcc26c7c20de (diff) | |
| download | phosphor-webui-3327583964a2b38bf2fd75f75d1d1f148f82f006.tar.gz phosphor-webui-3327583964a2b38bf2fd75f75d1d1f148f82f006.zip | |
Display correct Power Consumption & Cap values
Current values are hard coded to '000 W'.
This fix is to do REST calls and display the correct values.
Resolves openbmc/openbmc#2735
Change-Id: I2f6766f1685a2bd52da62cda19998794f80270ec
Signed-off-by: CamVan Nguyen <ctnguyen@us.ibm.com>
Diffstat (limited to 'app/common/services')
| -rw-r--r-- | app/common/services/api-utils.js | 69 | ||||
| -rw-r--r-- | app/common/services/constants.js | 10 |
2 files changed, 65 insertions, 14 deletions
diff --git a/app/common/services/api-utils.js b/app/common/services/api-utils.js index f73a584..431c7ce 100644 --- a/app/common/services/api-utils.js +++ b/app/common/services/api-utils.js @@ -12,6 +12,18 @@ window.angular && (function (angular) { angular .module('app.common.services') .factory('APIUtils', ['$http', 'Constants', '$q', 'dataService',function($http, Constants, $q, DataService){ + var getScaledValue = function(value, scale){ + scale = scale + ""; + scale = parseInt(scale, 10); + var power = Math.abs(parseInt(scale,10)); + + if(scale > 0){ + value = value * Math.pow(10, power); + }else if(scale < 0){ + value = value / Math.pow(10, power); + } + return value; + }; var SERVICE = { API_CREDENTIALS: Constants.API_CREDENTIALS, API_RESPONSE: Constants.API_RESPONSE, @@ -523,19 +535,6 @@ window.angular && (function (angular) { var order = 0; var customOrder = 0; - function getScaledValue(value, scale){ - scale = scale + ""; - scale = parseInt(scale, 10); - var power = Math.abs(parseInt(scale,10)); - - if(scale > 0){ - value = value * Math.pow(10, power); - }else if(scale < 0){ - value = value / Math.pow(10, power); - } - return value; - } - function getSensorStatus(reading){ var severityFlags = {critical: false, warning: false, normal: false}, severityText = '', order = 0; @@ -1060,6 +1059,50 @@ window.angular && (function (angular) { return defer.promise; }, + getPowerConsumption: function(){ + return $http({ + method: 'GET', + url: DataService.getHost() + "/xyz/openbmc_project/sensors/power/total_power", + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true + }).then(function(response){ + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + + return getScaledValue(content.data.Value, + content.data.Scale) + ' ' + + Constants.POWER_CONSUMPTION_TEXT[content.data.Unit]; + }, function(error){ + if ('Not Found' == error.statusText) { + return Constants.POWER_CONSUMPTION_TEXT.notavailable; + } else { + console.log(error); + } + }); + }, + getPowerCap: function(){ + return $http({ + method: 'GET', + url: DataService.getHost() + "/xyz/openbmc_project/control/host0/power_cap", + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true + }).then(function(response){ + var json = JSON.stringify(response.data); + var content = JSON.parse(json); + + return (false == content.data.PowerCapEnable) ? + Constants.POWER_CAP_TEXT.disabled : + content.data.PowerCap + ' ' + Constants.POWER_CAP_TEXT.unit; + }, function(error){ + console.log(error); + }); + }, }; return SERVICE; }]); diff --git a/app/common/services/constants.js b/app/common/services/constants.js index af0965d..0bb2123 100644 --- a/app/common/services/constants.js +++ b/app/common/services/constants.js @@ -122,7 +122,15 @@ window.angular && (function (angular) { CRITICAL_NO_SENSOR_DATA: 'There are no sensors in Critical state.', WARNING_NO_SENSOR_DATA: 'There are no sensors in Warning state.' } - } + }, + POWER_CAP_TEXT: { + unit: 'W', + disabled: 'Not Enabled' + }, + POWER_CONSUMPTION_TEXT: { + 'xyz.openbmc_project.Sensor.Value.Unit.Watts': 'W', + notavailable: 'Not Available' + }, }; }); |

