Skip to content

formatting.py

formatting

Helpers for formatting values for display.

Functions

format_capacity

format_capacity(
    capacity: int | None, metric: bool = True
) -> str

Format capacity for display.

Source code in ember_mug/formatting.py
16
17
18
19
20
21
22
23
24
def format_capacity(capacity: int | None, metric: bool = True) -> str:
    """Format capacity for display."""
    if capacity is None:
        return "Unknown"
    if metric is False:
        # Convert to fahrenheit
        capacity = round(capacity * 0.033814)
        return f"{capacity}oz"
    return f"{capacity}ml"

format_led_colour

format_led_colour(led_colour: Colour) -> str

Return colour as hex value.

Source code in ember_mug/formatting.py
27
28
29
def format_led_colour(led_colour: Colour) -> str:
    """Return colour as hex value."""
    return led_colour.as_hex()

format_liquid_level

format_liquid_level(liquid_level: int) -> str

Human readable liquid level.

Source code in ember_mug/formatting.py
32
33
34
def format_liquid_level(liquid_level: int) -> str:
    """Human readable liquid level."""
    return f"{(liquid_level / 30 * 100):.2f}%"

format_temp

format_temp(temp: float, metric: bool = True) -> str

Format temperature with the correct unit.

Source code in ember_mug/formatting.py
10
11
12
13
def format_temp(temp: float, metric: bool = True) -> str:
    """Format temperature with the correct unit."""
    unit = "C" if metric else "F"
    return f"{temp:.2f}°{unit}"