diff --git a/apps/hassgraph/hass_graph.star b/apps/hassgraph/hass_graph.star index c63fee36d..0dadc5ac2 100644 --- a/apps/hassgraph/hass_graph.star +++ b/apps/hassgraph/hass_graph.star @@ -5,6 +5,7 @@ load("images/img_2274bcef.bin", IMG_2274bcef_ASSET = "file") load("images/img_7b76fdf3.bin", IMG_7b76fdf3_ASSET = "file") load("images/img_adff806b.svg", IMG_adff806b_ASSET = "file") load("images/img_fbe29b76.svg", IMG_fbe29b76_ASSET = "file") +load("math.star", "math") load("render.star", "render") load("schema.star", "schema") load("time.star", "time") @@ -234,6 +235,10 @@ def render_app(config, current_value, points, stats, unit, label): child = render_graph_column(config, current_value, points, unit, label), ) +def round(num, precision): + """Round a float to the specified number of significant digits""" + return math.round(num * math.pow(10, precision)) / math.pow(10, precision) + def render_graph_column(config, current_value, points, unit, label): icon = get_icon(config) children = [] @@ -245,6 +250,10 @@ def render_graph_column(config, current_value, points, unit, label): width = 12, height = 12, )) + if (config.str("round_to") in ["0", "1", "2"]): + decimal = int(config.get("round_to")) + val = round(float(current_value), decimal) + current_value = str(int(val)) if val == int(val) else str(val) children.append(render.Text(content = current_value + unit, font = "6x13")) align = "space_between" if label else "end" return render.Column( @@ -389,6 +398,31 @@ def get_schema(): icon = "filter", name = "Display range", ), + schema.Dropdown( + id = "round_to", + desc = "Round to which decimal", + icon = "filter", + name = "Round To", + default = "none", + options = [ + schema.Option( + display = "None", + value = "none", + ), + schema.Option( + display = "Ones", + value = "0", + ), + schema.Option( + display = "Tenths", + value = "1", + ), + schema.Option( + display = "Hundreths", + value = "2", + ), + ], + ), schema.Location( id = "location", name = "Location", diff --git a/apps/hassgraph/manifest.yaml b/apps/hassgraph/manifest.yaml index 02b1ecf58..ddd3065c3 100644 --- a/apps/hassgraph/manifest.yaml +++ b/apps/hassgraph/manifest.yaml @@ -13,4 +13,4 @@ tags: - sports - utility published: '2024-06-19T15:18:22Z' -updated: '2026-06-05T00:54:23Z' +updated: '2026-07-06T22:24:02Z'