def discover_device(deviceClassId=None): if deviceClassId == None: deviceClassId = select_deviceClass() deviceClass = get_deviceClass(deviceClassId) if not deviceClass: return None params = {} params['deviceClassId'] = deviceClassId discoveryParams = parameters.read_params( deviceClass['discoveryParamTypes']) if len(discoveryParams) > 0: params['discoveryParams'] = discoveryParams print "\ndiscovering..." response = guh.send_command("Devices.GetDiscoveredDevices", params) if not 'deviceDescriptors' in response['params']: print "no devices found" deviceDescriptorList = [] deviceDescriptorIdList = [] for deviceDescriptor in response['params']['deviceDescriptors']: deviceDescriptorList.append( "%s (%s)" % (deviceDescriptor['title'], deviceDescriptor['description'])) deviceDescriptorIdList.append(deviceDescriptor['id']) if not deviceDescriptorIdList: print "\n Timeout: no device found." return None selection = guh.get_selection("Please select a device descriptor", deviceDescriptorList) if selection != None: return deviceDescriptorIdList[selection] return None
def set_plugin_configuration(): pluginId = select_configurable_plugin() plugin = get_plugin(pluginId) paramTypes = plugin['paramTypes'] params = {} params['pluginId'] = pluginId params['configuration'] = parameters.read_params(paramTypes) response = guh.send_command("Devices.SetPluginConfiguration", params) guh.print_device_error_code(response['params']['deviceError'])
def add_configured_device(deviceClassId): deviceClass = get_deviceClass(deviceClassId) params = {} params['deviceClassId'] = deviceClassId params['name'] = raw_input("\nEnter the \"name\" of the device: ") deviceParams = parameters.read_params(deviceClass['paramTypes']) if deviceParams: params['deviceParams'] = deviceParams print "\nAdding device with params:", guh.print_json_format(params) response = guh.send_command("Devices.AddConfiguredDevice", params) guh.print_device_error_code(response['params']['deviceError'])
def execute_action(): deviceId = devices.select_configured_device() if deviceId == None: return None device = devices.get_device(deviceId) actionType = select_actionType(device['deviceClassId']) #print nymea.print_json_format(actionType) if actionType == None: print "\n This device has no actions" return None actionTypeId = actionType['id'] params = {} params['actionTypeId'] = actionTypeId params['deviceId'] = deviceId actionType = get_actionType(actionTypeId) actionParams = parameters.read_params(actionType['paramTypes']) params['params'] = actionParams response = nymea.send_command("Actions.ExecuteAction", params) if response: nymea.print_device_error_code(response['params']['deviceError'])
def create_actions(): enough = False actions = [] while not enough: print "\n========================================================" raw_input("-> Press \"enter\" to create actions! ") deviceId = devices.select_configured_device() if not deviceId: return None device = devices.get_device(deviceId) actionType = select_actionType(device['deviceClassId']) if not actionType: continue params = parameters.read_params(actionType['paramTypes']) action = {} action['deviceId'] = deviceId action['actionTypeId'] = actionType['id'] if len(params) > 0: action['params'] = params actions.append(action) input = raw_input("Do you want to add another action? (y/N): ") if not input == "y": enough = True return actions