Skip to content

Commit cdfde84

Browse files
author
James Boulton
committed
Start of the table control support, and spelling fixes
1 parent c803857 commit cdfde84

25 files changed

Lines changed: 308 additions & 62 deletions

dashio/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
from .iotcontrol.button_group import ButtonGroup
9191
from .iotcontrol.event_log import EventData, EventLog
9292
from .iotcontrol.color_picker import ColorPicker
93+
from .iotcontrol.table import Table, TableRow
9394

9495
__all__ = [
9596
'Device',
@@ -142,6 +143,8 @@
142143
'DataPoint',
143144
'DataPointArray',
144145
'Knob',
146+
'Table',
147+
'TableRow',
145148
'Dial',
146149
'Direction',
147150
'Map',

dashio/device.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def _send_alarm(self, alarm_id, message_header, message_body):
201201
def _send_data(self, data: str):
202202
if not data:
203203
return
204+
reply_send = ""
204205
if isinstance(data, str):
205206
reply_send = data.replace("{device_id}", self.device_id)
206207
elif isinstance(data, list):
@@ -238,7 +239,7 @@ def add_all_c64_controls(self, c64_dict: dict, column_no=1):
238239
c64_dict : Dict
239240
dictionary of the CFG loaded by decode_cfg from a CFG64 or json
240241
column_no: Int From 1 to 3 (default 1).
241-
The DashIO app reports the size of the screen in no of columns. You can load a seperate
242+
The DashIO app reports the size of the screen in no of columns. You can load a separate
242243
config for each reported column number.
243244
"""
244245
if not 1 <= column_no <= 3:
@@ -253,6 +254,11 @@ def add_all_c64_controls(self, c64_dict: dict, column_no=1):
253254
else:
254255
new_control = CONTROL_INSTANCE_DICT[control_type].from_cfg_dict(control, column_no=column_no)
255256
self.add_control(new_control)
257+
elif control_type == "CFG" and isinstance(control_list, dict):
258+
logger.debug("CFG: %s", control_list)
259+
if 'name' in control_list['deviceSetup']:
260+
self._set_device_setup("name", True)
261+
self.set_name_callback(self._name_callback)
256262

257263
def add_control(self, iot_control):
258264
"""Add a control to the device.
@@ -309,7 +315,7 @@ def remove_control(self, iot_control):
309315
if key in self.controls_dict:
310316
del self.controls_dict[key]
311317

312-
def _set_devicesetup(self, control_name: str, settable: bool):
318+
def _set_device_setup(self, control_name: str, settable: bool):
313319
if settable:
314320
self._device_commands_dict[control_name.upper()] = getattr(self, '_' + control_name + '_rx_event', None)
315321
if control_name not in self._device_setup_list:
@@ -350,14 +356,14 @@ def set_wifi_callback(self, callback):
350356
The callback function. It will be invoked with one argument, the msg from IoTDashboard.
351357
The callback must return a Boolean indicating success.
352358
"""
353-
self._set_devicesetup("wifi", True)
359+
self._set_device_setup("wifi", True)
354360
self._wifi_rx_callback = callback
355361

356362
def unset_wifi_callback(self):
357363
"""
358364
Unset the wifi_rx_callback.
359365
"""
360-
self._set_devicesetup("wifi", False)
366+
self._set_device_setup("wifi", False)
361367
self._wifi_rx_callback = None
362368

363369
def _wifi_rx_event(self, msg) -> str:
@@ -377,14 +383,14 @@ def set_dashio_callback(self, callback):
377383
The callback function. It will be invoked with one argument, the msg from IoTDashboard.
378384
The callback must return a Boolean indicating success.
379385
"""
380-
self._set_devicesetup("dashio", True)
386+
self._set_device_setup("dashio", True)
381387
self._dashio_rx_callback = callback
382388

383389
def unset_dashio_callback(self):
384390
"""
385391
Unset the dashio callback function.
386392
"""
387-
self._set_devicesetup("dashio", False)
393+
self._set_device_setup("dashio", False)
388394
self._dashio_rx_callback = None
389395

390396
def _dashio_rx_event(self, msg):
@@ -404,16 +410,20 @@ def set_name_callback(self, callback):
404410
The callback function. It will be invoked with one argument, the msg from IoTDashboard.
405411
The callback must return the new name.
406412
"""
407-
self._set_devicesetup("name", True)
413+
self._set_device_setup("name", True)
408414
self._name_rx_callback = callback
409415

410416
def unset_name_callback(self):
411417
"""
412418
Unset the name callback function.
413419
"""
414-
self._set_devicesetup("name", False)
420+
self._set_device_setup("name", False)
415421
self._name_rx_callback = None
416422

423+
def _name_callback(self, msg) -> str:
424+
logger.debug("Name msg: %s", msg)
425+
return msg[2]
426+
417427
def _name_rx_event(self, msg) -> str:
418428
if self._name_rx_callback is not None:
419429
name = self._name_rx_callback(msg)
@@ -432,14 +442,14 @@ def set_tcp_callback(self, callback):
432442
The callback function. It will be invoked with one argument, the msg from IoTDashboard.
433443
The callback must return a Boolean indicating success.
434444
"""
435-
self._set_devicesetup("tcp", True)
445+
self._set_device_setup("tcp", True)
436446
self._tcp_rx_callback = callback
437447

438448
def unset_tcp_callback(self):
439449
"""
440450
Unset the tcp callback function.
441451
"""
442-
self._set_devicesetup("tcp", False)
452+
self._set_device_setup("tcp", False)
443453
self._tcp_rx_callback = None
444454

445455
def _tcp_rx_event(self, msg):
@@ -459,14 +469,14 @@ def set_mqtt_callback(self, callback):
459469
The callback function. It will be invoked with one argument, the msg from IoTDashboard.
460470
The callback must return a Boolean indicating success.
461471
"""
462-
self._set_devicesetup("mqtt", True)
472+
self._set_device_setup("mqtt", True)
463473
self._mqtt_rx_callback = callback
464474

465475
def unset_mqtt_callback(self):
466476
"""
467477
Unset the mqtt callback function.
468478
"""
469-
self._set_devicesetup("mqtt", False)
479+
self._set_device_setup("mqtt", False)
470480
self._mqtt_rx_callback = None
471481

472482
def _mqtt_rx_event(self, msg):

dashio/iotcontrol/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@
2323
from .button_group import ButtonGroup, ButtonGroupConfig
2424
from .event_log import EventLog, EventData
2525
from .color_picker import ColorPicker, ColorPickerConfig
26+
from .table import Table, TableRow, TableConfig

dashio/iotcontrol/audio_visual_display.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __init__(
6363

6464
@classmethod
6565
def from_cfg_dict(cls, cfg_dict: dict, column_no=1):
66-
"""Instatiates Button from cfg dictionary
66+
"""Instantiates Button from cfg dictionary
6767
6868
Parameters
6969
----------

dashio/iotcontrol/button.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class Button(Control):
115115
Updates the button state, button icon and text.
116116
117117
from_cfg_dict(cfg_dict: dict) :
118-
Instatiates Button from cfg dictionary
118+
Instantiates Button from cfg dictionary
119119
"""
120120

121121
def toggle_btn(self):
@@ -164,7 +164,7 @@ def __init__(
164164

165165
@classmethod
166166
def from_cfg_dict(cls, cfg_dict: dict, column_no=1):
167-
"""Instatiates Button from cfg dictionary
167+
"""Instantiates Button from cfg dictionary
168168
169169
Parameters
170170
----------

dashio/iotcontrol/button_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def __init__(
135135

136136
@classmethod
137137
def from_cfg_dict(cls, cfg_dict: dict, column_no=1):
138-
"""Instatiates ButtonGroup from cfg dictionary
138+
"""Instantiates ButtonGroup from cfg dictionary
139139
140140
Parameters
141141
----------

dashio/iotcontrol/chart.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self, name="", line_type=ChartLineType.LINE, color=Color.BLACK, rig
4040
self.axis_side = 'right'
4141

4242
def get_line_data(self):
43-
"""Returns the line data formated for the iotdashboard app
43+
"""Returns the line data formatted for the iotdashboard app
4444
4545
Returns
4646
-------
@@ -267,7 +267,7 @@ def y_axis_num_bars(self):
267267

268268
@classmethod
269269
def from_cfg_dict(cls, cfg_dict: dict, column_no=1):
270-
"""Instatiates Chart from cfg dictionary
270+
"""Instantiates Chart from cfg dictionary
271271
272272
Parameters
273273
----------

dashio/iotcontrol/color_picker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def __init__(
117117

118118
@classmethod
119119
def from_cfg_dict(cls, cfg_dict: dict, column_no=1):
120-
"""Instatiates ColorPicker from cfg dictionary
120+
"""Instantiates ColorPicker from cfg dictionary
121121
122122
Parameters
123123
----------

dashio/iotcontrol/control.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ class ControlPosition:
165165

166166
def __init__(self, x_position_ratio: float, y_position_ratio: float, width_ratio: float, height_ratio: float):
167167
"""The ControlPosition class describes the location and size of a control on a DeviceView. The
168-
x_postion and y_position ratio place the top left hand corner of the control. The width and height ratio
169-
describe the controls size. The ratio is a number betwwen 0 and 1 representing the width and height of the
168+
x_position and y_position ratio place the top left hand corner of the control. The width and height ratio
169+
describe the controls size. The ratio is a number between 0 and 1 representing the width and height of the
170170
DeviceView.
171171
172172
Parameters
@@ -258,7 +258,7 @@ def __init__(
258258

259259
@classmethod
260260
def from_dict(cls, cfg_dict: dict):
261-
"""Instatiates Dial from cfg dictionary
261+
"""Instantiates Dial from cfg dictionary
262262
263263
Parameters
264264
----------
@@ -281,7 +281,7 @@ def from_dict(cls, cfg_dict: dict):
281281

282282
@property
283283
def parent_id(self) -> str:
284-
"""The parent control or deviceview this control belongs to
284+
"""The parent control or device view this control belongs to
285285
286286
Returns
287287
-------
@@ -367,7 +367,7 @@ def get_cfg64(self, data) -> list:
367367
return cfg_list
368368

369369
def add_config(self, config, column_no=1):
370-
"""Add a duplicate Config for dashio Apps with wider screens"""
370+
"""Add a duplicate Config for DashIO Apps with wider screens"""
371371
config.cfg["controlID"] = self.control_id
372372
if 1 <= column_no <= self._cfg_max_no_columns:
373373
self._app_columns_cfg[str(column_no)].append(config)
@@ -389,7 +389,7 @@ def remove_transmit_message_callback(self, callback):
389389
self._message_tx_event -= callback
390390

391391
def __init__(self, cntrl_type: str, control_id: str):
392-
"""Control base type - all controls have these charactoristics and methods.
392+
"""Control base type - all controls have these characteristics and methods.
393393
394394
Parameters
395395
----------
@@ -440,7 +440,7 @@ def state_str(self, val):
440440
# Use getter, setter properties to store the settings in the config dictionary
441441
@property
442442
def parent_id(self, index=0, column_no=1) -> str:
443-
"""The parent control or deviceview this control belongs to
443+
"""The parent control or device view this control belongs to
444444
445445
Returns
446446
-------

dashio/iotcontrol/device_view.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def from_dict(cls, cfg_dict: dict):
110110

111111

112112
class DeviceView(Control):
113-
"""A DeviceView provides a control that descibes appearance and style of the group of controls
113+
"""A DeviceView provides a control that describes appearance and style of the group of controls
114114
that are displayed on this DeviceView by the iotdashboard app.
115115
116116
Attributes
@@ -126,7 +126,7 @@ class DeviceView(Control):
126126
The Icon representing the DeviceView
127127
color : Color
128128
The color of the DeviceView
129-
share_column : Booloan
129+
share_column : Boolean
130130
Something something
131131
num_columns : int
132132
Number of columns for DeviceView
@@ -200,7 +200,7 @@ def __init__(
200200

201201
@classmethod
202202
def from_cfg_dict(cls, cfg_dict: dict, column_no=1):
203-
"""Instatiates DeviceView from cfg dictionary
203+
"""Instantiates DeviceView from cfg dictionary
204204
205205
Parameters
206206
----------

0 commit comments

Comments
 (0)