Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try:
return int(value)
except ValueError:
print "Invalid network id"
return None
class ExtendedOption (Option):
TYPES = Option.TYPES + ("base64", "hexint", )
TYPE_CHECKER = copy(Option.TYPE_CHECKER)
TYPE_CHECKER["base64"] = DecodeBase64Option
TYPE_CHECKER["hexint"] = DecodeHexIntOption
if __name__ == '__main__':
devMgr = WeaveDeviceMgr.WeaveDeviceManager()
cmdLine = " ".join(sys.argv[1:])
args = shlex.split(cmdLine)
optParser = OptionParser(usage=optparse.SUPPRESS_USAGE, option_class=ExtendedOption)
print "Connecting to device ..."
print ''
print '#################################connect#################################'
optParser.add_option("", "--pairing-code", action="store", dest="pairingCode", type="string")
optParser.add_option("", "--access-token", action="store", dest="accessToken", type="base64")
optParser.add_option("", "--use-dummy-access-token", action="store_true", dest="useDummyAccessToken")
optParser.add_option("", "--ble", action="store_true", dest="useBle")
optParser.add_option("", "--account-id", action="store", dest="account_id")
print ''
print '#################################disable-network#################################'
try:
devMgr.DisableNetwork(lastNetworkId)
except WeaveDeviceMgr.DeviceManagerException, ex:
print str(ex)
print "Disable network complete"
print ''
print '#################################enable-network#################################'
try:
devMgr.EnableNetwork(lastNetworkId)
except WeaveDeviceMgr.DeviceManagerException, ex:
print ex
exit()
print "Enable network complete"
print ''
print '#################################test-network#################################'
try:
devMgr.TestNetworkConnectivity(lastNetworkId)
except WeaveDeviceMgr.DeviceManagerException, ex:
print ex
exit()
print "Network test complete"
i = i + 1
try:
networkType = WeaveDeviceMgr.ParseNetworkType("thread")
scanResult = devMgr.ScanNetworks(networkType)
except WeaveDeviceMgr.DeviceManagerException, ex:
print ex
print "ScanNetworks complete, %d network(s) found" % (len(scanResult))
i = 1
for net in scanResult:
print " Network %d" % (i)
net.Print(" ")
i = i + 1
print ''
print '#################################add-network#################################'
networkInfo = WeaveDeviceMgr.NetworkInfo(
networkType = WeaveDeviceMgr.NetworkType_WiFi,
wifiSSID = "Wireless-1",
wifiMode = WeaveDeviceMgr.WiFiMode_Managed,
wifiRole = WeaveDeviceMgr.WiFiRole_Station,
wifiSecurityType = WeaveDeviceMgr.WiFiSecurityType_None)
try:
addResult = devMgr.AddNetwork(networkInfo)
except WeaveDeviceMgr.DeviceManagerException, ex:
print ex
exit()
lastNetworkId = addResult
print "Add wifi network complete (network id = " + str(addResult) + ")"
try:
addResult = devMgr.AddNetwork(networkInfo)
except WeaveDeviceMgr.DeviceManagerException, ex:
print ex
exit()
lastNetworkId = addResult
print "Add wifi network complete (network id = " + str(addResult) + ")"
print ''
print '#################################update-network#################################'
# networkInfo = WeaveDeviceMgr.NetworkInfo(networkId=lastNetworkId)
networkInfo = WeaveDeviceMgr.NetworkInfo(
networkType = WeaveDeviceMgr.NetworkType_WiFi,
networkId=lastNetworkId,
wifiSSID = "Wireless-1",
wifiMode = WeaveDeviceMgr.WiFiMode_Managed,
wifiRole = WeaveDeviceMgr.WiFiRole_Station,
wifiSecurityType = WeaveDeviceMgr.WiFiSecurityType_None)
try:
devMgr.UpdateNetwork(networkInfo)
except WeaveDeviceMgr.DeviceManagerException, ex:
print str(ex)
exit()
print "Update network complete"
print ''
try:
networkType = WeaveDeviceMgr.ParseNetworkType("thread")
scanResult = devMgr.ScanNetworks(networkType)
except WeaveDeviceMgr.DeviceManagerException, ex:
print ex
print "ScanNetworks complete, %d network(s) found" % (len(scanResult))
i = 1
for net in scanResult:
print " Network %d" % (i)
net.Print(" ")
i = i + 1
print ''
print '#################################add-network#################################'
networkInfo = WeaveDeviceMgr.NetworkInfo(
networkType = WeaveDeviceMgr.NetworkType_WiFi,
wifiSSID = "Wireless-1",
wifiMode = WeaveDeviceMgr.WiFiMode_Managed,
wifiRole = WeaveDeviceMgr.WiFiRole_Station,
wifiSecurityType = WeaveDeviceMgr.WiFiSecurityType_None)
try:
addResult = devMgr.AddNetwork(networkInfo)
except WeaveDeviceMgr.DeviceManagerException, ex:
print ex
exit()
lastNetworkId = addResult
print "Add wifi network complete (network id = " + str(addResult) + ")"
print ''
addResult = devMgr.AddNetwork(networkInfo)
except WeaveDeviceMgr.DeviceManagerException, ex:
print ex
exit()
lastNetworkId = addResult
print "Add wifi network complete (network id = " + str(addResult) + ")"
print ''
print '#################################update-network#################################'
# networkInfo = WeaveDeviceMgr.NetworkInfo(networkId=lastNetworkId)
networkInfo = WeaveDeviceMgr.NetworkInfo(
networkType = WeaveDeviceMgr.NetworkType_WiFi,
networkId=lastNetworkId,
wifiSSID = "Wireless-1",
wifiMode = WeaveDeviceMgr.WiFiMode_Managed,
wifiRole = WeaveDeviceMgr.WiFiRole_Station,
wifiSecurityType = WeaveDeviceMgr.WiFiSecurityType_None)
try:
devMgr.UpdateNetwork(networkInfo)
except WeaveDeviceMgr.DeviceManagerException, ex:
print str(ex)
exit()
print "Update network complete"
print ''
print '#################################disable-network#################################'
category = 2
elif (category == 'detail'):
category = 3
try:
devMgr.SetLogFilter(category)
except WeaveDeviceMgr.DeviceManagerException, ex:
print str(ex)
exit()
print "Done."
print ''
print '#################################scan-network#################################'
try:
networkType = WeaveDeviceMgr.ParseNetworkType("wifi")
scanResult = devMgr.ScanNetworks(networkType)
except WeaveDeviceMgr.DeviceManagerException, ex:
print ex
print "ScanNetworks complete, %d network(s) found" % (len(scanResult))
i = 1
for net in scanResult:
print " Network %d" % (i)
net.Print(" ")
i = i + 1
try:
networkType = WeaveDeviceMgr.ParseNetworkType("thread")
scanResult = devMgr.ScanNetworks(networkType)
except WeaveDeviceMgr.DeviceManagerException, ex:
print ex
print "ScanNetworks complete, %d network(s) found" % (len(scanResult))
i = 1
bleManager = BleManager(devMgr)
try:
bleManager.ble_adapter_select(identifier=options.bleSrcAddr)
except WeaveDeviceMgr.DeviceManagerException, ex:
print ex
exit()
try:
line = ' ' + str(options.bleDstAddr)
bleManager.scan_connect(line)
except WeaveDeviceMgr.DeviceManagerException, ex:
print ex
exit()
devMgr.ConnectBle(bleConnection=FAKE_CONN_OBJ_VALUE,
pairingCode=options.pairingCode,
accessToken=options.accessToken)
try:
devMgr.Close()
devMgr.CloseEndpoints()
bleManager.disconnect()
except WeaveDeviceMgr.DeviceManagerException, ex:
print str(ex)
exit()
print "WoBLE central is good to go"
print "Shutdown complete"
exit()
else:
devMgr.ConnectDevice(deviceId=nodeId, deviceAddr=addr,
print "Connection monitor enabled"
print ''
print '#################################disable-connection-monitor#################################'
try:
devMgr.DisableConnectionMonitor()
except WeaveDeviceMgr.DeviceManagerException, ex:
print str(ex)
exit()
print "Connection monitor disabled"
print ''
print '#################################start-system-test#################################'
try:
devMgr.StartSystemTest(WeaveDeviceMgr.SystemTest_ProductList["thermostat"], 1)
except WeaveDeviceMgr.DeviceManagerException, ex:
print str(ex)
exit()
print "Start system test complete"
print ''
print '#################################stop-system-test#################################'
try:
devMgr.StopSystemTest()
except WeaveDeviceMgr.DeviceManagerException, ex:
print str(ex)
exit()
print "Stop system test complete"
print ''
devMgr.Close()
devMgr.CloseEndpoints()
except WeaveDeviceMgr.DeviceManagerException, ex:
print str(ex)
exit()
print ''
print '#################################rendezvous2#################################'
try:
devMgr.RendezvousDevice(
pairingCode=options.pairingCode,
targetFabricId=WeaveDeviceMgr.TargetFabricId_AnyFabric,
targetModes=WeaveDeviceMgr.TargetDeviceMode_Any,
targetVendorId=WeaveDeviceMgr.TargetVendorId_Any,
targetProductId=WeaveDeviceMgr.TargetProductId_Any,
targetDeviceId=WeaveDeviceMgr.TargetDeviceId_Any)
except WeaveDeviceMgr.DeviceManagerException, ex:
print str(ex)
exit()
print "Connected to device %X at %s" % (nodeId, addr)
print ''
print '#################################close#################################'
try:
devMgr.Close()
devMgr.CloseEndpoints()
except WeaveDeviceMgr.DeviceManagerException, ex:
print str(ex)
exit()