Skip to content

Commit

Permalink
feat: use pod_id as the ssid of the wifi hotspot
Browse files Browse the repository at this point in the history
  • Loading branch information
sassanh committed Jan 13, 2025
1 parent a2b471c commit ea79a73
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- fix: add ".local" to hostname in users menus - closes #134
- fix: use stdout instead of stderr for reading rpi-connect process output - closes #174
- feat: setup a wifi hotspot for when the a web-ui input is demanded and the device is not connected to any network - closes #169
- feat: use `pod_id` as the ssid of the wifi hotspot

## Version 1.1.0

Expand Down
1 change: 1 addition & 0 deletions ubo_app/logging.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# noqa: A005, FIX002 # TODO(@sassanh): remove A105 when fix is merged
# ruff: noqa: D100, D101, D102, D103, D104, D107
from __future__ import annotations

Expand Down
6 changes: 4 additions & 2 deletions ubo_app/system/system_manager/hotspot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import pathlib
import subprocess

Check warning on line 4 in ubo_app/system/system_manager/hotspot.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/system/system_manager/hotspot.py#L3-L4

Added lines #L3 - L4 were not covered by tests

from ubo_app.utils.pod_id import get_pod_id

Check warning on line 6 in ubo_app/system/system_manager/hotspot.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/system/system_manager/hotspot.py#L6

Added line #L6 was not covered by tests


def hotspot_handler(desired_state: str) -> None:

Check warning on line 9 in ubo_app/system/system_manager/hotspot.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/system/system_manager/hotspot.py#L9

Added line #L9 was not covered by tests
"""Set up a hotspot on the UBO."""
Expand All @@ -15,9 +17,9 @@ def hotspot_handler(desired_state: str) -> None:
f.write("""interface=wlan0

Check warning on line 17 in ubo_app/system/system_manager/hotspot.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/system/system_manager/hotspot.py#L16-L17

Added lines #L16 - L17 were not covered by tests
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h""")
with pathlib.Path('/etc/hostapd/hostapd.conf').open('w') as f:
f.write("""interface=wlan0
f.write(f"""interface=wlan0

Check warning on line 20 in ubo_app/system/system_manager/hotspot.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/system/system_manager/hotspot.py#L19-L20

Added lines #L19 - L20 were not covered by tests
driver=nl80211
ssid=UBO
ssid={get_pod_id()}
hw_mode=g
channel=7
wpa=2
Expand Down
10 changes: 4 additions & 6 deletions ubo_app/system/system_manager/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from ubo_app.system.system_manager.service_manager import service_handler
from ubo_app.system.system_manager.users import users_handler
from ubo_app.utils.eeprom import read_serial_number
from ubo_app.utils.pod_id import get_pod_id, set_pod_id

Check warning on line 33 in ubo_app/system/system_manager/main.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/system/system_manager/main.py#L33

Added line #L33 was not covered by tests

SOCKET_PATH = Path(os.environ.get('RUNTIME_DIRECTORY', '/run/ubo')).joinpath(
'system_manager.sock',
Expand Down Expand Up @@ -96,7 +97,6 @@ def process_request(command: bytes, connection: socket.socket) -> None:
def setup_hostname() -> None:
"""Set the hostname to 'ubo'."""
logger.info('Setting hostname...')
from ubo_app.constants import INSTALLATION_PATH

thread = Thread(target=check_connection)
thread.start()
Expand All @@ -105,16 +105,14 @@ def setup_hostname() -> None:
set(string.ascii_lowercase + string.digits + '-') - set('I1lO'),
)

id_path = Path(INSTALLATION_PATH) / 'pod-id'

if not id_path.exists():
if not get_pod_id():

Check warning on line 108 in ubo_app/system/system_manager/main.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/system/system_manager/main.py#L108

Added line #L108 was not covered by tests
serial_number = read_serial_number()
random.seed(serial_number)
# Generate 2 letters random id
id = f'ubo-{"".join(random.sample(available_letters, 2))}'
id_path.write_text(id)
set_pod_id(id)

Check warning on line 113 in ubo_app/system/system_manager/main.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/system/system_manager/main.py#L113

Added line #L113 was not covered by tests

id = id_path.read_text().strip()
id = get_pod_id()

Check warning on line 115 in ubo_app/system/system_manager/main.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/system/system_manager/main.py#L115

Added line #L115 was not covered by tests

# Set hostname of the system
subprocess.run( # noqa: S603
Expand Down
20 changes: 20 additions & 0 deletions ubo_app/utils/pod_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Module for managing the pod ID."""

import pathlib

Check warning on line 3 in ubo_app/utils/pod_id.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/utils/pod_id.py#L3

Added line #L3 was not covered by tests

from ubo_app.constants import INSTALLATION_PATH

Check warning on line 5 in ubo_app/utils/pod_id.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/utils/pod_id.py#L5

Added line #L5 was not covered by tests

id_path = pathlib.Path(INSTALLATION_PATH) / 'pod-id'

Check warning on line 7 in ubo_app/utils/pod_id.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/utils/pod_id.py#L7

Added line #L7 was not covered by tests


def get_pod_id() -> str | None:

Check warning on line 10 in ubo_app/utils/pod_id.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/utils/pod_id.py#L10

Added line #L10 was not covered by tests
"""Return the pod ID."""
try:
return id_path.read_text().strip()
except FileNotFoundError:
return None

Check warning on line 15 in ubo_app/utils/pod_id.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/utils/pod_id.py#L12-L15

Added lines #L12 - L15 were not covered by tests


def set_pod_id(pod_id: str) -> None:

Check warning on line 18 in ubo_app/utils/pod_id.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/utils/pod_id.py#L18

Added line #L18 was not covered by tests
"""Set the pod ID."""
id_path.write_text(pod_id)

Check warning on line 20 in ubo_app/utils/pod_id.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/utils/pod_id.py#L20

Added line #L20 was not covered by tests
1 change: 1 addition & 0 deletions ubo_app/utils/secrets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# noqa: A005, FIX002 # TODO(@sassanh): remove A105 when fix is merged
"""Module to manage secrets in a .env file."""

from __future__ import annotations
Expand Down

0 comments on commit ea79a73

Please sign in to comment.