Skip to content
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

Full refactoring of shell config handling w/o globals #15

Merged
merged 4 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 9 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ Welcome to the Wattpilot Shell 0.2. Type help or ? to list commands.

wattpilot> help

Documented commands (type help <topic>):
========================================
EOF exit ha info properties server unwatch watch
connect get help mqtt rawvalues set values
Documented commands (use 'help -v' for verbose/'help <topic>' for details):
===========================================================================
alias docs ha macro propset run_script shortcuts
config edit help mqtt quit server unwatch
connect EOF history properties rawvalues set values
disconnect exit info propget run_pyscript shell watch
```

The shell supports TAB-completion for all commands and their arguments.
Expand All @@ -49,8 +51,8 @@ It's also possible to pass a single command to the shell to integrate it into sc
wattpilotshell "<command> <args...>"

# Examples:
wattpilotshell "get amp"
wattpilotshell "set amp 6"
wattpilotshell "propget amp"
wattpilotshell "propset amp 6"
```

## MQTT Bridge Support
Expand Down Expand Up @@ -142,40 +144,7 @@ docker-compose run wattpilot shell

## Environment Variables

| Environment Variable | Description | Default Value |
| --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------- |
| `HA_ENABLED` | Enable Home Assistant Discovery | `false` |
| `HA_PROPERTIES` | Only discover given properties (leave unset for all properties having `homeAssistant` set in [wattpilot.yaml](src/wattpilot/ressources/wattpilot.yaml)) | |
| `HA_TOPIC_CONFIG` | Topic pattern for HA discovery config | `homeassistant/{component}/{uniqueId}/config` |
| `HA_WAIT_INIT_S` | Wait initial number of seconds after starting discovery (in addition to wait time depending on the number of properties). May be increased, if entities in HA are not populated with values. | `5` |
| `HA_WAIT_PROPS_MS` | Wait milliseconds per property after discovery before publishing property values. May be increased, if entities in HA are not populated with values. | `50` |
| `MQTT_AVAILABLE_PAYLOAD` | Payload for the availability topic in case the MQTT bridge is online | `online` |
| `MQTT_CLIENT_ID` | MQTT client ID | `wattpilot2mqtt` |
| `MQTT_ENABLED` | Enable MQTT | `false` |
| `MQTT_HOST` | MQTT host to connect to | |
| `MQTT_MESSAGES` | List of space-separated message types to be published to MQTT (leave unset for all messages) | |
| `MQTT_NOT_AVAILABLE_PAYLOAD` | Payload for the availability topic in case the MQTT bridge is offline (last will message) | `offline` |
| `MQTT_PASSWORD` | Password for connecting to MQTT | |
| `MQTT_PORT` | Port of the MQTT host to connect to | `1883` |
| `MQTT_PROPERTIES` | List of space-separated property names to publish changes for (leave unset for all properties) | |
| `MQTT_PUBLISH_MESSAGES` | Publish received Wattpilot messages to MQTT | `false` |
| `MQTT_PUBLISH_PROPERTIES` | Publish received property values to MQTT | `true` |
| `MQTT_TOPIC_AVAILABLE` | Topic pattern to publish Wattpilot availability status to | `{baseTopic}/available` |
| `MQTT_TOPIC_BASE` | Base topic for MQTT | `wattpilot` |
| `MQTT_TOPIC_MESSAGES` | Topic pattern to publish Wattpilot messages to | `{baseTopic}/messages/{messageType}` |
| `MQTT_TOPIC_PROPERTY_BASE` | Base topic for properties | `{baseTopic}/properties/{propName}` |
| `MQTT_TOPIC_PROPERTY_SET` | Topic pattern to listen for property value changes for | `~/set` |
| `MQTT_TOPIC_PROPERTY_STATE` | Topic pattern to publish property values to | `~/state` |
| `MQTT_USERNAME` | Username for connecting to MQTT | |
| `WATTPILOT_AUTOCONNECT` | Automatically connect to Wattpilot on startup | `true` |
| `WATTPILOT_AUTO_RECONNECT` | Automatically re-connect to Wattpilot on lost connections | `true` |
| `WATTPILOT_CONNECT_TIMEOUT` | Connect timeout for Wattpilot connection | `30` |
| `WATTPILOT_HOST` | IP address of the Wattpilot device to connect to | |
| `WATTPILOT_INIT_TIMEOUT` | Wait timeout for property initialization | `30` |
| `WATTPILOT_LOGLEVEL` | Log level (CRITICAL,ERROR,WARNING,INFO,DEBUG) | `INFO` |
| `WATTPILOT_PASSWORD` | Password for connecting to the Wattpilot device | |
| `WATTPILOT_RECONNECT_INTERVAL` | Waiting time in seconds before a lost connection is re-connected | `30` |
| `WATTPILOT_SPLIT_PROPERTIES` | Whether compound properties (e.g. JSON arrays or objects) should be decomposed into separate properties | `true` |
For a complete list of supported environment variables see [ShellEnvVariables.md](ShellEnvVariables.md).

## HELP improving API definition in wattpilot.yaml

Expand Down
67 changes: 48 additions & 19 deletions ShellCommands.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ See also:

```

## config

```bash
Show configuration values
Usage: config
```

## connect

```bash
Connect to Wattpilot (using WATTPILOT_* env variables)
Connect to Wattpilot
Usage: connect
```

Expand All @@ -37,6 +44,13 @@ Disconnect from Wattpilot
Usage: disconnect
```

## docs

```bash
Show markdown documentation for environment variables
Usage: docs
```

## edit

```bash
Expand All @@ -63,22 +77,6 @@ Exit the shell
Usage: exit
```

## get

```bash
Get a property value
Usage: get <propName>
```

## updateInverter

```bash
(un)pairs a connected inverter
Usage: updateInverter (pair|unpair) <inverterID>

<inverterID> is normally in the form 123.456789
```

## ha

```bash
Expand Down Expand Up @@ -228,6 +226,20 @@ List property definitions and values
Usage: properties [propRegex]
```

## propget

```bash
Get a property value
Usage: propget <propName>
```

## propset

```bash
Set a property value
Usage: propset <propName> <value>
```

## quit

```bash
Expand Down Expand Up @@ -296,8 +308,17 @@ Usage: server
## set

```bash
Set a property value
Usage: set <propName> <value>
Usage: set [-h] [param] [value]

Set a settable parameter or show current settings of parameters

positional arguments:
param parameter to set or view
value new value for settable

optional arguments:
-h, --help show this help message and exit

```

## shell
Expand Down Expand Up @@ -335,6 +356,14 @@ Unwatch a message or property
Usage: unwatch <event|message|property> <eventType|msgType|propName>
```

## UpdateInverter

```bash
Performs an Inverter Operation
Usage: updateInverter pair|unpair <inverterID>
<inverterID> is normally in the form 123.456789
```

## values

```bash
Expand Down
68 changes: 35 additions & 33 deletions ShellEnvVariables.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
# Wattpilot Shell Environment Variables

| Environment Variable | Default Value |
|----------------------|---------------|
| `HA_DISABLED_ENTITIES` | `false` |
| `HA_ENABLED` | `false` |
| `HA_PROPERTIES` | |
| `HA_TOPIC_CONFIG` | `homeassistant/{component}/{uniqueId}/config` |
| `HA_WAIT_INIT_S` | `0` |
| `HA_WAIT_PROPS_MS` | `0` |
| `MQTT_AVAILABLE_PAYLOAD` | `online` |
| `MQTT_CLIENT_ID` | `wattpilot2mqtt` |
| `MQTT_ENABLED` | `false` |
| `MQTT_HOST` | |
| `MQTT_MESSAGES` | |
| `MQTT_NOT_AVAILABLE_PAYLOAD` | `offline` |
| `MQTT_PORT` | `1883` |
| `MQTT_PROPERTIES` | |
| `MQTT_PUBLISH_MESSAGES` | `false` |
| `MQTT_PUBLISH_PROPERTIES` | `true` |
| `MQTT_TOPIC_AVAILABLE` | `{baseTopic}/available` |
| `MQTT_TOPIC_BASE` | `wattpilot` |
| `MQTT_TOPIC_MESSAGES` | `{baseTopic}/messages/{messageType}` |
| `MQTT_TOPIC_PROPERTY_BASE` | `{baseTopic}/properties/{propName}` |
| `MQTT_TOPIC_PROPERTY_SET` | `~/set` |
| `MQTT_TOPIC_PROPERTY_STATE` | `~/state` |
| `WATTPILOT_AUTOCONNECT` | `true` |
| `WATTPILOT_AUTO_RECONNECT` | `true` |
| `WATTPILOT_CONNECT_TIMEOUT` | `30` |
| `WATTPILOT_HOST` | |
| `WATTPILOT_INIT_TIMEOUT` | `30` |
| `WATTPILOT_LOGLEVEL` | `INFO` |
| `WATTPILOT_PASSWORD` | |
| `WATTPILOT_RECONNECT_INTERVAL` | `30` |
| `WATTPILOT_SPLIT_PROPERTIES` | `true` |
|Environment Variable|Type|Default Value|Description|
|--------------------|----|-------------|-----------|
|`HA_DISABLED_ENTITIES`|`boolean`|`false`|Create disabled entities in Home Assistant|
|`HA_ENABLED`|`boolean`|`false`|Enable Home Assistant Discovery|
|`HA_PROPERTIES`|`list`||List of space-separated properties that should be discovered by Home Assistant (leave unset for all properties having `homeAssistant` set in [wattpilot.yaml](src/wattpilot/ressources/wattpilot.yaml)|
|`HA_TOPIC_CONFIG`|`string`|`homeassistant/{component}/{uniqueId}/config`|Topic pattern for HA discovery config|
|`HA_WAIT_INIT_S`|`integer`|`0`|Wait initial number of seconds after starting discovery (in addition to wait time depending on the number of properties). May be increased, if entities in HA are not populated with values.|
|`HA_WAIT_PROPS_MS`|`integer`|`0`|Wait milliseconds per property after discovery before publishing property values. May be increased, if entities in HA are not populated with values.|
|`MQTT_AVAILABLE_PAYLOAD`|`string`|`online`|Payload for the availability topic in case the MQTT bridge is online|
|`MQTT_CLIENT_ID`|`string`|`wattpilot2mqtt`|MQTT client ID|
|`MQTT_ENABLED`|`boolean`|`false`|Enable MQTT|
|`MQTT_HOST`|`string`||MQTT host to connect to|
|`MQTT_MESSAGES`|`list`||List of space-separated message types to be published to MQTT (leave unset for all messages)|
|`MQTT_NOT_AVAILABLE_PAYLOAD`|`string`|`offline`|Payload for the availability topic in case the MQTT bridge is offline (last will message)|
|`MQTT_PASSWORD`|`password`||Password for connecting to MQTT|
|`MQTT_PORT`|`integer`|`1883`|Port of the MQTT host to connect to|
|`MQTT_PROPERTIES`|`list`||List of space-separated property names to publish changes for (leave unset for all properties)|
|`MQTT_PUBLISH_MESSAGES`|`boolean`|`false`|Publish received Wattpilot messages to MQTT|
|`MQTT_PUBLISH_PROPERTIES`|`boolean`|`true`|Publish received property values to MQTT|
|`MQTT_TOPIC_AVAILABLE`|`string`|`{baseTopic}/available`|Topic pattern to publish Wattpilot availability status to|
|`MQTT_TOPIC_BASE`|`string`|`wattpilot`|Base topic for MQTT|
|`MQTT_TOPIC_MESSAGES`|`string`|`{baseTopic}/messages/{messageType}`|Topic pattern to publish Wattpilot messages to|
|`MQTT_TOPIC_PROPERTY_BASE`|`string`|`{baseTopic}/properties/{propName}`|Base topic for properties|
|`MQTT_TOPIC_PROPERTY_SET`|`string`|`~/set`|Topic pattern to listen for property value changes for|
|`MQTT_TOPIC_PROPERTY_STATE`|`string`|`~/state`|Topic pattern to publish property values to|
|`MQTT_USERNAME`|`string`||Username for connecting to MQTT|
|`WATTPILOT_AUTOCONNECT`|`boolean`|`true`|Automatically connect to Wattpilot on startup|
|`WATTPILOT_AUTO_RECONNECT`|`boolean`|`true`|Automatically re-connect to Wattpilot on lost connections|
|`WATTPILOT_CONNECT_TIMEOUT`|`integer`|`30`|Connect timeout for Wattpilot connection|
|`WATTPILOT_HOST`|`string`||IP address of the Wattpilot device to connect to|
|`WATTPILOT_INIT_TIMEOUT`|`integer`|`30`|Wait timeout for property initialization|
|`WATTPILOT_LOGLEVEL`|`string`|`INFO`|Log level (CRITICAL,ERROR,WARNING,INFO,DEBUG)|
|`WATTPILOT_PASSWORD`|`password`||Password for connecting to the Wattpilot device|
|`WATTPILOT_RECONNECT_INTERVAL`|`integer`|`30`|Waiting time in seconds before a lost connection is re-connected|
|`WATTPILOT_SPLIT_PROPERTIES`|`boolean`|`true`|Whether compound properties (e.g. JSON arrays or objects) should be decomposed into separate properties|
Loading