Skip to content

Commit

Permalink
iot: fix print formatting for gateway codelab (#2058)
Browse files Browse the repository at this point in the history
* iot: fix print formatting for gateway codelab

* iot: fix lint errors
  • Loading branch information
hongalex authored Mar 20, 2019
1 parent 4cd36ef commit 49125ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
25 changes: 16 additions & 9 deletions iot/api-client/codelabs/lightsensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def detect_light(device_id, sock):
lux = "{:.3f}".format(LightSensor.lux)

sys.stdout.write(
'\r>> ' + bcolors.CGREEN + bcolors.CBLINK + 'Lux: {}'.format(lux) +
'\r>> ' + bcolors.CGREEN + bcolors.CBOLD + 'Lux: {}'.format(lux) +
bcolors.ENDC + ' <<')
sys.stdout.flush()

Expand All @@ -95,9 +95,14 @@ def detect_light(device_id, sock):


def print_sensor_state():
print(
'\nSensor is {}, reporting lux every {} seconds.'.format(
LightSensor.power, LightSensor.interval))
if LightSensor.power == 'on':
print(
'\nSensor is {}, reporting lux every {} seconds.'.format(
LightSensor.power, LightSensor.interval))
else:
print(
'\nSensor is {}. Send a configuration update to turn on'.format(
LightSensor.power))


def process_message(message):
Expand Down Expand Up @@ -172,11 +177,13 @@ def main():
sys.exit(1)
else:
# Received data from the socket, so process the message.
message = json.loads(data.decode("utf-8"))
if not message:
print('invalid json: {}'.format(data.decode("utf-8")))
continue
process_message(message)
decode = data.decode("utf-8")
if decode != '':
message = json.loads(decode)
if not message:
print('invalid json: {}'.format(data.decode("utf-8")))
continue
process_message(message)
finally:
print('Closing socket')
sock.close()
Expand Down
2 changes: 1 addition & 1 deletion iot/api-client/codelabs/thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def main():
humidity = "{:.3f}".format(h)
temperature = "{:.3f}".format(temperature_f)
sys.stdout.write(
'\r >>' + bcolors.CGREEN + bcolors.CBOLD +
'\r>> ' + bcolors.CGREEN + bcolors.CBOLD +
'Temp: {} F, Hum: {}%'.format(temperature, humidity) +
bcolors.ENDC + ' <<')
sys.stdout.flush()
Expand Down

0 comments on commit 49125ba

Please sign in to comment.