diff --git a/items/items-provider.js b/items/items-provider.js deleted file mode 100644 index eebf73e6a..000000000 --- a/items/items-provider.js +++ /dev/null @@ -1,126 +0,0 @@ -// const osgi = require('../osgi'); -const items = require('./items'); -const utils = require('../utils'); -const { AbstractProvider } = require('../provider'); - -const ITEM_PROVIDER_CLASS = 'org.openhab.core.items.ItemProvider'; - -class StaticItemProvider extends AbstractProvider { - constructor (items) { - super(ITEM_PROVIDER_CLASS); - this.items = items; - this.registerService(); - } - - addProviderChangeListener (listener) { - } - - removeProviderChangeListener (listener) { - } - - getAll () { - return this.items; - } -} - -class ManagedItemProvider extends AbstractProvider { - constructor () { - super(ITEM_PROVIDER_CLASS); - this.items = new Set(); - this.listeners = new Set(); - this.registerService(); - } - - addProviderChangeListener (listener) { - this.listeners.add(listener); - } - - removeProviderChangeListener (listener) { - this.listeners.delete(listener); - } - - add (item) { - if (item instanceof items.Item) { - item = item.rawItem; - } - - if (!this.items.has(item)) { - this.items.add(item); - for (const listener of this.listeners) { - listener.added(this.hostProvider, item); - } - } - } - - remove (itemOrName) { - if (typeof itemOrName === 'string') { - this.items.forEach(i => { if (i.name === itemOrName) this.remove(i); }); - } else { - if (itemOrName instanceof items.Item) { - itemOrName = itemOrName.rawItem; - } - - if (this.items.has(itemOrName)) { - this.items.delete(itemOrName); - - for (const listener of this.listeners) { - listener.removed(this.hostProvider, itemOrName); - } - } - } - } - - update (item) { - if (item instanceof items.Item) { - item = item.rawItem; - } - - for (const listener of this.listeners) { - listener.updated(this.hostProvider, item); - } - } - - getAll () { - return utils.jsSetToJavaSet(this.items); - } -} - -class StaticCallbackItemProvider extends AbstractProvider { - constructor () { - super(ITEM_PROVIDER_CLASS); - this.itemsCallbacks = []; - } - - addProviderChangeListener (listener) { - } - - removeProviderChangeListener (listener) { - } - - addItemsCallback (callback) { - this.itemsCallbacks.push(callback); - } - - getAll () { - return utils.jsArrayToJavaList(this.itemsCallbacks.flatMap(c => c())); - } -} - -module.exports = { - /** - * Creates a new instance of class StaticItemProvider. - * @param {HostItem[]} items - * @returns {StaticItemProvider} - */ - staticItemProvider: (items) => new StaticItemProvider(items), - /** - * Creates a new instance of class ManagedItemProvider. - * @returns {ManagedItemProvider} - */ - managedItemProvider: () => new ManagedItemProvider(), - /** - * Creates a new instance of StaticCallbackItemProvider. - * @returns {StaticCallbackItemProvider} - */ - staticCallbackItemProvider: () => new StaticCallbackItemProvider() -}; diff --git a/items/items.js b/items/items.js index 361a9f3ad..669bef574 100644 --- a/items/items.js +++ b/items/items.js @@ -575,8 +575,6 @@ module.exports = { createItem, removeItem, Item, - /** @type {object} */ - provider: require('./items-provider'), /** * Custom indexer, to allow static Item lookup. * @example diff --git a/metadata/metadata-provider.js b/metadata/metadata-provider.js deleted file mode 100644 index 506ca558d..000000000 --- a/metadata/metadata-provider.js +++ /dev/null @@ -1,46 +0,0 @@ -const { AbstractProvider } = require('../provider'); -const utils = require('../utils'); - -const METADATA_PROVIDER_CLASS = 'org.openhab.core.items.MetadataProvider'; - -class StaticCallbackMetadataProvider extends AbstractProvider { - constructor () { - super(METADATA_PROVIDER_CLASS); - this.metadataCallbacks = []; - } - - addProviderChangeListener (listener) { - } - - removeProviderChangeListener (listener) { - } - - addMetadataCallback (callback) { - this.metadataCallbacks.push(callback); - } - - getAll () { - require('../log')('metadata-provider').debug('///' + this.metadataCallbacks.length); - require('../log')('metadata-provider').debug('///' + this.metadataCallbacks.flatMap(c => c()).length); - - for (const x of this.metadataCallbacks.flatMap(c => c())) { - require('../log')('metadata-provider').debug(x); - } - - return utils.jsArrayToJavaList(this.metadataCallbacks.flatMap(c => c())); - } -} - -/** - * Returns a new instance of StaticCallbackMetadataProvider. - * - * @private - * @returns {StaticCallbackMetadataProvider} - */ -const staticCallbackMetadataProvider = () => { - return new StaticCallbackMetadataProvider(); -}; - -module.exports = { - staticCallbackMetadataProvider -}; diff --git a/metadata/metadata.js b/metadata/metadata.js index 1d914cee6..bd9708197 100644 --- a/metadata/metadata.js +++ b/metadata/metadata.js @@ -70,6 +70,5 @@ module.exports = { addValue, updateValue, upsertValue, - provider: require('./metadata-provider'), itemchannellink: require('./itemchannellink') }; diff --git a/provider.js b/provider.js deleted file mode 100644 index 5f613b7e3..000000000 --- a/provider.js +++ /dev/null @@ -1,47 +0,0 @@ -const osgi = require('./osgi'); -const log = require('./log')('provider'); // eslint-disable-line no-unused-vars -// const utils = require('./utils'); - -function getAllFunctionNames (obj) { - let props = []; - let o = obj; - do { - props = props.concat(Object.getOwnPropertyNames(o)); - o = Object.getPrototypeOf(o); - } while (o.constructor.name !== 'AbstractProvider'); - - return props.filter(p => typeof obj[p] === 'function'); -} - -class AbstractProvider { - constructor (type) { - this.typeName = type.class.getName(); - this.JavaType = Java.extend(type);// require('@runtime/osgi').classutil.extend(type); - } - - register () { - const javaConfig = {}; - - const functionNamesToBind = getAllFunctionNames(this) - .filter(f => f !== 'constructor') - .filter(f => f !== 'javaType'); - - for (const fn of functionNamesToBind) { - javaConfig[fn] = this[fn].bind(this); - } - - const hostProvider = this.processHostProvider(new this.JavaType(javaConfig)); - - this.hostProvider = hostProvider; - - osgi.registerService(this.hostProvider, this.typeName); - } - - processHostProvider (hostProvider) { - return hostProvider; - } -} - -module.exports = { - AbstractProvider -}; diff --git a/types/items/items.d.ts b/types/items/items.d.ts index 7a599f388..eaa8401ec 100644 --- a/types/items/items.d.ts +++ b/types/items/items.d.ts @@ -319,6 +319,5 @@ export class Item { } import ItemHistory = require("./item-history"); import ItemSemantics = require("./item-semantics"); -export declare const provider: object; export declare function objects(): any; //# sourceMappingURL=items.d.ts.map \ No newline at end of file diff --git a/types/items/items.d.ts.map b/types/items/items.d.ts.map index 5d3d8137b..0960581ee 100644 --- a/types/items/items.d.ts.map +++ b/types/items/items.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"items.d.ts","sourceRoot":"","sources":["../../items/items.js"],"names":[],"mappings":";;;;;;;UAsBc,MAAM;;;;UACN,MAAM;;;;YACN,MAAM;;;;eACN,MAAM;;;;aACN,QAAQ;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OAGG;IACH,6DAIC;IAED;;;;;OAKG;IACH,mBAJW,kBAAgB,QAM1B;IAED;;;;;;OAMG;IACH,8BAJW,kBAAgB,GACd,OAAO,CAUnB;IAED;;;;;;OAMG;IACH,sEAkBC;IAED;;;;OAIG;IACH,0BAKC;IAED;;;;OAIG;IACH,yBAEC;IAED;;;;OAIG;IACH,kBAHW,kBAAgB,QAK1B;IAED;;;OAGG;IACH,2BAEC;IAED;;;OAGG;IACH,6CAIC;IAED;;;OAGG;IACH,gDAMC;IAED;;;OAGG;IACH,qBAEC;IAED;;;OAGG;IACH,qCAGC;IAED;;;OAGG;IACH,wCAKC;CACF;;;+BA8OY,MAAM;AAWR,uCAMP"} \ No newline at end of file +{"version":3,"file":"items.d.ts","sourceRoot":"","sources":["../../items/items.js"],"names":[],"mappings":";;;;;;;UAsBc,MAAM;;;;UACN,MAAM;;;;YACN,MAAM;;;;eACN,MAAM;;;;aACN,QAAQ;;;;WACR,QAAQ;;;;eACR,YAAa;;;;eACb,YAAY;;;;iBACZ,MAAM;;;;;;;;;;;;;;QAOoB,MAAM;YACC,OAAO,GAAxC,MAAM;;;;;;;QAEU,KAAK,GAArB,MAAM;QACU,MAAM;YACC,kBAAkB,GAAzC,MAAM;;;;;;;QAEc,KAAK,GAAzB,MAAM;;;AAigBpB;;;;;GAKG;AACH,gCAHW,MAAM,GACJ,MAAM,CAIa;AAlDhC;;;;;;GAMG;AACH,8BAJW,MAAM,kBACN,OAAO,GACL,IAAI,CAchB;AAED;;;;;GAKG;AACH,4BAFa,IAAI,EAAE,CAIlB;AAnJD;;;;;;;;;;;GAWG;AACH,oCALW,UAAU,GACR,IAAI,CA+BhB;AA8GD;;;;;;GAMG;AACH,sDAFa,IAAI,EAAE,CAIlB;AAxED;;;;;;;;;;;;;;GAcG;AACH,wCALW,UAAU,mBACR,IAAI,CAmBhB;AA5KD;;;;;;;;;;;;GAYG;AACH,uCALW,UAAU,GACR,IAAI,CA6ChB;AA2CD;;;;;;GAMG;AACH,2CAHW,iBAAe,GACb,OAAO,CAsCnB;AA3aD;;;;GAIG;AACH;IACE;;;;OAIG;IACH,+BAqBC;IAjBC;;;OAGG;IACH,kBAAsB;IAEtB;;;OAGG;IACH,SAFU,WAAW,CAEkB;IAEvC;;;OAGG;IACH,WAFU,aAAa,CAEoB;IAG7C;;;OAGG;IACH,mBAEC;IAED;;;OAGG;IACH,mBAEC;IAED;;;OAGG;IACH,oBAEC;IAED;;;OAGG;IACH,oBAEC;IAED;;;OAGG;IACH,0BAEC;IAED;;;OAGG;IACH,sBAEC;IAED;;;OAGG;IACH,0BAEC;IAED;;;;OAIG;IACH,+BASC;IAED;;;;OAIG;IACH,4BAHW,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;OAKG;IACH,+BAJW,MAAM,SACN,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;OAKG;IACH,+BAJW,MAAM,SACN,MAAM,GACJ,OAAO,CAInB;IAED;;;OAGG;IACH,6DAIC;IAED;;;;;OAKG;IACH,mBAJW,kBAAgB,QAM1B;IAED;;;;;;OAMG;IACH,8BAJW,kBAAgB,GACd,OAAO,CAUnB;IAED;;;;;;OAMG;IACH,sEAkBC;IAED;;;;OAIG;IACH,0BAKC;IAED;;;;OAIG;IACH,yBAEC;IAED;;;;OAIG;IACH,kBAHW,kBAAgB,QAK1B;IAED;;;OAGG;IACH,2BAEC;IAED;;;OAGG;IACH,6CAIC;IAED;;;OAGG;IACH,gDAMC;IAED;;;OAGG;IACH,qBAEC;IAED;;;OAGG;IACH,qCAGC;IAED;;;OAGG;IACH,wCAKC;CACF;;;AAuPU,uCAMP"} \ No newline at end of file diff --git a/types/metadata/metadata.d.ts b/types/metadata/metadata.d.ts index 060b1d139..d739109a5 100644 --- a/types/metadata/metadata.d.ts +++ b/types/metadata/metadata.d.ts @@ -20,6 +20,5 @@ export function updateValue(itemName: any, namespace: any, value: any, config: a * @returns {boolean} true if the value was added, false if it was updated */ export function upsertValue(itemName: string, namespace: string, value: string, config?: Map): boolean; -export declare const provider: typeof import("./metadata-provider"); export declare const itemchannellink: typeof import("./itemchannellink"); //# sourceMappingURL=metadata.d.ts.map \ No newline at end of file