Skip to content

Commit 0298c2d

Browse files
author
James Boulton
committed
Update to the Selector to allow initial selection list and support setting the initial selection in the app.
1 parent de33557 commit 0298c2d

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

Documents/Documentation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ Feedback to the user of the dashboard is achieved when the IoT device responds t
497497
* *control_position : ControlPosition, optional.* The position of the control on a DeviceView, by default None.
498498
* *title_position : TitlePosition, optional.* Position of the title when displayed on the **Dash** app, by default None.
499499
* *column_no : int.* Optional default is 1. Must be 1..3. The Dash App reports its screen size in columns. column_no allows you to specify which column no to load into. Each control can store three configs that define how the device looks for Dash apps installed on single column phones or 2 column fold out phones or 3 column tablets.
500+
* *selection : list, optional.* Optional. This selection list.
500501

501502
#### Selector Message Attributes
502503

dashio/iotcontrol/selector.py

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,44 @@
2626
from .enums import TitlePosition
2727

2828

29+
class SelectorConfig(ControlConfig):
30+
"""SelectorConfig"""
31+
32+
def __init__(
33+
self,
34+
control_id: str,
35+
title: str,
36+
title_position: TitlePosition,
37+
control_position: ControlPosition | None,
38+
selection: list[str] | None = None
39+
) -> None:
40+
super().__init__(control_id, title, control_position, title_position)
41+
self.cfg["selection"] = selection
42+
43+
@classmethod
44+
def from_dict(cls, cfg_dict: dict):
45+
"""Instantiates SelectorConfig from cfg dictionary
46+
47+
Parameters
48+
----------
49+
cfg_dict : dict
50+
A dictionary usually loaded from a config json from IoTDashboard App
51+
52+
Returns
53+
-------
54+
SelectorConfig
55+
"""
56+
tmp_cls = cls(
57+
cfg_dict["controlID"],
58+
cfg_dict["title"],
59+
_get_title_position(cfg_dict["titlePosition"]),
60+
ControlPosition(cfg_dict["xPositionRatio"], cfg_dict["yPositionRatio"], cfg_dict["widthRatio"], cfg_dict["heightRatio"]),
61+
cfg_dict.get("selection", None)
62+
)
63+
tmp_cls.parent_id = cfg_dict["parentID"]
64+
return tmp_cls
65+
66+
2967
class Selector(Control):
3068
"""A Selector control
3169
"""
@@ -35,8 +73,9 @@ def __init__(
3573
control_id: str,
3674
title="A Selector",
3775
title_position=TitlePosition.BOTTOM,
76+
selection: list[str] | None = None,
3877
control_position=None,
39-
column_no=1
78+
column_no=1,
4079
):
4180
"""A Selector control
4281
@@ -54,18 +93,23 @@ def __init__(
5493
The Dash App reports its screen size in columns. column_no allows you to specify which column no to load into.
5594
Each control can store three configs that define how the device looks for Dash apps installed on single column
5695
phones or 2 column fold out phones or 3 column tablets.
96+
selection : list[str], optional default is None
97+
The selection list
5798
"""
5899
super().__init__("SLCTR", control_id)
100+
self.selection_list = []
101+
if selection is not None:
102+
self.selection_list = list(map(lambda s: s.translate(BAD_CHARS), selection))
59103
self._app_columns_cfg[str(column_no)].append(
60-
ControlConfig(
104+
SelectorConfig(
61105
control_id,
62106
title,
107+
title_position,
63108
control_position,
64-
title_position
109+
self.selection_list
65110
)
66111
)
67112
self._position = 0
68-
self.selection_list = []
69113

70114
@classmethod
71115
def from_cfg_dict(cls, cfg_dict: dict, column_no=1):
@@ -84,6 +128,7 @@ def from_cfg_dict(cls, cfg_dict: dict, column_no=1):
84128
cfg_dict["controlID"],
85129
cfg_dict["title"],
86130
_get_title_position(cfg_dict["titlePosition"]),
131+
cfg_dict.get("selection", None),
87132
ControlPosition(cfg_dict["xPositionRatio"], cfg_dict["yPositionRatio"], cfg_dict["widthRatio"], cfg_dict["heightRatio"]),
88133
column_no
89134
)

dashio/iotcontrol/slider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(
4444
bar_color: Color | str,
4545
knob_color: Color | str,
4646
bar_style: SliderBarStyle,
47-
control_position: ControlPosition | None,
47+
control_position: ControlPosition | None
4848
) -> None:
4949
super().__init__(control_id, title, control_position, title_position)
5050
self.cfg["redValue"] = red_value

dashio/iotcontrol/time_graph.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ def __init__(
103103
The data is stored in a ring buffer this sets the ring buffer size, by default 60
104104
break_data : bool, optional
105105
If true draws the line with breaks between missing data, by default False
106+
right_axis: bool, optional
107+
Defaults to left, right if true.
106108
"""
107109
self.name = name.translate(BAD_CHARS)
108110
self.line_type = line_type

0 commit comments

Comments
 (0)