Skip to content

Commit

Permalink
[items] Fix type def issues due to private method in Item class (#394)
Browse files Browse the repository at this point in the history
Private methods are not supported by .d.ts type declarations, so do not
use them!

Refs #392.

Signed-off-by: Florian Hotze <[email protected]>
  • Loading branch information
florian-h05 authored Nov 3, 2024
1 parent 1c7399b commit 0ec2f5e
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 12 deletions.
2 changes: 2 additions & 0 deletions build/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Change this to match your project
"include": ["../src/**/*.js"],
"exclude": [
"../src/helpers.js",
"../src/index.js",
"../test/**",
"../coverage/**",
"../dist/**",
Expand Down
8 changes: 4 additions & 4 deletions src/items/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,11 @@ class Item {
* Calculates the toggled state of this Item.
* For Items like Color and Dimmer, getStateAs(OnOffType) is used and the toggle calculated of that.
*
* @private
* @ignore
* @returns the toggled state (e.g. 'OFF' if the Item is 'ON')
* @throws error if the Item is uninitialized or is a type that doesn't make sense to toggle
*/
#getToggleState () {
getToggleState () {
if (this.isUninitialized) {
throw Error('Cannot toggle uninitialized Items');
}
Expand Down Expand Up @@ -366,7 +366,7 @@ class Item {
if (this.type === 'Contact') {
throw Error('Cannot command Contact Items');
}
this.sendCommand(this.#getToggleState());
this.sendCommand(this.getToggleState());
}

/**
Expand All @@ -375,7 +375,7 @@ class Item {
* @throws error if the Item is uninitialized or a type that cannot be toggled
*/
postToggleUpdate () {
this.postUpdate(this.#getToggleState());
this.postUpdate(this.getToggleState());
}

/**
Expand Down
10 changes: 9 additions & 1 deletion types/items/items.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,15 @@ export class Item {
* @return {boolean} true if the command was sent, false otherwise
*/
sendDecreaseCommand(value: number | Quantity | HostState): boolean;
/**
* Calculates the toggled state of this Item.
* For Items like Color and Dimmer, getStateAs(OnOffType) is used and the toggle calculated of that.
*
* @ignore
* @returns the toggled state (e.g. 'OFF' if the Item is 'ON')
* @throws error if the Item is uninitialized or is a type that doesn't make sense to toggle
*/
getToggleState(): "PAUSE" | "PLAY" | "OPEN" | "CLOSED" | "ON" | "OFF";
/**
* Sends a command to flip the Item's state (e.g. if it is 'ON' an 'OFF' command is sent).
* @throws error if the Item is uninitialized or a type that cannot be toggled or commanded
Expand Down Expand Up @@ -317,7 +326,6 @@ export class Item {
*/
removeTags(...tagNames: string[]): void;
toString(): any;
#private;
}
import metadata = require("./metadata/metadata");
import TimeSeries = require("./time-series");
Expand Down
2 changes: 1 addition & 1 deletion types/items/items.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion types/items/metadata/itemchannellink.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type Item = {
sendCommandIfDifferent(value: any): boolean;
sendIncreaseCommand(value: any): boolean;
sendDecreaseCommand(value: any): boolean;
"__#6@#getToggleState"(): "PAUSE" | "PLAY" | "OPEN" | "CLOSED" | "ON" | "OFF";
getToggleState(): "PAUSE" | "PLAY" | "OPEN" | "CLOSED" | "ON" | "OFF";
sendToggleCommand(): void;
postToggleUpdate(): void;
postUpdate(value: any): void;
Expand Down
2 changes: 1 addition & 1 deletion types/items/metadata/metadata.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type Item = {
sendCommandIfDifferent(value: any): boolean;
sendIncreaseCommand(value: any): boolean;
sendDecreaseCommand(value: any): boolean;
"__#6@#getToggleState"(): "PAUSE" | "PLAY" | "OPEN" | "CLOSED" | "ON" | "OFF";
getToggleState(): "PAUSE" | "PLAY" | "OPEN" | "CLOSED" | "ON" | "OFF";
sendToggleCommand(): void;
postToggleUpdate(): void;
postUpdate(value: any): void;
Expand Down
2 changes: 1 addition & 1 deletion types/quantity.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type Item = {
sendCommandIfDifferent(value: any): boolean;
sendIncreaseCommand(value: any): boolean;
sendDecreaseCommand(value: any): boolean;
"__#6@#getToggleState"(): "PAUSE" | "PLAY" | "OPEN" | "CLOSED" | "ON" | "OFF";
getToggleState(): "PAUSE" | "PLAY" | "OPEN" | "CLOSED" | "ON" | "OFF";
sendToggleCommand(): void;
postToggleUpdate(): void;
postUpdate(value: any): void;
Expand Down
2 changes: 1 addition & 1 deletion types/rules/operation-builder.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type Item = {
sendCommandIfDifferent(value: any): boolean;
sendIncreaseCommand(value: any): boolean;
sendDecreaseCommand(value: any): boolean;
"__#6@#getToggleState"(): "PAUSE" | "PLAY" | "OPEN" | "CLOSED" | "ON" | "OFF";
getToggleState(): "PAUSE" | "PLAY" | "OPEN" | "CLOSED" | "ON" | "OFF"; /** @private */
sendToggleCommand(): void;
postToggleUpdate(): void;
postUpdate(value: any): void;
Expand Down
2 changes: 1 addition & 1 deletion types/rules/operation-builder.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion types/triggers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type Item = {
sendCommandIfDifferent(value: any): boolean;
sendIncreaseCommand(value: any): boolean;
sendDecreaseCommand(value: any): boolean;
"__#6@#getToggleState"(): "PAUSE" | "PLAY" | "OPEN" | "CLOSED" | "ON" | "OFF";
getToggleState(): "PAUSE" | "PLAY" | "OPEN" | "CLOSED" | "ON" | "OFF";
sendToggleCommand(): void;
postToggleUpdate(): void;
postUpdate(value: any): void;
Expand Down

0 comments on commit 0ec2f5e

Please sign in to comment.