def monitor(request): device_config = config.get_device_config() light_config = config.get_light_config() return render(request,'farm/farm.html',context={ 'device1_state':device_config.device1State, 'device2_state':device_config.device2State, 'device3_state':device_config.device3State, 'device4_state':device_config.device4State, 'light_state':light_config.isLightOn, 'light_color':light_config.lightColor, 'light_color_str':config.get_color_str(light_config.lightColor), 'light_level':light_config.lightLevel })
def monitor(request): if not checkHasPermissionModifyConfig(request.user): return forbidden(request) device_config = config.get_device_config() light_config = config.get_light_config() return render(request,'farm/farm.html',context={ 'device1_state':device_config.device1State, 'device2_state':device_config.device2State, 'device3_state':device_config.device3State, 'device4_state':device_config.device4State, 'light_state':light_config.isLightOn, 'light_color':light_config.lightColor, 'light_color_str':config.get_color_str(light_config.lightColor), 'light_level':light_config.lightLevel })
def mobile_manage(request): getUserList = authorization.get_user(request) if getUserList[0] == authorization.RESULT_SUCCESS: if (getUserList[2].is_staff and getUserList[2].is_active) or getUserList[2].is_superuser: device_config = config.get_device_config() light_config = config.get_light_config() return HttpResponse(json.dumps({ 'device1_state': device_config.device1State, 'device2_state': device_config.device2State, 'device3_state': device_config.device3State, 'device4_state': device_config.device4State, 'light_state': light_config.isLightOn, 'light_color': light_config.lightColor, 'light_color_str': config.get_color_str(light_config.lightColor), 'light_level': light_config.lightLevel },ensure_ascii=False)) else: return HttpResponse(JSON_PERMISSION_DENIED) elif getUserList[0] == authorization.RESULT_TOKEN_NOT_EXIST: return HttpResponse(JSON_LOGIN_REQUIRE) else: return HttpResponse(JSON_OPPERATION_FAIL)
def light(request): request_result = __checkUser(request) if request_result == HTTP_RESULT_SUCCESS: light_config = config.get_light_config() if request.method == 'POST': if config.KEY_IS_LIGHT_ON in request.POST: light_config.isLightOn = request.POST.get(config.KEY_IS_LIGHT_ON, config.STATE_OFF) print('环境光设置为', light_config.isLightOn) conn.sendCmd('08','0'+str(light_config.isLightOn)) state.light = light_config.isLightOn time.sleep(0.01) if config.KEY_LIGHT_COLOR in request.POST: light_config.lightColor = request.POST.get(config.KEY_LIGHT_COLOR, config.STATE_OFF) print('环境光颜色设置为', light_config.lightColor) conn.sendCmd('09','0'+str(light_config.lightColor)) state.light_color = light_config.lightColor time.sleep(0.01) if config.KEY_LIGHT_LEVEL in request.POST: light_config.lightLevel = request.POST.get(config.KEY_LIGHT_LEVEL, config.STATE_OFF) print('环境光亮度设置为', light_config.lightLevel) tempData = light_config.lightLevel if(int(tempData) > 9): tempData = 'a' conn.sendCmd('0a','0'+str(tempData)) state.light_level = light_config.lightLevel time.sleep(0.01) config.set_light_config_obj(light_config) time.sleep(0.3) conn.sendCmdReset() json_obj = { KEY_RESULT: HTTP_RESULT_SUCCESS, config.KEY_IS_LIGHT_ON: light_config.isLightOn, config.KEY_LIGHT_COLOR: light_config.lightColor, config.KEY_LIGHT_LEVEL: light_config.lightLevel, } return HttpResponse(json.dumps(json_obj)) else: return HttpResponse(DICT_RESULT_CODE.get(request_result, JSON_UNKNOWN_ERROR))
def light(request): request_result = __checkUser(request) if request_result == HTTP_RESULT_SUCCESS: light_config = config.get_light_config() if request.method == 'POST': if config.KEY_IS_LIGHT_ON in request.POST: light_config.isLightOn = request.POST.get(config.KEY_IS_LIGHT_ON, config.STATE_OFF) print('环境光设置为', light_config.isLightOn) if config.KEY_LIGHT_COLOR in request.POST: light_config.lightColor = request.POST.get(config.KEY_LIGHT_COLOR, config.STATE_OFF) print('环境光颜色设置为', light_config.lightColor) if config.KEY_LIGHT_LEVEL in request.POST: light_config.lightLevel = request.POST.get(config.KEY_LIGHT_LEVEL, config.STATE_OFF) print('环境光亮度设置为', light_config.lightLevel) config.set_light_config_obj(light_config) json_obj = { KEY_RESULT: HTTP_RESULT_SUCCESS, config.KEY_IS_LIGHT_ON: light_config.isLightOn, config.KEY_LIGHT_COLOR: light_config.lightColor, config.KEY_LIGHT_LEVEL: light_config.lightLevel, } return HttpResponse(json.dumps(json_obj)) else: return HttpResponse(DICT_RESULT_CODE.get(request_result, JSON_UNKNOWN_ERROR))