def expect_network_cmd(): # Ask spanner to wait for 3 seconds while at the same time checking if we # got a command from the device result = device.waitForCommand(3) # Make sure we actually got a command, and we didn't just time out spanner.assertTrue(result.commandReceived) # Double check the name of the command spanner.assertEqual("heartbeat_event", command.name) spanner.assertEqual("", command.value)
def test_raise_flooding_alarm(): # set PIN state testboard.digitalWrite(OUTPUT_PIN, HIGH) time.sleep(2) # Ask spanner to wait for 3 seconds while at the same time checking if we # got a command from the device result = device.waitForCommand(3) # Make sure we actually got a command, and we didn't just time out spanner.assertTrue(result.commandReceived) # Double check the name of the command spanner.assertEqual("alarm_triggered", command.name) spanner.assertEqual("water_flooding", command.value)
def test_raise_flooding_alarm(): # set PIN state testboard.digitalWrite(OUTPUT_PIN, HIGH) time.sleep(2) url = 'https://api.particle.io/v1/devices/events?access_token='+particle_token response = with_urllib3(url) # or with_requests(url) client = sseclient.SSEClient(response) # acts like a while loop for event in client.events(): data = json.loads(event.data) # e.g data['data'] = 'alarm' command = data['data'] # Double check the name of the command spanner.assertEqual("alarm_triggered", command.name) spanner.assertEqual("water_flooding", command.value) sys.exit(0)