Skip to content
Open
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
23 changes: 22 additions & 1 deletion packages/cli/src/cli/presentation/styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,27 @@ def get_device_status_style(status: str) -> str:
return status_styles.get(str(status).lower(), Colors.DEVICE_UNKNOWN)


_STATUS_LABELS = {
"detected": "Detected",
"updated": "Updated",
"update_available": "Update Available",
"no_update_needed": "Up to Date",
"auth_required": "Auth Required",
"not_shelly": "Not a Shelly Device",
"unreachable": "Unreachable",
"error": "Error",
}


def get_device_status_label(status: str) -> str:
key = status.value if hasattr(status, "value") else str(status)
label = _STATUS_LABELS.get(key.lower())
if label is not None:
return label
return key.replace("_", " ").title() if key else "Unknown"


def format_device_status(status: str) -> str:
style = get_device_status_style(status)
return f"[{style}]{status}[/{style}]"
label = get_device_status_label(status)
return f"[{style}]{label}[/{style}]"
Empty file.
49 changes: 49 additions & 0 deletions packages/cli/tests/unit/presentation/test_styles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import pytest
from cli.presentation.styles import (
format_device_status,
get_device_status_label,
get_device_status_style,
)
from core.domain.enums.enums import Status


class TestGetDeviceStatusLabel:

@pytest.mark.parametrize(
"status,expected",
[
(Status.DETECTED, "Detected"),
(Status.UPDATED, "Updated"),
(Status.UPDATE_AVAILABLE, "Update Available"),
(Status.NO_UPDATE_NEEDED, "Up to Date"),
(Status.AUTH_REQUIRED, "Auth Required"),
(Status.NOT_SHELLY, "Not a Shelly Device"),
(Status.UNREACHABLE, "Unreachable"),
(Status.ERROR, "Error"),
],
)
def test_it_labels_every_known_status(self, status, expected):
assert get_device_status_label(status) == expected
assert get_device_status_label(status.value) == expected

def test_it_title_cases_an_unrecognized_status(self):
assert get_device_status_label("something_new") == "Something New"

def test_it_falls_back_to_unknown_for_an_empty_status(self):
assert get_device_status_label("") == "Unknown"


class TestFormatDeviceStatus:

def test_it_wraps_the_label_in_the_matching_color_style(self):
style = get_device_status_style("update_available")

result = format_device_status("update_available")

assert result == f"[{style}]Update Available[/{style}]"

def test_it_never_leaks_the_raw_enum_token(self):
result = format_device_status("no_update_needed")

assert "no_update_needed" not in result
assert "Up to Date" in result
Loading