Skip to content

Commit

Permalink
Merge pull request #80 from max-pfeiffer/release/v1-2-0
Browse files Browse the repository at this point in the history
Release/v1 2 0
  • Loading branch information
max-pfeiffer authored Jun 14, 2024
2 parents 54ee8aa + 1687e26 commit 77ab065
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 129 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.11
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.2
version: 1.8.3
virtualenvs-in-project: true
- name: Load cached virtual environment
id: cached-dependencies
Expand All @@ -40,11 +40,11 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.11
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.2
version: 1.8.3
virtualenvs-in-project: true
- name: Load cached venv
id: cached-dependencies
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
- id: check-added-large-files
args: ['--maxkb=1024']
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
rev: v0.4.8
hooks:
- id: ruff
args: ["--fix", "--exit-non-zero-on-fix", "--config", "pyproject.toml", "irrigation_pi", "backend"]
Expand Down
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ found in `/etc/nginx/sites-available/irrigation-pi` on your Raspberry Pi.
## Management CLI
Irrigation Pi comes with its own management CLI. With the CLI you can perform installation and configuration tasks
for the application and servers. Use the `--help` option to find out more about commands and usage.
You need to go to installation directory and activate the virtual Python environment before running the CLI.
```shell
raspberrypi: $ irrigation-pi --help
$ cd /srv/irrigation-pi
$ source .venv/bin/activate
$ irrigation-pi --help
Usage: irrigation-pi [OPTIONS] COMMAND [ARGS]...

Irrigation Pi command line interface (CLI).
Expand All @@ -120,7 +123,30 @@ Commands:
run Run commands.
uninstall Uninstall commands.
```
For instance, you can install and run a Wi-Fi hotspot with it. This is particularly useful when you run the
Raspberry Pi in your garden as an island solution:
```shell
$ sudo irrigation-pi install wifi-hotspot
```
Afterwards you can login on SSID Irrigation-Pi. Use `--help` to display more configuration options:
```shell
$ irrigation-pi install wifi-hotspot --help
Usage: irrigation-pi install wifi-hotspot [OPTIONS]

Install Wi-Fi hotspot using NetworkManager.

For more details see: https://networkmanager.dev/docs/api/latest/

Options:
--interface-name TEXT Name of the 802-11-wireless interface, i.e.
wlan0.
--ssid TEXT SSID of Wi-Fi Hotspot.
--password TEXT Password for Wi-Fi Hotspot, minimum length 8
characters. [required]
--autoconnect [on|off] Wi-Fi Hotspot autoconnect.
--autoconnect-priority TEXT Wi-Fi Hotspot autoconnect-priority.
--help Show this message and exit.
```
## Why another irrigation controller software for the Raspberry Pi?
First of all I was searching GitHub and the web for ready to use solutions. And I found a couple.
Some of them did not match my use case: I just want a simple and easy to use application for watering plants on my
Expand Down
2 changes: 2 additions & 0 deletions irrigation_pi/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@

HOST: str = "raspberrypi.local"
PORT: str = "80"

WIFI_HOTSPOT_CONNECTION_NAME: str = "Irrigation-Pi"
4 changes: 4 additions & 0 deletions irrigation_pi/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
install_debian_packages,
install_nginx_configuration,
install_systemd_configuration,
install_wifi_hotspot,
)
from irrigation_pi.restart import restart_nginx, restart_uvicorn
from irrigation_pi.run import backend, frontend
Expand All @@ -25,6 +26,7 @@
uninstall_database,
uninstall_nginx_configuration,
uninstall_systemd_configuration,
uninstall_wifi_hotspot,
)


Expand Down Expand Up @@ -54,6 +56,7 @@ def install():
install.add_command(install_database)
install.add_command(install_systemd_configuration)
install.add_command(install_nginx_configuration)
install.add_command(install_wifi_hotspot)


@click.group()
Expand All @@ -71,6 +74,7 @@ def uninstall():
uninstall.add_command(uninstall_database)
uninstall.add_command(uninstall_nginx_configuration)
uninstall.add_command(uninstall_systemd_configuration)
uninstall.add_command(uninstall_wifi_hotspot)


@click.group()
Expand Down
81 changes: 75 additions & 6 deletions irrigation_pi/install.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Install commands."""

# ruff: noqa: D205, D301, D400

from pathlib import Path
from shutil import chown

Expand All @@ -20,6 +22,7 @@
PORT,
SYSTEMD_CONFIG_PATH,
VIRTUAL_ENVIRONMENT_PATH,
WIFI_HOTSPOT_CONNECTION_NAME,
)
from irrigation_pi.utils import (
activate_virtual_environment,
Expand All @@ -34,7 +37,7 @@
@click.pass_context
def install_all(ctx: Context):
"""Install everything necessary to run the application on Raspberry Pi.
\f
:return:
"""
ctx.forward(install_debian_packages)
Expand All @@ -47,7 +50,7 @@ def install_all(ctx: Context):
@click.command(name="debian-packages")
def install_debian_packages():
"""Install Debian packages.
\f
:return:
"""
click.echo("Updating Debian package sources...")
Expand All @@ -62,7 +65,7 @@ def install_debian_packages():
@click.command(name="config")
def install_application_configuration():
"""Install irrigation-pi application configuration.
\f
:return:
"""
click.echo("Installing irrigation-pi application configuration...")
Expand All @@ -75,7 +78,7 @@ def install_application_configuration():
@click.command(name="database")
def install_database():
"""Install backend database.
\f
:return:
"""
click.echo("Installing database...")
Expand All @@ -95,7 +98,7 @@ def install_systemd_configuration():
https://systemd.io/
https://wiki.debian.org/systemd
https://wiki.debian.org/systemd/Services
\f
:return:
"""
click.echo("Installing Systemd configuration...")
Expand All @@ -118,7 +121,7 @@ def install_nginx_configuration():
"""Install nginx configuration.
See: https://nginx.org/en/docs/
\f
:return:
"""
# Create nginx config
Expand All @@ -139,3 +142,69 @@ def install_nginx_configuration():

# Reload nginx config
run_subprocess(["sudo", "systemctl", "reload", "nginx"])


@click.command(name="wifi-hotspot")
@click.option(
"--interface-name",
default="wlan0",
help="Name of the 802-11-wireless interface, i.e. wlan0.",
)
@click.option("--ssid", default="Irrigation-Pi", help="SSID of Wi-Fi Hotspot.")
@click.password_option(
required=True,
help="Password for Wi-Fi Hotspot, minimum length 8 characters.",
)
@click.option(
"--autoconnect",
default="on",
type=click.Choice(["on", "off"], case_sensitive=False),
help="Wi-Fi Hotspot autoconnect.",
)
@click.option(
"--autoconnect-priority", default="100", help="Wi-Fi Hotspot autoconnect-priority."
)
def install_wifi_hotspot(
interface_name: str,
ssid: str,
password: str,
autoconnect: str,
autoconnect_priority: str,
):
"""Install Wi-Fi hotspot using NetworkManager.
For more details see: https://networkmanager.dev/docs/api/latest/
\f
:return:
"""
click.echo("Installing Wi-Fi hotspot...")

# Configure Wi-Fi hotspot with NetworkManager
run_subprocess(
[
"sudo",
"nmcli",
"connection",
"add",
"con-name",
WIFI_HOTSPOT_CONNECTION_NAME,
"type",
"wifi",
"ifname",
interface_name,
"wifi.mode",
"ap",
"wifi.ssid",
ssid,
"wifi-sec.key-mgmt",
"wpa-psk",
"wifi-sec.psk",
password,
"ipv4.method",
"shared",
"connection.autoconnect",
autoconnect,
"connection.autoconnect-priority",
autoconnect_priority,
]
)
6 changes: 4 additions & 2 deletions irrigation_pi/restart.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Restart commands."""

# ruff: noqa: D205, D301, D400

import click

from irrigation_pi.utils import run_subprocess
Expand All @@ -8,7 +10,7 @@
@click.command(name="uvicorn")
def restart_uvicorn() -> None:
"""Restart Uvicorn server.
\f
:return:
"""
click.echo("Restarting Uvicorn server...")
Expand All @@ -19,7 +21,7 @@ def restart_uvicorn() -> None:
@click.command(name="nginx")
def restart_nginx() -> None:
"""Restart nginx server.
\f
:return:
"""
click.echo("Restarting nginx server...")
Expand Down
6 changes: 4 additions & 2 deletions irrigation_pi/run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Export commands."""

# ruff: noqa: D205, D301, D400

import click

from irrigation_pi.constants import (
Expand All @@ -16,7 +18,7 @@
@click.command()
def backend():
"""Run backend application.
\f
:return:
"""
click.echo("Running backend application...")
Expand All @@ -40,7 +42,7 @@ def backend():
@click.command()
def frontend():
"""Run frontend application.
\f
:return:
"""
click.echo("Running frontend application...")
Expand Down
29 changes: 24 additions & 5 deletions irrigation_pi/uninstall.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Uninstall commands."""

# ruff: noqa: D205, D301, D400

import click
from click import Context

Expand All @@ -9,6 +11,7 @@
NGINX_CONFIG_ACTIVATION_PATH,
NGINX_CONFIG_PATH,
SYSTEMD_CONFIG_PATH,
WIFI_HOTSPOT_CONNECTION_NAME,
)
from irrigation_pi.utils import (
run_subprocess,
Expand All @@ -19,7 +22,7 @@
@click.pass_context
def uninstall_all(ctx: Context):
"""Uninstall everything necessary to run the application on Raspberry Pi.
\f
:return:
"""
ctx.forward(uninstall_application_configuration)
Expand All @@ -31,7 +34,7 @@ def uninstall_all(ctx: Context):
@click.command(name="config")
def uninstall_application_configuration():
"""Uninstall irrigation-pi application configuration.
\f
:return:
"""
click.echo("Uninstalling irrigation-pi application configuration...")
Expand All @@ -41,7 +44,7 @@ def uninstall_application_configuration():
@click.command(name="database")
def uninstall_database():
"""Uninstall database.
\f
:return:
"""
click.echo("Uninstalling database...")
Expand All @@ -51,7 +54,7 @@ def uninstall_database():
@click.command(name="systemd-config")
def uninstall_systemd_configuration():
"""Uninstall systemd config.
\f
:return:
"""
click.echo("Uninstalling systemd configuration...")
Expand All @@ -68,7 +71,7 @@ def uninstall_systemd_configuration():
@click.command(name="nginx-config")
def uninstall_nginx_configuration():
"""Uninstall nginx configuration.
\f
:return:
"""
click.echo("Uninstalling nginx configuration...")
Expand All @@ -80,3 +83,19 @@ def uninstall_nginx_configuration():

# Reload nginx config
run_subprocess(["sudo", "systemctl", "reload", "nginx"])


@click.command(name="wifi-hotspot")
def uninstall_wifi_hotspot():
"""Uninstall Wi-Fi hotspot using NetworkManager.
For more details see: https://networkmanager.dev/docs/api/latest/
\f
:return:
"""
click.echo("Uninstalling Wi-Fi hotspot...")

# Delete Wi-Fi hotspot with NetworkManager
run_subprocess(
["sudo", "nmcli", "connection", "delete", WIFI_HOTSPOT_CONNECTION_NAME]
)
Loading

0 comments on commit 77ab065

Please sign in to comment.