From 4106f13426c2691de1d9c5de1de42bc21de56684 Mon Sep 17 00:00:00 2001 From: Eduard Carrerars Date: Wed, 5 Nov 2025 10:39:04 +0100 Subject: [PATCH 1/2] Add progressbar property to indicator result - Include progressbar in result when it's set to True - Update tests to verify progressbar property in result --- ooui/graph/indicator.py | 10 +++++++++- spec/graph/graph_spec.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/ooui/graph/indicator.py b/ooui/graph/indicator.py index 1299284..4c92203 100644 --- a/ooui/graph/indicator.py +++ b/ooui/graph/indicator.py @@ -24,6 +24,8 @@ def __init__(self, graph_type, element): ) or None self._show_percent = parse_bool_attribute( element.get('showPercent')) if element.get('showPercent') else False + self._progressbar = parse_bool_attribute( + element.get('progressbar')) if element.get('progressbar') else False self.domain_parse_values = {} @property @@ -42,6 +44,10 @@ def total_domain(self): def show_percent(self): return self._show_percent + @property + def progressbar(self): + return self._progressbar + @property def suffix(self): return self._suffix @@ -61,7 +67,9 @@ def process(self, value, total=0): res['color'] = self.color.eval(res) if self.icon: res['icon'] = self.icon.eval(res) - if not self.show_percent: + if self.progressbar: + res['progressbar'] = self.progressbar + if not self.show_percent and not self.progressbar: res.pop('percent', None) return res diff --git a/spec/graph/graph_spec.py b/spec/graph/graph_spec.py index 96c8e7a..475a0d4 100644 --- a/spec/graph/graph_spec.py +++ b/spec/graph/graph_spec.py @@ -33,8 +33,43 @@ expect(graph.fields).to(contain_only('potencia')) expect(graph.total_domain).to(be_none) expect(graph.show_percent).to(be_true) + expect(graph.progressbar).to(be_false) expect(graph.suffix).to(equal('kW')) + with it('should support progressbar attribute'): + xml = """ + + """ + graph = parse_graph(xml) + expect(graph.progressbar).to(be_true) + expect(graph.show_percent).to(be_false) + + with it('should calculate percent when progressbar is true'): + xml = """ + + """ + graph = parse_graph(xml) + result = graph.process(50, 100) + expect(result).to(have_key('percent', 50.0)) + expect(result).to(have_key('progressbar', True)) + + with it('should calculate percent when showPercent is true'): + xml = """ + + """ + graph = parse_graph(xml) + result = graph.process(50, 100) + expect(result).to(have_key('percent', 50.0)) + + with it('should not include percent when both progressbar and showPercent are false'): + xml = """ + + """ + graph = parse_graph(xml) + result = graph.process(50, 100) + expect(result).not_to(have_key('percent')) + expect(result).not_to(have_key('progressbar')) + with it("should parse a chart graph XML with type line"): xml = """ From c87299b256c9867fe56339e2a6cf0a44faa7e2be Mon Sep 17 00:00:00 2001 From: Eduard Carrerars Date: Wed, 5 Nov 2025 18:08:10 +0100 Subject: [PATCH 2/2] Add showPercent to indicator response when explicitly set --- ooui/graph/indicator.py | 2 ++ spec/graph/graph_spec.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/ooui/graph/indicator.py b/ooui/graph/indicator.py index 4c92203..d307037 100644 --- a/ooui/graph/indicator.py +++ b/ooui/graph/indicator.py @@ -69,6 +69,8 @@ def process(self, value, total=0): res['icon'] = self.icon.eval(res) if self.progressbar: res['progressbar'] = self.progressbar + if self.show_percent: + res['showPercent'] = self.show_percent if not self.show_percent and not self.progressbar: res.pop('percent', None) return res diff --git a/spec/graph/graph_spec.py b/spec/graph/graph_spec.py index 475a0d4..94b76b7 100644 --- a/spec/graph/graph_spec.py +++ b/spec/graph/graph_spec.py @@ -52,6 +52,7 @@ result = graph.process(50, 100) expect(result).to(have_key('percent', 50.0)) expect(result).to(have_key('progressbar', True)) + expect(result).not_to(have_key('showPercent')) with it('should calculate percent when showPercent is true'): xml = """ @@ -60,6 +61,7 @@ graph = parse_graph(xml) result = graph.process(50, 100) expect(result).to(have_key('percent', 50.0)) + expect(result).to(have_key('showPercent', True)) with it('should not include percent when both progressbar and showPercent are false'): xml = """ @@ -69,6 +71,7 @@ result = graph.process(50, 100) expect(result).not_to(have_key('percent')) expect(result).not_to(have_key('progressbar')) + expect(result).not_to(have_key('showPercent')) with it("should parse a chart graph XML with type line"): xml = """