def read(self, from_values): self.component_lookup = { x.type: x.instantiate for x in self.context.components if x.category == self.category } val = from_values.get(self.name) if val is None: val = self.default if not isinstance(val, dict): raise iot_api_core.IotException(400, 'Invalid Value: ' + str(val)) component_type = val.get('componentType', '__NOTYPE__') component_data = val.get('componentData', {}) component_factory = self.component_lookup.get(component_type) if component_factory: component = component_factory() component.load(component_data) result = { 'componentType': component.component_type, 'componentData': component.to_json(), 'displayName': component.display_name } val = result else: raise iot_api_core.IotException(400, 'Invalid Value: ' + component_type) self.value = val return val
def read(self, from_values): self.component_lookup = { x.type: x.instantiate for x in self.context.components if x.category == self.category } val = from_values.get(self.name) if val is None: val = self.default components = [] for c in val: comp_values = {} component_type = c.get('componentType', '__NOTYPE__') component_data = c.get('componentData', {}) component_factory = self.component_lookup.get(component_type) if component_factory: component = component_factory() component.load(component_data) result = { 'componentType': component.component_type, 'componentData': component.to_json(), 'displayName': component.display_name } components.append(result) else: raise iot_api_core.IotException( 400, 'Invalid Value: ' + component_type) self.value = components return components
def read(self, from_values): val = super().read(from_values) if not bool(_rgbstring.match(val)): raise iot_api_core.IotException(400, 'Invalid Color: ' + val) self.value = val return val
def read(self, from_values): val = from_values.get(self.name) if val is None: val = self.default try: val = int(val) except Exception as e: raise iot_api_core.IotException(400, 'Invalid Number: ' + str(val)) if (self.options['min'] is not None and val < self.options['min']) or ( self.options['max'] is not None and val > self.options['max']): raise iot_api_core.IotException( 400, 'Invalid Number: ' + str(val) + ' - must be in range ' + str(self.options['min']) + ' to ' + str(self.options['max'])) self.value = val return str(val)
def read(self, from_values): val = from_values.get(self.name) if val is None: val = self.default try: if val is not None: val = int(val) except: raise iot_api_core.IotException(400, 'Invalid Int: ' + str(val)) self.value = val return val
def read(self, from_values): val = from_values.get(self.name) check_hash = {str(x): x for x in self.options} check_hash['None'] = None if val is None: val = self.default if str(val) not in check_hash: raise iot_api_core.IotException( 400, 'Invalid Value: ' + str(val) + ' - must be in set ' + ','.join(list(self.options.keys()))) self.value = check_hash[str(val)] return self.value
def read(self, from_values): val = from_values.get(self.name) result = {} if val is None: val = self.default no_image = '/icons/iot/' + current_app.config['WIDGET_ID'] + '/api/instances/icons/no_image_available.png' no_image_payload = { 'preview': no_image, 'previewLarge': no_image, 'previewMedium': no_image, 'previewSmall': no_image } result['mode'] = str(val.get('mode', 'model-image')) if result['mode'] not in ['model-image', 'upload']: raise iot_api_core.IotException(400, 'Invalid mode: ' + result['mode']) if result['mode'] == 'upload': result.update(self.read_image(val)) elif result['mode'] == 'model-image': if self.context.model_id: model_info = self.context.model_info if model_info['image'] and 'key' in model_info['image']: data = { 'key': model_info['image']['key'], 'version': model_info['image']['versionId'] } payload = self.context.lumavate.get('/iot/v1/files/preview/' + model_info['image']['key'] + '/' + model_info['image']['versionId']) result.update(payload) result['modelKey'] = result['key'] result['modelVersion'] = result['version'] del result['key'] del result['version'] else: result.update(no_image_payload) else: result.update(no_image_payload) self.value = result return result
def read(self, from_values): val = from_values.get(self.name) result = {} if val is None: val = self.default result['mode'] = str(val.get('mode', 'model-name')) if result['mode'] not in ['model-name', 'custom']: raise iot_api_core.IotException(400, 'Invalid mode: ' + result['mode']) if result['mode'] == 'custom': result['title'] = val.get('title') else: if self.context.model_id: result['title'] = self.context.model_info['name'] else: result['title'] = {'en-us': 'My Product'} self.value = result return result
def read(self, from_values): val = from_values.get(self.name) result = {} if val is None: val = self.default result['mode'] = val.get('mode', 'page') if result['mode'] not in ['page', 'custom']: raise iot_api_core.IotException(400, 'Invalid mode: ' + result['mode']) if result['mode'] == 'custom': result['url'] = val.get('url') else: result['instanceId'] = val.get('instanceId') if result['instanceId']: instance = self.context.lumavate.get( '/iot/v1/widget-instances/' + str(result['instanceId'])) result['url'] = instance['url'] else: result['url'] = '' self.value = result return result
def token(self): if hasattr(g, 'lumavate_context'): return g.lumavate_context['token'] else: raise iot_api_core.IotException(401, 'Not Authorized')