Skip to content

Commit

Permalink
feat: add method to query supported RF regions (#6957)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Jun 24, 2024
1 parent 43735f8 commit ba71df5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/api/controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,14 @@ export enum RFRegion {
> [!ATTENTION] Not all controllers support configuring the RF region. These methods will throw if they are not supported
To determine which regions are supported by the current controller, use the following method:

```ts
getSupportedRFRegions(filterSubsets: boolean): MaybeNotKnown<readonly RFRegion[]>
```

The `filterSubsets` parameter (`true` by default) can be used to filter out regions that are subsets of other supported regions. For example, if the controller supports both `USA` and `USA (Long Range)`, only `USA (Long Range)` will be returned, since it includes the `USA` region.

#### Configure TX powerlevel

```ts
Expand Down
35 changes: 35 additions & 0 deletions packages/zwave-js/src/lib/controller/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6235,6 +6235,41 @@ ${associatedNodes.join(", ")}`,
return result.region;
}

/**
* Returns the RF regions supported by this controller, or `undefined` if the information is not known yet.
*
* @param filterSubsets Whether to exclude regions that are subsets of other regions,
* for example `USA` which is a subset of `USA (Long Range)`
*/
public getSupportedRFRegions(
filterSubsets: boolean = true,
): MaybeNotKnown<readonly RFRegion[]> {
// FIXME: Once supported in firmware, query the controller for supported regions instead of hardcoding
const ret = new Set([
// Always supported
RFRegion.Europe,
RFRegion.USA,
RFRegion["Australia/New Zealand"],
RFRegion["Hong Kong"],
RFRegion.India,
RFRegion.Israel,
RFRegion.Russia,
RFRegion.China,
RFRegion.Japan,
RFRegion.Korea,
RFRegion["Default (EU)"],
]);

if (this.isLongRangeCapable()) {
ret.add(RFRegion["USA (Long Range)"]);
if (filterSubsets) {
ret.delete(RFRegion.USA);
}
}

return [...ret].sort((a, b) => a - b);
}

/** Configure the Powerlevel setting of the Z-Wave API */
public async setPowerlevel(
powerlevel: number,
Expand Down

0 comments on commit ba71df5

Please sign in to comment.