Beispiel #1
0
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
Beispiel #2
0
 def notify(self, name, value):
     self.log.info('AWS IoT: publish({}={})'.format(name, value))
     Thing(name, self.client).publish_state(value)
Beispiel #3
0
 def notify(self, name, value):
     Thing(name, self.client).publish_state(value)
Beispiel #4
0
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)