Skip to content

Commit

Permalink
Merge pull request #188 from mmirate/eta
Browse files Browse the repository at this point in the history
Add support for showing absolute ETA
  • Loading branch information
cameroncros committed May 24, 2021
2 parents 8aca974 + 9601e55 commit 3f83e08
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ See the following link for instructions on how to setup a Discord bot:

- The Channel ID is the ID of the TEXT channel within the Discord Server that the bot is communicating with, not the Discord Server.
- When following (https://github.com/Chikachi/DiscordIntegration/wiki/How-to-get-a-token-and-channel-ID-for-Discord), STOP after "Get the channel ID of the Discord text channel" section. Everything else is not needed on that page.
- OAuth2 permissions are not necessary.
- OAuth2 permissions are not necessary.
- If you reinstall your Octoprint system, you only need the bot token and channel ID to get it back up and running.

## API
Expand Down Expand Up @@ -115,9 +115,15 @@ If you don't receive it, something is most likely wrong!
### Access Settings

The access settings allow specific commands to be limited to specific users.
- In the commands section, put a comma-separated list of commands.
- In the users section, put a comma-separated list of user IDs.
- A '*' in either section can be used to match all commands/users.
* In the commands section, put a comma-separated list of commands.
* Check out [this wiki page](https://github.com/cameroncros/OctoPrint-DiscordRemote/wiki/Default-Commands,-Parameters-and-Description) for the list of commands
* The command list should look like "help, status, snapshot, mute, unmute" and is useful for tailoring access to any other users you might invite to avoid them issuing a command like /abort!
* In the users section, put a comma-separated list of user IDs.
* The user ID needs to be the numerical form, which is a number like: 165259232034275409
* In a text channel, find a message sent by you (or send one) and then right-click your name over that message and click "Copy ID"
* Or, join a voice channel, and then right-click your name in the sidebar, and click "Copy ID"
* The text user ID (like "MyUser" or "MyUser#1234") will result in "Permission Denied" responses to commands.
* A '*' in either section can be used to match all commands/users.

If the current command and user combination matches any of the rules, it will be executed.
If additional rules are required, manually editing the config will be required.
Expand Down Expand Up @@ -148,6 +154,7 @@ Some events also support variables, here is a basic list :
- `{externaddr}` : the external IP address of the OctoPrint server
- `{timeremaining}` : the time remaining for the print ('Unknown' if the print is not running)
- `{timespent}` : the time spent so far on the print
- `{eta}` : the date+time which is `{timeremaining}` into the future

**Printing process : started event** :
- `{name}` : file's name that's being printed
Expand Down
12 changes: 12 additions & 0 deletions octoprint_discordremote/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ def notify_event(self, event_id, data=None):
data['externaddr'] = self.get_external_ip_address()
data['timeremaining'] = self.get_print_time_remaining()
data['timespent'] = self.get_print_time_spent()
data['eta'] = self.get_print_eta()

# Special case for progress eventID : we check for progress and steps
if event_id == 'printing_progress':
Expand Down Expand Up @@ -620,6 +621,17 @@ def get_print_time_remaining(self):
except (KeyError, ValueError):
return 'Unknown'

def get_print_eta(self):
current_data = self._printer.get_current_data()
try:
remaining_time_val = current_data['progress']['printTimeLeft']
return (
(datetime.now() + timedelta(seconds=remaining_time_val))
.isoformat(' ', 'minutes')
)
except (KeyError, ValueError):
return 'Unknown'

def start_periodic_reporting(self):
self.stop_periodic_reporting()
self.last_progress_percent = 0
Expand Down
3 changes: 2 additions & 1 deletion octoprint_discordremote/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,14 @@ def status(self):
printing = self.plugin.get_printer().is_printing()
builder.add_field(title='Printing', text='Yes' if printing else 'No', inline=True)
if printing:
builder.add_field(title='File', text=current_data['job']['file']['name'], inline=True)
builder.add_field(title='File', text=f"`{current_data['job']['file']['name']}`", inline=True)
completion = current_data['progress']['completion']
if completion:
builder.add_field(title='Progress', text='%d%%' % completion, inline=True)

builder.add_field(title='Time Spent', text=self.plugin.get_print_time_spent(), inline=True)
builder.add_field(title='Time Remaining', text=self.plugin.get_print_time_remaining(), inline=True)
builder.add_field(title='ETA', text=self.plugin.get_print_eta(), inline=True)

try:
cmd_response = subprocess.Popen(['vcgencmd', 'get_throttled'], stdout=subprocess.PIPE).communicate()
Expand Down
2 changes: 1 addition & 1 deletion octoprint_discordremote/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def handle_heartbeat_ack(self):
if self.status_callback:
self.status_callback(connected="connected")
if self.error_counter > 0:
self.error_counter -= 0
self.error_counter = 0
self.heartbeat_sent = 0
self.process_queue()

Expand Down

0 comments on commit 3f83e08

Please sign in to comment.