As we saw previously when poll_dweets_forever() (similar to stream_dweets_forever()) gets a dweet, it parses out the content property from the dweet's JSON. This is then passed to process_dweet() for handling, where we extract the state child property from the content property:
def process_dweet(dweet):
"""Inspect the dweet and set LED state accordingly"""
global last_led_state
if not 'state' in dweet:
return
led_state = dweet['state'] # (14)
if led_state == last_led_state: # (15)
return; # LED is already in requested state.
On line (15) (and (17) in the subsequent code block), we test for and maintain the LED's last known state and avoid interacting with the LED if it's already in the requested state. This will avoid potential visual glitching of the LED that can occur if it's repeatedly put into...