def read_paramDescriptors(paramTypes): params = [] for paramType in paramTypes: selectionTypes = ["yes", "no"] selectionText = "-> Do you want to create a descriptor for the param \"%s\"?" % ( paramType['displayName']) selection = nymea.get_selection(selectionText, selectionTypes) if selectionTypes[selection] == "no": continue operator = nymea.select_valueOperator(paramType['displayName']) if paramType['type'] == "Bool": boolTypes = ["true", "false"] selectionString = "Please enter value for parameter \"%s\" (type: %s): " % ( paramType['displayName'], paramType['type']) selection = nymea.get_selection(selectionString, boolTypes) if selection == None: return None paramValue = boolTypes[selection] else: print "Please enter value for parameter \"%s\" (type: %s): " % ( paramType['displayName'], paramType['type']) paramValue = raw_input("%s %s " % (paramType['displayName'], nymea.get_valueOperator_string(operator))) param = {} param['paramTypeId'] = paramType['id'] param['value'] = paramValue param['operator'] = operator params.append(param) #print "got params:", nymea.print_json_format(params) return params
def execute_rule_actions(): ruleDescription = select_rule() if ruleDescription == None: print "\n No rules found" return None ruleId = ruleDescription['id'] params = {} params['ruleId'] = ruleId rule = nymea.send_command("Rules.GetRuleDetails", params)['params']['rule'] if len(rule['exitActions']) == 0: options = ["Execute actions"] selection = nymea.get_selection( "Which actions of the rule should be executed?", options) response = nymea.send_command("Rules.ExecuteActions", params) nymea.print_rule_error_code(response['params']['ruleError']) else: options = ["Execute actions", "Execute exit actions"] selection = nymea.get_selection( "Which actions of the rule should be executed?", options) if selection == None: return None if (options[selection] == "Execute actions"): response = nymea.send_command("Rules.ExecuteActions", params) nymea.print_rule_error_code(response['params']['ruleError']) else: response = nymea.send_command("Rules.ExecuteExitActions", params) nymea.print_rule_error_code(response['params']['ruleError']) return None
def create_time_filter(): timeFilter = {} boolTypes = ["yes", "no"] selection = nymea.get_selection("Do you want to define a \"Start date\"?", boolTypes) if boolTypes[selection] == "yes": timeFilter['startDate'] = raw_input( "Please enter the \"Start date\": ") selection = nymea.get_selection("Do you want to define a \"End date\"?", boolTypes) if boolTypes[selection] == "yes": timeFilter['endDate'] = raw_input("Please enter the \"End date\": ") return timeFilter
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 = nymea.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 = nymea.get_selection("Please select a device descriptor", deviceDescriptorList) if selection != None: return deviceDescriptorIdList[selection] return None
def createTimeDescriptor(): print "\n========================================================" print "Create time descriptor\n" timeDescriptor = {} enough = False options = ["Create calendar items", "Create time event items"] selection = nymea.get_selection( "Which kind of time items do you want to create?", options) if options[selection] == "Create calendar items": calendarItems = [] while not enough: calendarItems.append(createCalendarItem()) input = raw_input( "Do you want to add another calendar item? (y/N): ") if not input == "y": enough = True timeDescriptor['calendarItems'] = calendarItems return timeDescriptor else: timeEventItems = [] while not enough: timeEventItems.append(createTimeEventItem()) input = raw_input( "Do you want to add another time event item? (y/N): ") if not input == "y": enough = True timeDescriptor['timeEventItems'] = timeEventItems return timeDescriptor
def add_network(): # First get the list of adapters response = nymea.send_command("Zigbee.GetAdapters", {}) if len(response['params']['adapters']) == 0: print "There are no adapters available." return None adapterList = []; for adapter in response['params']['adapters']: adapterList.append("%s (%s) - %s" % (adapter['description'], adapter['serialPort'], adapter['name'])) selection = nymea.get_selection("Please select a device descriptor", adapterList) selectedAdapter = {} if selection != None: selectedAdapter = response['params']['adapters'][selection] else: print "ERROR: invalid adapter selection." return None print("Selected adapter:") nymea.print_json_format(selectedAdapter) params = {} params["serialPort"] = selectedAdapter["serialPort"] params["baudRate"] = selectedAdapter["baudRate"] params["backend"] = selectedAdapter["backend"] response = nymea.send_command("Zigbee.AddNetwork", params) print("Add network returned %s" % response["params"]["zigbeeError"]) if response["params"]["zigbeeError"] == "ZigbeeErrorNoError": print("New network has the uuid %s" % response["params"]["networkUuid"])
def edit_params(currentDeviceParams, paramTypes): params = [] for paramType in paramTypes: print "\nThe ParamType looks like this:\n", nymea.print_json_format( paramType) if 'readOnly' in paramType and paramType['readOnly']: print "--------------------------------------------------------" print "\nThe param \"%s\" is not writable! (current = \"%s\")\n" % ( paramType['displayName'], get_param_value(paramType['id'], currentDeviceParams)) raw_input("\nPress \"enter\" to continue...\n") print "--------------------------------------------------------" continue param = {} if any("allowedValues" in item for item in paramType) and len(paramType['allowedValues']) != 0: title = "Please select one of following allowed values: (current = \"%s\")" % ( get_param_value(paramType['id'], currentDeviceParams)) selection = nymea.get_selection(title, paramType['allowedValues']) if selection == None: return None paramValue = paramType['allowedValues'][selection] param['paramTypeId'] = paramType['id'] param['value'] = paramValue params.append(param) else: # make bool selectable to make shore they are "true" or "false" if paramType['type'] == "Bool": boolTypes = ["true", "false"] selectionString = "Please enter value (currently: \"%s\") for parameter \"%s\" (type: %s): " % ( get_param_value(paramType['id'], currentDeviceParams), paramType['displayName'], paramType['type']) selection = nymea.get_selection(selectionString, boolTypes) if selection == None: return None paramValue = boolTypes[selection] param['paramTypeId'] = paramType['id'] param['value'] = paramValue else: paramValue = raw_input( "Please enter value (currently: \"%s\") for parameter \"%s\" (type: %s): " % (get_param_value(paramType['id'], currentDeviceParams), paramType['displayName'], paramType['type'])) param['paramTypeId'] = paramType['id'] param['value'] = paramValue params.append(param) return params
def getYesNoSelection(question): responseTypes = ["yes", "no"] selection = nymea.get_selection(question, responseTypes) if responseTypes[selection] == "yes": return True elif responseTypes[selection] == "no": return False else: return None
def createRepeatingOption(forDateTime=False): print "\n========================================================" print "Create repeating option\n" repeatingOption = {} if forDateTime: options = ["Repeat yearly"] selection = nymea.get_selection("Please select the repeating mode:", options) repeatingOption['mode'] = "RepeatingModeYearly" print repeatingOption return repeatingOption options = [ "0. Repeat hourly", "1. Repeat daily", "2. Repeat weekly", "3. Repeat monthly", "4. Repeat yearly" ] selection = nymea.get_selection("Please select the repeating mode:", options) if selection is 0: repeatingOption['mode'] = "RepeatingModeHourly" if selection is 1: repeatingOption['mode'] = "RepeatingModeDaily" if selection is 2: repeatingOption['mode'] = "RepeatingModeWeekly" weekDaysString = raw_input( "Please enter the list of week days (space separated [1-7]): ") repeatingOption['weekDays'] = [ int(weekDay) for weekDay in weekDaysString.split() ] if selection is 3: repeatingOption['mode'] = "RepeatingModeMonthly" monthDaysString = raw_input( "Please enter the list of month days (space separated [1-31]): ") repeatingOption['monthDays'] = [ int(monthDay) for monthDay in monthDaysString.split() ] print repeatingOption return repeatingOption
def set_language(): params = {} languages = get_languages() selection = nymea.get_selection( "Please select one of following allowed values:", languages) if selection == None: return None params['language'] = languages[selection] response = nymea.send_command("Configuration.SetLanguage", params) nymea.print_json_format(response['params'])
def set_timezone(): params = {} timeZones = [] timeZones = get_timezones() selection = nymea.get_selection( "Please select one of following allowed values:", timeZones) if selection == None: return None params['timeZone'] = timeZones[selection] response = nymea.send_command("Configuration.SetTimeZone", params) nymea.print_json_format(response['params'])
def enable_cloud_connection(): params = {} options = ["enable", "disable"] selection = nymea.get_selection( "Do you want to do with the cloud connection: ", options) if selection == 0: params['enable'] = True else: params['enable'] = False response = nymea.send_command("Cloud.Enable", params) nymea.print_json_format(response['params'])
def select_eventType(deviceClassId): eventTypes = get_eventTypes(deviceClassId) if not eventTypes: return None eventTypeList = [] for i in range(len(eventTypes)): eventTypeList.append(eventTypes[i]['displayName']) selection = nymea.get_selection("Please select an event type:", eventTypeList) if selection != None: return eventTypes[selection] return None
def select_createMethod(title, createMethods): if len(createMethods) == 0: print "ERROR: this device has no createMethods. Please check the plugin code!!!" return None elif len(createMethods) == 1: return createMethods[0] else: selection = nymea.get_selection(title, createMethods) if selection == None: print "ERROR: could not get selection of CreateMethod" return None return createMethods[selection]
def enable_networking(): params = {} options = ["enable", "disable"] selection = nymea.get_selection("Do you want to do with the networking: ", options) if selection == 0: params['enable'] = True else: params['enable'] = False response = nymea.send_command("NetworkManager.EnableNetworking", params) nymea.print_networkmanager_error_code( response['params']['networkManagerError'])
def select_configured_device(): devices = get_configured_devices() if not devices: print "\n No configured device found.\n" return None deviceList = [] deviceIdList = [] for i in range(len(devices)): deviceList.append(devices[i]['name']) deviceIdList.append(devices[i]['id']) selection = nymea.get_selection("Please select a device", deviceList) if selection != None: return deviceIdList[selection] return None
def select_vendor(): vendors = get_supported_vendors()['params']['vendors'] if not vendors: print "\n No vendors found. Please install nymea-plugins and restart nymead." return None vendorList = [] vendorIdList = [] for i in range(0, len(vendors)): vendorList.append(vendors[i]['displayName']) vendorIdList.append(vendors[i]['id']) selection = nymea.get_selection("Please select a vendor", vendorList) if selection != None: return vendorIdList[selection] return None
def select_actionType(deviceClassId): actions = get_actionTypes(deviceClassId) if not actions: return None actionList = [] #print "got actions", actions for i in range(len(actions)): #print "got actiontype", actions[i] actionList.append(actions[i]['displayName']) selection = nymea.get_selection("Please select an action type:", actionList) if selection != None: return actions[selection] return None
def select_stateType(deviceClassId): stateTypes = get_stateTypes(deviceClassId) if not stateTypes: print "\n This device has no states.\n" print "\n========================================================" raw_input("-> Press \"enter\" to select an other device! ") return None stateTypeList = [] for i in range(len(stateTypes)): stateTypeList.append(stateTypes[i]['displayName']) selection = nymea.get_selection("Please select a state type:", stateTypeList) if selection != None: return stateTypes[selection] return None
def enable_disable_rule(): ruleDescription = select_rule() if ruleDescription == None: print "\n No rules found" return actionTypes = ["enable", "disable"] selection = nymea.get_selection("What do you want to do with this rule: ", actionTypes) if selection == 0: params = {} params['ruleId'] = ruleDescription['id'] response = nymea.send_command("Rules.EnableRule", params) nymea.print_rule_error_code(response['params']['ruleError']) else: params = {} params['ruleId'] = ruleDescription['id'] response = nymea.send_command("Rules.DisableRule", params) nymea.print_rule_error_code(response['params']['ruleError'])
def selectNetwork(message): params = {} response = nymea.send_command("Zigbee.GetNetworks", params) nymea.print_json_format(response['params']) if len(response['params']['zigbeeNetworks']) == 0: print "ERROR: there are no networks configured." return None networkList = []; for network in response['params']['zigbeeNetworks']: networkList.append("%s %s (channel %s) - %s" % (network['backend'], network['macAddress'], network['channel'], network['serialPort'])) selection = nymea.get_selection(message, networkList) selectedNetwork = {} if selection != None: return response['params']['zigbeeNetworks'][selection] else: return None
def select_deviceClass(): vendorId = select_vendor() if not vendorId: return None deviceClasses = get_deviceClasses(vendorId) if not deviceClasses: print "\n No supported devices for this vendor\n" return None deviceClassList = [] deviceClassIdList = [] for i in range(0, len(deviceClasses)): deviceClassList.append(deviceClasses[i]['displayName']) deviceClassIdList.append(deviceClasses[i]['id']) selection = nymea.get_selection("Please select device class", deviceClassList) if selection != None: return deviceClassIdList[selection] return None
def select_rule(): ruleDescriptions = [] ruleDescriptions = nymea.send_command("Rules.GetRules", {})['params']['ruleDescriptions'] if not ruleDescriptions: print "\n No rule found" return None descriptions = [] for ruleDescription in ruleDescriptions: descriptions.append( "%s (%s) -> %s / %s" % (ruleDescription['name'], ruleDescription['id'], print_rule_enabled_status(ruleDescription['enabled']), print_rule_active_status(ruleDescription['active']))) selection = nymea.get_selection("Please select rule:", descriptions) if selection != None: return ruleDescriptions[selection] return None
def selectWirelessInterface(): params = {} response = nymea.send_command("NetworkManager.GetNetworkDevices", params) if response['params'][ 'networkManagerError'] != 'NetworkManagerErrorNoError': print("There is no wireless interface available") nymea.print_networkmanager_error_code( response['params']['networkManagerError']) return None if len(response['params']['wirelessNetworkDevices']) is 1: return response['params']['wirelessNetworkDevices'][0]['interface'] else: interfaces = [] for wirelessNetworkDevice in response['params'][ 'wirelessNetworkDevices']: interfaces.append(wirelessNetworkDevice['interface']) selection = nymea.get_selection("Please select a wifi interface:", interfaces) return interfaces[selection]
def remove_configured_device(): deviceId = select_configured_device() if not deviceId: return None print "Removing device with DeviceId%s" % deviceId params = {} params['deviceId'] = deviceId response = nymea.send_command("Devices.RemoveConfiguredDevice", params) if response['params']['deviceError'] == 'DeviceErrorDeviceInRule': selectionString = "This device is used in a rule. How do you want to remove the device from the rules?" removePolicys = [ "Remove the device from the rules", "Delete all offending rules" ] selection = nymea.get_selection(selectionString, removePolicys) if removePolicys[selection] == "Remove the device from the rules": params['removePolicy'] = "RemovePolicyUpdate" else: params['removePolicy'] = "RemovePolicyCascade" response = nymea.send_command("Devices.RemoveConfiguredDevice", params) nymea.print_device_error_code(response['params']['deviceError'])
def create_logfilter(): params = {} boolTypes = ["yes", "no"] # Devices selection = nymea.get_selection("Do you want to filter for \"Devices\"? ", boolTypes) if boolTypes[selection] == "yes": deviceIds = [] deviceId = devices.select_configured_device() deviceIds.append(deviceId) finished = False while not finished: selection = nymea.get_selection( "Do you want to add an other \"Device\"? ", boolTypes) if boolTypes[selection] == "no": finished = True break deviceId = devices.select_configured_device() if not deviceId: params['deviceIds'] = deviceIds return params deviceIds.append(deviceId) params['deviceIds'] = deviceIds # LoggingSources selection = nymea.get_selection( "Do you want to filter for \"LoggingSource\"? ", boolTypes) if boolTypes[selection] == "yes": sources = [] finished = False loggingSources = [ "LoggingSourceSystem", "LoggingSourceEvents", "LoggingSourceActions", "LoggingSourceStates", "LoggingSourceRules" ] selection = nymea.get_selection("Please select a \"LoggingSource\": ", loggingSources) if selection: sources.append(loggingSources[selection]) else: finished = True while not finished: selection = nymea.get_selection( "Do you want to add an other \"LoggingSource\"? ", boolTypes) if boolTypes[selection] == "no": finished = True break selection = get_selection("Please select a \"LoggingSource\": ", loggingSources) if selection: sources.append(loggingSources[selection]) else: finished = True break params['loggingSources'] = sources # LoggingLevel selection = nymea.get_selection( "Do you want to filter for \"LoggingLevel\"? ", boolTypes) if boolTypes[selection] == "yes": levels = [] loggingLevels = ["LoggingLevelInfo", "LoggingLevelAlert"] selection = nymea.get_selection("Please select a \"LoggingLevel\": ", loggingLevels) if selection: levels.append(loggingLevels[selection]) params['loggingLevels'] = levels # LoggingEventType selection = nymea.get_selection( "Do you want to filter for \"LoggingEventType\"? ", boolTypes) if boolTypes[selection] == "yes": types = [] loggingEventTypes = [ "LoggingEventTypeTrigger", "LoggingEventTypeActiveChange", "LoggingEventTypeEnabledChange", "LoggingEventTypeActionsExecuted", "LoggingEventTypeExitActionsExecuted" ] selection = nymea.get_selection( "Please select a \"LoggingEventType\": ", loggingEventTypes) if selection: types.append(loggingEventTypes[selection]) params['eventTypes'] = types # Value selection = nymea.get_selection( "Do you want to filter for certain log \"Values\"? ", boolTypes) if boolTypes[selection] == "yes": values = [] finished = False value = raw_input("Please enter value which should be filtered out: ") values.append(value) while not finished: selection = nymea.get_selection( "Do you want to add an other \"Value\"? ", boolTypes) if boolTypes[selection] == "no": finished = True break value = raw_input( "Please enter value which should be filtered out: ") values.append(value) params['values'] = values # Times selection = nymea.get_selection("Do you want to add a \"TimeFilter\"? ", boolTypes) if boolTypes[selection] == "yes": timeFilters = [] finished = False timeFilters.append(create_time_filter()) while not finished: selection = nymea.get_selection( "Do you want to add an other \"TimeFilter\"? ", boolTypes) if boolTypes[selection] == "no": finished = True break timeFilters.append(create_time_filter()) params['timeFilters'] = timeFilters nymea.print_json_format(params) nymea.debug_stop() return params
def read_params(paramTypes): params = [] for paramType in paramTypes: print "\nThe ParamType looks like this:\n", nymea.print_json_format( paramType) if 'readOnly' in paramType and paramType['readOnly']: print "--------------------------------------------------------" print "\nThe param \"%s\" is not writable!)\n" % ( paramType['displayName']) raw_input("\nPress \"enter\" to continue...\n") print "--------------------------------------------------------" param = {} param['paramTypeId'] = paramType['id'] param['value'] = paramType.get('defaultValue', '') elif any("allowedValues" in item for item in paramType) and len( paramType['allowedValues']) != 0: # has to be a string (for sorting list) allowedValues = [] for value in paramType['allowedValues']: allowedValues.append(str(value)) selection = nymea.get_selection( "Please select one of following allowed values:", allowedValues) if selection == None: return None paramValue = paramType['allowedValues'][selection] param = {} param['paramTypeId'] = paramType['id'] param['value'] = paramValue else: # make bool selectable to make shore they are "true" or "false" if paramType['type'] == "Bool": boolTypes = ["true", "false"] selectionString = "Please enter value for parameter \"%s\" (type: %s): " % ( paramType['displayName'], paramType['type']) selection = nymea.get_selection(selectionString, boolTypes) if selection == None: return None paramValue = boolTypes[selection] elif paramType['type'] == "Int": paramValue = int( raw_input( "Please enter value for parameter \"%s\" (type: %s): " % (paramType['displayName'], paramType['type']))) elif paramType['type'] == "Double": paramValue = float( raw_input( "Please enter value for parameter \"%s\" (type: %s): " % (paramType['displayName'], paramType['type']))) elif paramType['type'] == "Uint": paramValue = int( raw_input( "Please enter value for parameter \"%s\" (type: %s): " % (paramType['displayName'], paramType['type']))) else: paramValue = raw_input( "Please enter value for parameter \"%s\" (type: %s): " % (paramType['displayName'], paramType['type'])) param = {} param['paramTypeId'] = paramType['id'] param['value'] = paramValue params.append(param) return params
def read_ruleActionParams(paramTypes, eventDescriptors=[]): params = [] for paramType in paramTypes: print nymea.print_json_format(paramType) if any("allowedValues" in item for item in paramType): selection = nymea.get_selection( "Please select one of following allowed values:", paramType['allowedValues']) if selection == None: return None paramValue = paramType['allowedValues'][selection] param = {} param['paramTypeId'] = paramType['id'] param['value'] = paramValue params.append(param) else: # check if we want normal action params or if we want to use an eventtypeid if eventDescriptors: selectionTypes = ["yes", "no"] selectionText = "-> Should the ruleActionParam \"%s\" depend on an event?" % ( paramType['displayName']) selection = nymea.get_selection(selectionText, selectionTypes) if selection == None: return None if selectionTypes[selection] == "yes": eventTypeIds = [] for i in eventDescriptors: eventTypeIds.append(i['eventTypeId']) selection = nymea.get_selection( "Please select an eventTypeId", eventTypeIds) eventTypeId = eventTypeIds[selection] eventType = events.get_eventType(eventTypeId) eventParamNames = [] eventParamTypeIds = [] for i in eventType['paramTypes']: eventParamNames.append(i['displayName']) eventParamTypeIds.append(i['id']) paramSelection = nymea.get_selection( "Please select the name of the eventParam for the action", eventParamNames) param = {} param['paramTypeId'] = paramType['id'] param['eventTypeId'] = eventTypeId param['eventParamTypeId'] = eventParamTypeIds[ paramSelection] params.append(param) else: if paramType['type'] == "Bool": boolTypes = ["true", "false"] selectionString = "Please enter value for parameter %s (type: %s): " % ( paramType['displayName'], paramType['type']) selection = nymea.get_selection( selectionString, boolTypes) if selection == None: return None paramValue = boolTypes[selection] elif paramType['type'] == "Int": paramValue = int( raw_input( "Please enter value for parameter \"%s\" (type: %s): " % (paramType['displayName'], paramType['type']))) elif paramType['type'] == "Double": paramValue = double( raw_input( "Please enter value for parameter \"%s\" (type: %s): " % (paramType['displayName'], paramType['type']))) elif paramType['type'] == "Uint": paramValue = uint( raw_input( "Please enter value for parameter \"%s\" (type: %s): " % (paramType['displayName'], paramType['type']))) else: paramValue = raw_input( "Please enter value for parameter \"%s\" (type: %s): " % (paramType['displayName'], paramType['type'])) param = {} param['paramTypeId'] = paramType['id'] param['value'] = paramValue params.append(param) else: # make bool selectable to make shore they are "true" or "false" if paramType['type'] == "Bool": boolTypes = ["true", "false"] selectionString = "Please enter value for parameter %s (type: %s): " % ( paramType['displayName'], paramType['type']) selection = nymea.get_selection(selectionString, boolTypes) if selection == None: return None paramValue = boolTypes[selection] elif paramType['type'] == "Int": paramValue = int( raw_input( "Please enter value for parameter \"%s\" (type: %s): " % (paramType['displayName'], paramType['type']))) elif paramType['type'] == "Double": paramValue = float( raw_input( "Please enter value for parameter \"%s\" (type: %s): " % (paramType['displayName'], paramType['type']))) elif paramType['type'] == "Uint": paramValue = int( raw_input( "Please enter value for parameter \"%s\" (type: %s): " % (paramType['displayName'], paramType['type']))) else: paramValue = raw_input( "Please enter value for parameter \"%s\" (type: %s): " % (paramType['displayName'], paramType['type'])) param = {} param['paramTypeId'] = paramType['id'] param['value'] = paramValue params.append(param) return params
def configure_webSocketServer(): configurations = nymea.send_command("Configuration.GetConfigurations") webSocketConfigs = configurations['params'][ 'webSocketServerConfigurations'] configList = [] for i in range(len(webSocketConfigs)): configList.append( "%s:%s SSL:%s Auth:%s" % (webSocketConfigs[i]['address'], webSocketConfigs[i]['port'], webSocketConfigs[i]['sslEnabled'], webSocketConfigs[i]['authenticationEnabled'])) configList.append("New entry") selection = nymea.get_selection("Please select a configuration", configList) if selection == None: return None params = {} configuration = {} if selection == len(configList) - 1: # new config configuration['id'] = str(uuid.uuid4()) configuration['address'] = raw_input( "\nEnter the \"address\" of the WebSocket server: ") configuration['port'] = raw_input( "\nEnter the \"port\" of the WebSocket server: ") configuration['sslEnabled'] = selector.getYesNoSelection( "Should SSL be enabled?") configuration['authenticationEnabled'] = selector.getYesNoSelection( "Should authentication be enabled?") else: selectedConfig = webSocketConfigs[selection] editList = [] editList.append("Modify") editList.append("Delete") editSelection = nymea.get_selection( "Do you want to edit or delete the server interface?", editList) if editSelection == None: return None if editSelection == 1: #delete params = {} params['id'] = selectedConfig['id'] nymea.send_command( "Configuration.DeleteWebSocketServerConfiguration", params) return None configuration['id'] = selectedConfig['id'] configuration['address'] = raw_input( "\nEnter the \"address\" of the WebSocket server (current \"%s\"): " % (selectedConfig['address'])) configuration['port'] = raw_input( "\nEnter the \"port\" of the WebSocket server (current %s): " % (selectedConfig['port'])) configuration['sslEnabled'] = selector.getYesNoSelection( "Should SSL be enabled? (current \"%s\"): " % (selectedConfig['sslEnabled'])) configuration['authenticationEnabled'] = selector.getYesNoSelection( "Should authentication be enabled? (current %s): " % (selectedConfig['authenticationEnabled'])) params['configuration'] = configuration response = nymea.send_command( "Configuration.SetWebSocketServerConfiguration", params) nymea.print_json_format(response['params'])
def create_stateDescriptor(): print "-> Creating a new stateDescriptor:\n" deviceId = devices.select_configured_device() device = devices.get_device(deviceId) if device == None: return None stateType = select_stateType(device['deviceClassId']) if stateType == None: return None valueOperator = nymea.select_valueOperator(stateType['displayName']) stateDescriptor = {} print "\nThe StateType looks like this:\n", nymea.print_json_format( stateType) print "Please enter the value for state \"%s\" (type: %s): " % ( stateType['displayName'], stateType['type']) # make bool selectable to make shore they are "true" or "false" if any("possibleValues" in item for item in stateType): # has to be a string (for sorting list) possibleValues = [] for value in stateType['possibleValues']: possibleValues.append(str(value)) selection = nymea.get_selection( "Please select one of following possible values:", possibleValues) if selection == None: return None stateValue = stateType['possibleValues'][selection] else: # make bool selectable to make shore they are "true" or "false" if stateType['type'] == "Bool": boolTypes = ["true", "false"] selectionString = "Please enter the value for state \"%s\" (type: %s): " % ( stateType['displayName'], stateType['type']) selection = nymea.get_selection(selectionString, boolTypes) if selection == None: return None stateValue = boolTypes[selection] elif stateType['type'] == "Int": stateValue = int( raw_input("%s %s " % (stateType['displayName'], nymea.get_valueOperator_string(valueOperator)))) elif stateType['type'] == "Double": stateValue = float( raw_input("%s %s " % (stateType['displayName'], nymea.get_valueOperator_string(valueOperator)))) elif stateType['type'] == "Uint": stateValue = int( raw_input("%s %s " % (stateType['displayName'], nymea.get_valueOperator_string(valueOperator)))) else: stateValue = raw_input( "%s %s " % (stateType['displayName'], nymea.get_valueOperator_string(valueOperator))) stateDescriptor['deviceId'] = deviceId stateDescriptor['stateTypeId'] = stateType['id'] stateDescriptor['value'] = stateValue stateDescriptor['operator'] = valueOperator print nymea.print_json_format(stateDescriptor) return stateDescriptor