def test_publish_state(): client = Mock() thing = Thing('light', client) on_state = {'on': True} thing.publish_state(on_state) expected_message = json.dumps({'state': {'reported': on_state}}) client.publish.assert_called_once_with(thing.topic, expected_message) assert thing.state == on_state
Then go into the AWS IoT console and see if your thing's state has been updated. """ import sys from thingamon import Client, Thing import time if __name__ == '__main__': if len(sys.argv) != 4: print('usage: update_once <AWS_ENDPOINT> <NAME_OF_THING> <MOOD>') sys.exit() host = sys.argv[1] name = sys.argv[2] mood = sys.argv[3] client = Client(host, client_cert_filename='cert.pem', private_key_filename='thing-private-key.pem', log_mqtt=True) thing = Thing(name, client) thing.publish_state({'mood': mood}) # thingamon uses MQTT in async mode, so here we wait a bit # for the message to get sent. Normal long running apps don't need # to do this except in their exit handlers. # Adjust the time as needed. time.sleep(3)