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

Adds support for printer configuration #422

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 23 additions & 0 deletions grocy/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ or disabled:
- `shoppinglist`
- `stock`
- `tasks`
- `label_printer`
- `thermal_printer`

Set it `true` to enable it, `false` otherwise.

Expand Down Expand Up @@ -202,6 +204,27 @@ Allows you to specify a default ingress user if desired (e.g. `admin`).

If no ingress user is set, the default login authentication is used.

### Option: `Label Printer`

Allows posting to a webhook to print labels

- `label_printer_webhook` The URI that Grocy will POST to when asked to print a label
- `label_printer_run_server` Whether the webhook will be called server- or client-side
- `label_printer_params` Additional parameters supplied to the webhook
- `` TRUE to use JSON or FALSE to use normal POST request variables

### Option: `Thermal Printer`

Thermal printers are receipt printers, not regular printers,
the printer must support the ESC/POS protocol, see https://github.com/mike42/escpos-php
valadas marked this conversation as resolved.
Show resolved Hide resolved

- `tprinter_is_network_printer` Set to true if it's a network printer
- `tprinter_print_quantity_name` Set to false if you do not want to print the quantity names (related to the shopping list)
- `tprinter_print_notes` Set to false if you do not want to print notes (related to the shopping list)
- `tprinter_ip` IP of the network printer (does only matter if it's a network printer)
- `tprinter_port` Port of the network printer (does only matter if it's a network printer)
- `tprinter_connector` Printer device (does only matter if you use a locally attached printer) For USB on Linux this is often '/dev/usb/lp0', for serial printers it could be similar to '/dev/ttyS0' Make sure that the user that runs the webserver has permissions to write to the printer - on Linux add your webserver user to the LP group with usermod -a -G lp www-data

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update markdown formatting and refine the documentation for clarity.

- - `` TRUE to use JSON or FALSE to use normal POST request variables
+ - `label_printer_hook_json`: TRUE to use JSON or FALSE to use normal POST request variables

- the printer must support the ESC/POS protocol, see https://github.com/mike42/escpos-php
+ the printer must support the ESC/POS protocol, see [ESC/POS protocol](https://github.com/mike42/escpos-php)

- For USB on Linux this is often '/dev/usb/lp0', for serial printers it could be similar to '/dev/ttyS0' Make sure that the user that runs the webserver has permissions to write to the printer - on Linux add your webserver user to the LP group with usermod -a -G lp www-data
+ For USB on Linux, this is often '/dev/usb/lp0'. For serial printers, it could be similar to '/dev/ttyS0'. Ensure that the user who runs the webserver has permissions to write to the printer. On Linux, add your webserver user to the LP group with `usermod -a -G lp www-data`.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
### Option: `Label Printer`
Allows posting to a webhook to print labels
- `label_printer_webhook` The URI that Grocy will POST to when asked to print a label
- `label_printer_run_server` Whether the webhook will be called server- or client-side
- `label_printer_params` Additional parameters supplied to the webhook
- `` TRUE to use JSON or FALSE to use normal POST request variables
### Option: `Thermal Printer`
Thermal printers are receipt printers, not regular printers,
the printer must support the ESC/POS protocol, see https://github.com/mike42/escpos-php
- `tprinter_is_network_printer` Set to true if it's a network printer
- `tprinter_print_quantity_name` Set to false if you do not want to print the quantity names (related to the shopping list)
- `tprinter_print_notes` Set to false if you do not want to print notes (related to the shopping list)
- `tprinter_ip` IP of the network printer (does only matter if it's a network printer)
- `tprinter_port` Port of the network printer (does only matter if it's a network printer)
- `tprinter_connector` Printer device (does only matter if you use a locally attached printer) For USB on Linux this is often '/dev/usb/lp0', for serial printers it could be similar to '/dev/ttyS0' Make sure that the user that runs the webserver has permissions to write to the printer - on Linux add your webserver user to the LP group with usermod -a -G lp www-data
### Option: `Label Printer`
Allows posting to a webhook to print labels
- `label_printer_webhook` The URI that Grocy will POST to when asked to print a label
- `label_printer_run_server` Whether the webhook will be called server- or client-side
- `label_printer_params` Additional parameters supplied to the webhook
- `label_printer_hook_json`: TRUE to use JSON or FALSE to use normal POST request variables
### Option: `Thermal Printer`
Thermal printers are receipt printers, not regular printers,
the printer must support the ESC/POS protocol, see [ESC/POS protocol](https://github.com/mike42/escpos-php)
- `tprinter_is_network_printer` Set to true if it's a network printer
- `tprinter_print_quantity_name` Set to false if you do not want to print the quantity names (related to the shopping list)
- `tprinter_print_notes` Set to false if you do not want to print notes (related to the shopping list)
- `tprinter_ip` IP of the network printer (does only matter if it's a network printer)
- `tprinter_port` Port of the network printer (does only matter if it's a network printer)
- `tprinter_connector` Printer device (does only matter if you use a locally attached printer) For USB on Linux, this is often '/dev/usb/lp0'. For serial printers, it could be similar to '/dev/ttyS0'. Ensure that the user who runs the webserver has permissions to write to the printer. On Linux, add your webserver user to the LP group with `usermod -a -G lp www-data`.

## Known issues and limitations

- Grocy support to provide custom lookup resources to lookup information
Expand Down
14 changes: 14 additions & 0 deletions grocy/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ options:
shoppinglist: true
stock: true
tasks: true
label_printer: false
thermal_printer: false
tweaks:
chores_assignment: true
multiple_shopping_lists: true
Expand Down Expand Up @@ -60,6 +62,8 @@ schema:
shoppinglist: bool
stock: bool
tasks: bool
label_printer: bool
thermal_printer: bool
tweaks:
calendar_first_day_of_week: int(0,6)?
chores_assignment: bool
Expand All @@ -71,6 +75,16 @@ schema:
stock_product_freezing: bool
stock_product_opened_tracking: bool
stock_count_opened_products_against_minimum_stock_amount: bool
label_printer_webhook: str
label_printer_run_server: bool
label_printer_params: str
label_printer_hook_json: bool
tprinter_is_network_printer: bool
tprinter_print_quantity_name: bool
tprinter_print_notes: bool
tprinter_ip: str
tprinter_port: int(1,65535)?
tprinter_connector: str
ssl: bool
certfile: str
keyfile: str
Expand Down
58 changes: 58 additions & 0 deletions grocy/rootfs/etc/s6-overlay/s6-rc.d/php-fpm/run
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
# ==============================================================================
declare caldayweek
declare mealday
declare label_printer_webhook
declare label_printer_params
declare tprinter_ip
declare tprinter_port
declare tprinter_connector
export GROCY_CULTURE
export GROCY_CURRENCY
export GROCY_ENTRY_PAGE
Expand Down Expand Up @@ -44,6 +49,14 @@ if bashio::config.false 'features.tasks'; then
export GROCY_FEATURE_FLAG_TASKS=0
fi

if bashio::config.true 'features.label_printer'; then
export GROCY_FEATURE_FLAG_LABEL_PRINTER=1
fi

if bashio::config.true 'features.thermal_printer'; then
export FEATURE_FLAG_THERMAL_PRINTER=1
fi

if bashio::config.has_value 'tweaks.calendar_first_day_of_week'; then
caldayweek=$(bashio::config 'tweaks.calendar_first_day_of_week')
export GROCY_CALENDAR_FIRST_DAY_OF_WEEK=${caldayweek}
Expand Down Expand Up @@ -86,6 +99,51 @@ if bashio::config.false 'tweaks.stock_count_opened_products_against_minimum_stoc
export GROCY_FEATURE_SETTING_STOCK_COUNT_OPENED_PRODUCTS_AGAINST_MINIMUM_STOCK_AMOUNT=0
fi

if bashio::config.has_value 'tweaks.label_printer_webhook'; then
label_printer_webhook=$(bashio::config 'tweaks.label_printer_webhook')
export GROCY_MEAL_PLAN_FIRST_DAY_OF_WEEK=${label_printer_webhook}
fi

if bashio::config.false 'tweaks.label_printer_run_server'; then
export GROCY_LABEL_PRINTER_RUN_SERVER=0
fi

if bashio::config.has_value 'tweaks.label_printer_params'; then
label_printer_params=$(bashio::config 'tweaks.label_printer_params')
export GROCY_LABEL_PRINTER_PARAMS=${label_printer_params}
fi

if bashio::config.true 'tweaks.label_printer_hook_json'; then
export GROCY_LABEL_PRINTER_HOOK_JSON=1
fi

if bashio::config.true 'tweaks.tprinter_is_network_printer'; then
export GROCY_TPRINTER_IS_NETWORK_PRINTER=1
fi

if bashio::config.false 'tweaks.tprinter_print_quantity_name'; then
export GROCY_TPRINTER_PRINT_QUANTITY_NAME=0
fi

if bashio::config.false 'tweaks.tprinter_print_notes'; then
export GROCY_TPRINTER_PRINT_NOTES=0
fi

if bashio::config.has_value 'tweaks.tprinter_ip'; then
tprinter_ip=$(bashio::config 'tweaks.tprinter_ip')
export GROCY_TPRINTER_IP=${tprinter_ip}
fi

if bashio::config.has_value 'tweaks.tprinter_port'; then
tprinter_ip=$(bashio::config 'tweaks.tprinter_port')
export GROCY_TPRINTER_PORT=${tprinter_port}
valadas marked this conversation as resolved.
Show resolved Hide resolved
fi

if bashio::config.has_value 'tweaks.tprinter_connector'; then
tprinter_connector=$(bashio::config 'tweaks.tprinter_connector')
export GROCY_TPRINTER_CONNECTOR=${tprinter_connector}
fi
Copy link

@coderabbitai coderabbitai bot May 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The handling of printer configuration values and their export as environment variables is well-implemented. However, there seems to be a copy-paste error on line 104 where GROCY_MEAL_PLAN_FIRST_DAY_OF_WEEK is mistakenly set to label_printer_webhook. This should be corrected.

- export GROCY_MEAL_PLAN_FIRST_DAY_OF_WEEK=${label_printer_webhook}
+ export GROCY_LABEL_PRINTER_WEBHOOK=${label_printer_webhook}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if bashio::config.has_value 'tweaks.label_printer_webhook'; then
label_printer_webhook=$(bashio::config 'tweaks.label_printer_webhook')
export GROCY_MEAL_PLAN_FIRST_DAY_OF_WEEK=${label_printer_webhook}
fi
if bashio::config.false 'tweaks.label_printer_run_server'; then
export GROCY_LABEL_PRINTER_RUN_SERVER=0
fi
if bashio::config.has_value 'tweaks.label_printer_params'; then
label_printer_params=$(bashio::config 'tweaks.label_printer_params')
export GROCY_LABEL_PRINTER_PARAMS=${label_printer_params}
fi
if bashio::config.true 'tweaks.label_printer_hook_json'; then
export GROCY_LABEL_PRINTER_HOOK_JSON=1
fi
if bashio::config.true 'tweaks.tprinter_is_network_printer'; then
export GROCY_TPRINTER_IS_NETWORK_PRINTER=1
fi
if bashio::config.false 'tweaks.tprinter_print_quantity_name'; then
export GROCY_TPRINTER_PRINT_QUANTITY_NAME=0
fi
if bashio::config.false 'tweaks.tprinter_print_notes'; then
export GROCY_TPRINTER_PRINT_NOTES=0
fi
if bashio::config.has_value 'tweaks.tprinter_ip'; then
tprinter_ip=$(bashio::config 'tweaks.tprinter_ip')
export GROCY_TPRINTER_IP=${tprinter_ip}
fi
if bashio::config.has_value 'tweaks.tprinter_port'; then
tprinter_ip=$(bashio::config 'tweaks.tprinter_port')
export GROCY_TPRINTER_PORT=${tprinter_port}
fi
if bashio::config.has_value 'tweaks.tprinter_connector'; then
tprinter_connector=$(bashio::config 'tweaks.tprinter_connector')
export GROCY_TPRINTER_CONNECTOR=${tprinter_connector}
fi
if bashio::config.has_value 'tweaks.label_printer_webhook'; then
label_printer_webhook=$(bashio::config 'tweaks.label_printer_webhook')
export GROCY_LABEL_PRINTER_WEBHOOK=${label_printer_webhook}
fi
if bashio::config.false 'tweaks.label_printer_run_server'; then
export GROCY_LABEL_PRINTER_RUN_SERVER=0
fi
if bashio::config.has_value 'tweaks.label_printer_params'; then
label_printer_params=$(bashio::config 'tweaks.label_printer_params')
export GROCY_LABEL_PRINTER_PARAMS=${label_printer_params}
fi
if bashio::config.true 'tweaks.label_printer_hook_json'; then
export GROCY_LABEL_PRINTER_HOOK_JSON=1
fi
if bashio::config.true 'tweaks.tprinter_is_network_printer'; then
export GROCY_TPRINTER_IS_NETWORK_PRINTER=1
fi
if bashio::config.false 'tweaks.tprinter_print_quantity_name'; then
export GROCY_TPRINTER_PRINT_QUANTITY_NAME=0
fi
if bashio::config.false 'tweaks.tprinter_print_notes'; then
export GROCY_TPRINTER_PRINT_NOTES=0
fi
if bashio::config.has_value 'tweaks.tprinter_ip'; then
tprinter_ip=$(bashio::config 'tweaks.tprinter_ip')
export GROCY_TPRINTER_IP=${tprinter_ip}
fi
if bashio::config.has_value 'tweaks.tprinter_port'; then
tprinter_ip=$(bashio::config 'tweaks.tprinter_port')
export GROCY_TPRINTER_PORT=${tprinter_port}
fi
if bashio::config.has_value 'tweaks.tprinter_connector'; then
tprinter_connector=$(bashio::config 'tweaks.tprinter_connector')
export GROCY_TPRINTER_CONNECTOR=${tprinter_connector}
fi

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in last commit

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@valadas, thanks for addressing the issue in your last commit! Everything looks good now.


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!


GROCY_CULTURE=$(bashio::config "culture")
GROCY_CURRENCY=$(bashio::config "currency")
GROCY_ENTRY_PAGE=$(bashio::config 'entry_page')
Expand Down