Skip to content

Commit e87339a

Browse files
committed
removed type requirement for input to broadcast(), converted messages to strings before sending to Scratch
1 parent affa165 commit e87339a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

scratch.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,18 @@ def sensorupdate(self, data):
7070
raise TypeError('Expected a dict')
7171
message = 'sensor-update'
7272
for key in data.keys():
73-
message = message+' "'+key+'" '+str(data[key])
73+
message = message+' "'+str(key)+'" '+str(data[key])
7474
self.send(message)
7575

7676
def broadcast(self, data):
7777
"""Takes a list of message strings and writes a broadcast message to scratch"""
78-
if not isinstance(data, list):
79-
raise TypeError('Expected a list')
8078
message = 'broadcast'
81-
for mess in data:
82-
message = message+' "'+mess+'"'
83-
self.send(message)
79+
if isinstance(data, list):
80+
for mess in data:
81+
message = message+' "'+str(mess)+'"'
82+
self.send(message)
83+
else:
84+
self.send(message+' "'+str(data)+'"')
8485

8586
def parse_message(self, message):
8687
#TODO: parse sensorupdates with quotes in sensor names and values

0 commit comments

Comments
 (0)