Repository navigation
feat(node-red): run and pick any API energy command, gated on paired from the catalog #197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2d7e5e3
feat(node-red): run and pick any API energy command, gated on paired …
Bre77 2c6bede
refactor(node-red): keep the gateway command adapter out of the gatew…
Bre77 56753e8
fix(node-red): a Local gateway only unlocks the paired commands it takes
Bre77 98ac661
test(node-red): an unpaired catalog dispatch goes through a matching …
Bre77 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@teslemetry/node-red-contrib-teslemetry": minor | ||
| --- | ||
|
|
||
| The Energy Command node lists every Teslemetry API energy site command, with a field for each argument, and runs any of them from `msg.command` by its route name with its arguments in `msg.payload`. This adds backup events, gateway config and diagnostics. Commands that need a key the gateway trusts are offered for a site paired with Teslemetry or with a Local gateway, and backup reserve, operation mode, grid export, dispatch and island mode go to the Local gateway first. Nodes saved with an earlier command name keep working unchanged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import type { SiteCommands } from "./localPowerwall"; | ||
|
|
||
| type Body = Record<string, any>; | ||
|
|
||
| /** The gateway's positional arguments for an API command body, by API route name. */ | ||
| const LOCAL_ARGS: { [M in keyof SiteCommands]: (body: Body) => Parameters<SiteCommands[M]> } = { | ||
| backup: (b) => [b.backup_reserve_percent], | ||
| operation: (b) => [b.default_real_mode], | ||
| grid_import_export: (b) => [ | ||
| b.disallow_charge_from_grid_with_solar_installed ?? null, | ||
| b.customer_preferred_export_rule, | ||
| ], | ||
| dispatch_battery_power: (b) => [b.power_watts, b.duration_seconds], | ||
| resume_battery_operation: () => [], | ||
| set_island_mode: (b) => [b.mode, b.force ?? null], | ||
| }; | ||
|
|
||
| /** The gateway method and arguments for an API command, or undefined when the gateway does not take it. */ | ||
| export function localCommand( | ||
| name: string, | ||
| body: Body, | ||
| ): { method: keyof SiteCommands; args: unknown[] } | undefined { | ||
| if (!Object.prototype.hasOwnProperty.call(LOCAL_ARGS, name)) return undefined; | ||
| const method = name as keyof SiteCommands; | ||
| return { method, args: LOCAL_ARGS[method](body) }; | ||
| } | ||
|
|
||
| /** The API route names a gateway takes. */ | ||
| export const LOCAL_COMMANDS = new Set(Object.keys(LOCAL_ARGS)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.