def get_skynet_info(self): token_model = AlarmSetting() token = token_model.get_pair('skynet_token') uuid_model = AlarmSetting() uuid = uuid_model.get_pair('skynet_uuid') if not uuid or not token: return False self.uuid = uuid.value self.token = token.value return {'uuid' : uuid.value, 'token' : token.value}
def get(): fields = [{'field': 'alarm_status', 'label' : 'Alarm Status', 'value' : 1}, {'field': 'alarm_minutes', 'label' : 'Alarm Minutes', 'value' : 0}, {'field': 'alarm_hours', 'label' : 'Alarm Hours', 'value' : 6}, {'field': 'snooze_minutes', 'label' : 'Snooze Minutes', 'value' : 10}, {'field': 'alarm_text', 'label' : 'Alarm Text', 'value' : 'ALARM!'}] settings = {} for field in fields: model = AlarmSetting() data = model.get_pair(field['field']) value = field['value'] if data: value = data.value settings[field['field']] = value return json.dumps(settings)
def save_skynet_info(self, new_uuid, new_token): token_model = AlarmSetting() token = token_model.get_pair('skynet_token') if not token: token = token_model.create(name='skynet_token', label='Skynet Token', value=new_token) else: token = token.update(value=new_token) uuid_model = AlarmSetting() uuid = uuid_model.get_pair('skynet_uuid') if not uuid: uuid = uuid_model.create(name='skynet_uuid', label='Skynet UUID', value=new_uuid) else: uuid = uuid.update(value=new_uuid) self.uuid = uuid.value self.token = token.value