Skip to content

Commit

Permalink
v2 rework to promises
Browse files Browse the repository at this point in the history
  • Loading branch information
foxriver76 committed Mar 13, 2024
1 parent 01be2dc commit 591b1fc
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 238 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ The configuration here is enhanced by an "enabled" key and passed to the "init"
One example is the Sentry plugin available at https://github.com/ioBroker/plugin-sentry

## Changelog
### 2.0.0 (2024-03-13)
**Breaking Changes:**
* (foxriver76) Methods no longer work with callback, please check the methods according to the types.
* (foxriver76) All methods with `async` postfix are now working renamed to methods without the postfix
while the callback methods have been removed
* (foxriver76) Renamed `instanciatePlugin` to `instantiatePlugin`
* (foxriver76) renamed `isPluginInstanciated` to `isPluginInstantiated`

### 1.2.1 (2021-01-24)
* (Apollon77) Add error handling in some places when setting active Status
Expand Down
65 changes: 11 additions & 54 deletions lib/PluginBase.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ declare class PluginBase {
pluginScope: "adapter" | "controller";
parentNamespace: string;
pluginNamespace: string;
log: import("./NamespaceLogger");
log: NamespaceLogger;
iobrokerConfig: Record<string, any>;
parentPackage: Record<string, any>;
settings: import("@iobroker/plugin-base/types").PluginSettings;
Expand All @@ -29,95 +29,53 @@ declare class PluginBase {
* Method for Plugin developer to initialize his Plugin
*
* @param {Record<string, any>} pluginConfig plugin configuration from config files
* @param {import("@iobroker/plugin-base/types").InitCallback} callback Will be called when done. On err or `initSuccessful === false` the plugin instance will be discarded.
* @return {Promise<void>} resolves if init was successful else rejects
*/
init(pluginConfig: Record<string, any>, callback: import("@iobroker/plugin-base/types").InitCallback): void;
init(pluginConfig: Record<string, any>): Promise<void>;
/**
* Method which is called on a clean end of the process to pot. clean up used resources
*
* @return {boolean} The return value indicates if the exit was successful. If no action needs to be taken, you should return true.
*/
destroy(): boolean;
/**
* Get a State from State DB
*
* @param {string} id id of the state to retrieve
* @param {ioBroker.GetStateCallback} callback Will be called with the result
*/
getState(id: string, callback: ioBroker.GetStateCallback): void;
/**
* Get a State from State DB
*
* @param {string} id id of the state to retrieve
* @return {ReturnType<ioBroker.Adapter["getStateAsync"]>} Promise with error or result
*/
getStateAsync(id: string): Promise<ioBroker.State>;
/**
* Set a State in State DB
*
* @param {string} id id of the state to set
* @param {Partial<ioBroker.State>} state state value to set
* @param {ioBroker.SetStateCallback} [callback] Will be called with the result
*/
setState(id: string, state: Partial<ioBroker.State>, callback?: ioBroker.SetStateCallback): void;
getState(id: string): ReturnType<ioBroker.Adapter["getStateAsync"]>;
/**
* Set a State in State DB
*
* @param {string} id id of the state to set
* @param {Partial<ioBroker.State>} state state value to set
* @return {Promise<ioBroker.State | null | undefined>} Promise with error or result
*/
setStateAsync(id: string, state: Partial<ioBroker.State>): Promise<ioBroker.State>;
/**
* Get an Object from Objects DB
*
* @param {string} id id of the object to retrieve
* @param {ioBroker.GetObjectCallback} callback Will be called with the result
*/
getObject(id: string, callback: ioBroker.GetObjectCallback): void;
setState(id: string, state: Partial<ioBroker.State>): Promise<ioBroker.State | null | undefined>;
/**
* Get an Object from Objects DB
*
* @param {string} id id of the object to retrieve
* @return {Promise<ioBroker.Object | null | undefined>} Promise with result or error
*/
getObjectAsync(id: string): Promise<ioBroker.Object>;
/**
* Set an Object in Objects DB
*
* @param {string} id id of the object to set
* @param {ioBroker.Object} obj object to set
* @param {ioBroker.SetObjectCallback} [callback] Will be called with the result
*/
setObject(id: string, obj: ioBroker.Object, callback?: ioBroker.SetObjectCallback): void;
getObject(id: string): Promise<ioBroker.Object | null | undefined>;
/**
* Set an Object in Objects DB
*
* @param {string} id id of the object to set
* @param {ioBroker.Object} obj object to set
* @return {ReturnType<ioBroker.Adapter["setObjectAsync"]>} Promise with error or result
*/
setObjectAsync(id: string, obj: ioBroker.Object): Promise<{
id: string;
}>;
/**
* Set/Extend an Object in Objects DB
*
* @param {string} id id of the object to set/extend
* @param {ioBroker.Object} obj object to set
* @param {ioBroker.ExtendObjectCallback} [callback] Will be called with the result
*/
extendObject(id: string, obj: ioBroker.Object, callback?: ioBroker.ExtendObjectCallback): void;
setObject(id: string, obj: ioBroker.Object): ReturnType<ioBroker.Adapter["setObjectAsync"]>;
/**
* Set/Extend an Object in Objects DB
*
* @param {string} id id of the object to set/extend
* @param {object} obj object to set
* @return {ReturnType<ioBroker.Adapter["extendObjectAsync"]>} Promise with result or error
*/
extendObjectAsync(id: string, obj: any): Promise<{
id: string;
}>;
extendObject(id: string, obj: object): ReturnType<ioBroker.Adapter["extendObjectAsync"]>;
/****************************************
* Internal methods!!
****************************************/
Expand All @@ -143,15 +101,14 @@ declare class PluginBase {
*
* @param {Record<string, any>} pluginConfig plugin configuration from config files
* @param {Record<string, any>} parentConfig io-package from parent module where plugin is used in
* @param {import("@iobroker/plugin-base/types").InitCallback} callback Will be called when done. On err or `initSuccessful === false` the plugin instance will be discarded.
*/
initPlugin(pluginConfig: Record<string, any>, parentConfig: Record<string, any>, callback: import("@iobroker/plugin-base/types").InitCallback): Promise<void>;
initPlugin(pluginConfig: Record<string, any>, parentConfig: Record<string, any>): Promise<void>;
parentIoPackage: Record<string, any>;
/**
* @internal
* @param {Record<string, any>} pluginConfig
* @param {string | boolean} activate
* @param {import("@iobroker/plugin-base/types").InitCallback} callback
*/
_initialize(pluginConfig: Record<string, any>, activate: string | boolean, callback: import("@iobroker/plugin-base/types").InitCallback): Promise<void>;
_initialize(pluginConfig: Record<string, any>, activate: string | boolean): Promise<void>;
}
import NamespaceLogger = require("./NamespaceLogger");
Loading

0 comments on commit 591b1fc

Please sign in to comment.