|
2 | 2 | # Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
3 | 3 | # |
4 | 4 |
|
5 | | -import sys |
6 | 5 | import logging |
| 6 | +import sys |
| 7 | + |
7 | 8 | import greengrasssdk |
8 | 9 |
|
9 | 10 | # Setup logging to stdout |
10 | 11 | logger = logging.getLogger(__name__) |
11 | 12 | logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) |
12 | 13 |
|
13 | | -client = greengrasssdk.client('iot-data') |
| 14 | +client = greengrasssdk.client("iot-data") |
14 | 15 |
|
15 | 16 |
|
16 | 17 | def uptime_handler(event, context): |
17 | 18 | logger.info("Received message!") |
18 | | - if 'state' in event: |
19 | | - if event['state'] == "on": |
| 19 | + if "state" in event: |
| 20 | + if event["state"] == "on": |
20 | 21 | try: |
21 | | - client.publish( |
22 | | - topic='/topic/metering', |
23 | | - queueFullPolicy='AllOrException', |
24 | | - payload="Robot arm turned ON") |
25 | | - logger.info("Triggering publish to topic " |
26 | | - "/topic/metering with ON state") |
| 22 | + client.publish(topic="/topic/metering", queueFullPolicy="AllOrException", payload="Robot arm turned ON") |
| 23 | + logger.info("Triggering publish to topic " "/topic/metering with ON state") |
27 | 24 | except Exception as e: |
28 | | - logger.error("Failed to trigger publish to topic " |
29 | | - "/topic/metering with ON state: " + repr(e)) |
30 | | - elif event['state'] == "off": |
| 25 | + logger.error("Failed to trigger publish to topic " "/topic/metering with ON state: " + repr(e)) |
| 26 | + elif event["state"] == "off": |
31 | 27 | try: |
32 | 28 | client.publish( |
33 | | - topic='/topic/metering', |
34 | | - queueFullPolicy='AllOrException', |
35 | | - payload="Robot arm turned OFF") |
36 | | - logger.info("Triggering publish to topic " |
37 | | - "/topic/metering with OFF state") |
| 29 | + topic="/topic/metering", queueFullPolicy="AllOrException", payload="Robot arm turned OFF" |
| 30 | + ) |
| 31 | + logger.info("Triggering publish to topic " "/topic/metering with OFF state") |
38 | 32 | except Exception as e: |
39 | | - logger.error("Failed to trigger publish to topic " |
40 | | - "/topic/metering with OFF state: " + repr(e)) |
| 33 | + logger.error("Failed to trigger publish to topic " "/topic/metering with OFF state: " + repr(e)) |
0 commit comments