Skip to content

Commit b64916b

Browse files
author
James Boulton
committed
tidyup
1 parent 9d579f2 commit b64916b

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

utilities/dashio_data_exporter

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,9 @@ def on_message(client, obj, msg):
105105

106106
def on_subscribe(client, userdata, mid, reason_codes, properties):
107107
"""Get the data on subscribe event message"""
108-
if control_type == 'TGRPH':
109-
get_time_graph_data()
110-
elif control_type == 'MAP':
111-
get_map_data()
112-
elif control_type == 'LOG':
113-
get_log_data()
108+
msg = f"\t{device_id}\t{control_type}\t{control_id}\t{dashboard_id}\t{from_timestamp}\n"
109+
control_topic = f"{username}/{device_id}/store/control"
110+
mqtt_client.publish(control_topic, msg)
114111

115112

116113
def parse_line_data(rx_username: str, rx_device_id: str, line_data: list[str]) -> str:
@@ -126,7 +123,8 @@ def parse_line_data(rx_username: str, rx_device_id: str, line_data: list[str]) -
126123
parse_log_data(control_data)
127124

128125

129-
def format_log_json(log: str):
126+
def format_log_json_to_cvs(log: str) -> str:
127+
"""Convert the json to csv"""
130128
log_dict = json.loads(log)
131129
log_str = "{time}, {color}, ".format_map(log_dict)
132130
log_str += ", ".join(log_dict["lines"])
@@ -145,9 +143,11 @@ def parse_log_data(control_data: ControlData):
145143
elif file_format == 'cvs':
146144
line = f"# {control_data.device_id}, TGRPH, {control_data.control_id}"
147145
line += "\nTimestamp, color, lines\n"
148-
line += "\n".join(format_log_json(l_str) for l_str in control_data.data)
146+
line += "\n".join(format_log_json_to_cvs(l_str) for l_str in control_data.data)
149147
if screen:
150148
print(line)
149+
else:
150+
return
151151
if out_to_file:
152152
filename = f"{control_data.device_id}_{control_data.control_type}_{control_data.control_id}_{control_data.data[0]}.{file_format}"
153153
print("Writing to file: " + filename)
@@ -171,31 +171,15 @@ def parse_tgrph_data(control_data: ControlData):
171171
line += "\n".join(line_data)
172172
if screen:
173173
print(line)
174+
else:
175+
return
174176
if out_to_file:
175177
filename = f"{control_data.device_id}_{control_data.control_type}_{control_data.control_id}_{control_data.data[0]}.{file_format}"
176178
print("Writing to file: " + filename)
177179
with open(filename, "w", encoding='utf-8') as writer:
178180
writer.write(line)
179181

180182

181-
def get_log_data():
182-
msg = f"\t{device_id}\tLOG\t{control_id}\t{dashboard_id}\t{from_timestamp}\n"
183-
control_topic = f"{username}/{device_id}/store/control"
184-
mqtt_client.publish(control_topic, msg)
185-
186-
187-
def get_map_data():
188-
msg = f"\t{device_id}\tMAP\t{control_id}\t{dashboard_id}\t{from_timestamp}\n"
189-
control_topic = f"{username}/{device_id}/store/control"
190-
mqtt_client.publish(control_topic, msg)
191-
192-
193-
def get_time_graph_data():
194-
msg = f"\t{device_id}\tTGRPH\t{control_id}\t{dashboard_id}\t{from_timestamp}\n"
195-
control_topic = f"{username}/{device_id}/store/control"
196-
mqtt_client.publish(control_topic, msg)
197-
198-
199183
def main():
200184
"""The Main"""
201185

0 commit comments

Comments
 (0)