(function () { function extractData(res) { return res && res.data; } function Property($http, DillerRpc, propertyId) { /** * @param {Diller.Interval} interval * @returns {Promise} */ function getInterval(interval) { var req = DillerRpc.getValuesReq(propertyId); req.params = {}; var from = interval.getFrom(); if(from.isValid()) { req.params.from = from.toISOString(); } var to = interval.getTo(); if(to.isValid()) { req.params.to = to.toISOString(); } req.params.aggregateLevel = interval.getLevel(); return $http(req).then(extractData); } /** @lends Property.prototype */ return { getInterval: getInterval }; } function Device($http, DillerRpc, deviceId) { var properties = {}; /** * @param propertyId * @returns {Property} */ function getProperty(propertyId) { var p = properties[propertyId]; if (!p) { p = new Property($http, DillerRpc, propertyId); properties[propertyId] = p; } return p; } /** @lends Device.prototype */ return { getProperty: getProperty }; } function DillerClient($timeout, $http, DillerRpc) { var devices = {}; function getDevice(deviceId) { var d = devices[deviceId]; if (!d) { d = new Device($http, DillerRpc, deviceId); devices[deviceId] = d; } return d; } /** @lends DillerClient.prototype */ return { getDevice: getDevice }; } angular .module('diller.client', []) .service('DillerClient', DillerClient) .service('DillerRpc', window.DillerRpc); })();