def zone_device_listing(request, zone_dev): context = RequestContext(request) username = request.user zone_dev = zone_dev.encode('ascii', 'ignore') zone_info = zone_dev.split("_") zone_id = zone_info[0] device_type = zone_info[1] #Side navigation bar device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) #For the page if device_type == 'th': thermostats = [ob.data_as_json() for ob in Thermostat.objects.filter(zone_id=zone_id, thermostat_id__approval_status='APR', network_status='ONLINE')] if len(thermostats) != 0: zone_nickname = thermostats[0]['zone']['zone_nickname'] rtu = [ob.as_json() for ob in RTU.objects.filter(zone_id=zone_id, rtu_id__approval_status='APR', network_status='ONLINE')] if len(rtu) != 0: zone_nickname = rtu[0]['zone']['zone_nickname'] vav = [ob.as_json() for ob in VAV.objects.filter(zone_id=zone_id, vav_id__approval_status='APR', network_status='ONLINE')] if len(vav) != 0: zone_nickname = vav[0]['zone']['zone_nickname'] active_al = get_notifications() context.update({'active_al':active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) context.update(device_list_side_nav) return render_to_response( 'dashboard/thermostats.html', {'thermostats': thermostats, 'rtu': rtu, 'vav': vav, 'zone_id': zone_id, 'zone_nickname': zone_nickname, }, context) elif device_type == 'lt': lighting = [ob.data_as_json() for ob in Lighting.objects.filter(zone_id=zone_id, lighting_id__approval_status='APR', network_status='ONLINE')] zone_nickname = lighting[0]['zone']['zone_nickname'] return render_to_response( 'dashboard/lighting_loads.html', {'lighting_loads': lighting, 'zone_id': zone_id, 'zone_nickname': zone_nickname}, context) elif device_type == 'pl': plugloads = [ob.data_as_json() for ob in Plugload.objects.filter(zone_id=zone_id, plugload_id__approval_status='APR', network_status='ONLINE')] zone_nickname = plugloads[0]['zone']['zone_nickname'] context.update(device_list_side_nav) return render_to_response( 'dashboard/plugloads.html', {'plugloads': plugloads, 'zone_id': zone_id, 'zone_nickname': zone_nickname}, context)
def network_status(request): print 'Network status page load' context = RequestContext(request) if request.session.get('last_visit'): # The session has a value for the last visit last_visit_time = request.session.get('last_visit') visits = request.session.get('visits', 0) if (datetime.now() - datetime.strptime(last_visit_time[:-7], "%Y-%m-%d %H:%M:%S")).days > 0: request.session['visits'] = visits + 1 else: # The get returns None, and the session does not have a value for the last visit. request.session['last_visit'] = str(datetime.now()) request.session['visits'] = 1 active_al = get_notifications() context.update({'active_al': active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) if request.user.get_profile().group.name.lower() == 'admin': nw_status = [ob.network_status() for ob in NetworkStatus.objects.all()] return render_to_response( 'admin/network_status.html', {'nw_status': nw_status}, context) else: return HttpResponseRedirect('/home/')
def alerts(request): print 'inside alerts view method' context = RequestContext(request) device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) if request.user.get_profile().group.name.lower() == 'admin': usr = UserFullName.objects.filter(username=request.user)[0] _registered_alerts = [ob.as_json() for ob in ActiveAlert.objects.all()] _alerts = [ob.as_json() for ob in EventTrigger.objects.all()] _alert_pr = [ob.as_json() for ob in Priority.objects.all()] _n_type = [ob.as_json() for ob in NotificationChannel.objects.all()] active_al = get_notifications() bemoss_not = general_notifications() _temp_range = [ob.as_json() for ob in TempRangeValue.objects.all()] _temp_failure_time = [ob.as_json() for ob in TempFailureTime.objects.all()] context.update({'b_al': bemoss_not}) return render_to_response( 'admin/alarms.html', {'registered_alerts': _registered_alerts, 'alerts': _alerts, 'priority': _alert_pr, 'n_type': _n_type, 'user_full_name': usr, 'temp_range': _temp_range, 'temp_failure_time': _temp_failure_time, 'active_al': active_al}, context) else: return HttpResponseRedirect('/home/')
def discover_devices(request): if request.user.get_profile().group.name.lower() == 'admin': context = RequestContext(request) discovery_status = Miscellaneous.objects.get(key='auto_discovery') print discovery_status.value hvac = SupportedDevices.objects.filter(device_type__in=["thermostat", "vav", "rtu"]) lt_loads = SupportedDevices.objects.filter(device_type="lighting") plugloads = SupportedDevices.objects.filter(device_type="plugload") print lt_loads print hvac print plugloads device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) active_al = get_notifications() context.update({'active_al': active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) return render_to_response('dashboard/manual_discovery.html', {'hvac': hvac, 'lt_loads': lt_loads, 'plugloads': plugloads, 'discovery_status': discovery_status}, context ) else: return HttpResponseRedirect('/home/')
def zone_device_listing(request, zone_dev): context = RequestContext(request) username = request.user zone_dev = zone_dev.encode('ascii', 'ignore') zone_info = zone_dev.split("_") zone_id = zone_info[0] device_type = zone_info[1] #Side navigation bar device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) #For the page if device_type == 'th': thermostats = [ob.data_as_json() for ob in Thermostat.objects.filter(zone_id=zone_id, thermostat_id__approval_status='APR', network_status='ONLINE')] if len(thermostats) != 0: zone_nickname = thermostats[0]['zone']['zone_nickname'] rtu = [ob.as_json() for ob in RTU.objects.filter(zone_id=zone_id, rtu_id__approval_status='APR', network_status='ONLINE')] if len(rtu) != 0: zone_nickname = rtu[0]['zone']['zone_nickname'] vav = [ob.as_json() for ob in VAV.objects.filter(zone_id=zone_id, vav_id__approval_status='APR', network_status='ONLINE')] if len(vav) != 0: zone_nickname = vav[0]['zone']['zone_nickname'] active_al = get_notifications() context.update({'active_al':active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) context.update(device_list_side_nav) return render_to_response( 'dashboard/thermostats.html', {'thermostats': thermostats, 'rtu': rtu, 'vav': vav, 'zone_id': zone_id, 'zone_nickname': zone_nickname, }, context) elif device_type == 'lt': lighting = [ob.data_as_json() for ob in Lighting.objects.filter(zone_id=zone_id, lighting_id__approval_status='APR', network_status='ONLINE')] zone_nickname = lighting[0]['zone']['zone_nickname'] return render_to_response( 'dashboard/lighting_loads.html', {'lighting_loads': lighting, 'zone_id': zone_id, 'zone_nickname': zone_nickname}, context) elif device_type == 'pl': plugloads = [ob.data_as_json() for ob in Plugload.objects.filter(zone_id=zone_id, plugload_id__approval_status='APR', network_status='ONLINE')] zone_nickname = plugloads[0]['zone']['zone_nickname'] context.update(device_list_side_nav) return render_to_response( 'dashboard/plugloads.html', {'plugloads': plugloads, 'zone_id': zone_id, 'zone_nickname': zone_nickname}, context)
def alerts(request): print 'inside alerts view method' context = RequestContext(request) device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) if request.user.get_profile().group.name.lower() == 'admin': usr = UserFullName.objects.filter(username=request.user)[0] _registered_alerts = [ob.as_json() for ob in ActiveAlert.objects.all()] _alerts = [ob.as_json() for ob in EventTrigger.objects.all()] _alert_pr = [ob.as_json() for ob in Priority.objects.all()] _n_type = [ob.as_json() for ob in NotificationChannel.objects.all()] active_al = get_notifications() bemoss_not = general_notifications() _temp_range = [ob.as_json() for ob in TempRangeValue.objects.all()] _temp_failure_time = [ ob.as_json() for ob in TempFailureTime.objects.all() ] context.update({'b_al': bemoss_not}) return render_to_response( 'admin/alarms.html', { 'registered_alerts': _registered_alerts, 'alerts': _alerts, 'priority': _alert_pr, 'n_type': _n_type, 'user_full_name': usr, 'temp_range': _temp_range, 'temp_failure_time': _temp_failure_time, 'active_al': active_al }, context) else: return HttpResponseRedirect('/home/')
def notifications(request): print "Notifications page load" context = RequestContext(request) device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) active_al = get_notifications() context.update({"active_al": active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) if request.user.get_profile().group.name.lower() == 'admin': usr = UserFullName.objects.filter(username=request.user)[0] _registered_alerts = [ob.as_json() for ob in ActiveAlert.objects.all()] _alerts = [ob.as_json() for ob in EventTrigger.objects.all()] _alert_pr = [ob.as_json() for ob in Priority.objects.all()] _n_type = [ob.as_json() for ob in NotificationChannel.objects.all()] active_al = get_notifications() # print context return render_to_response( 'admin/notifications.html', {'registered_alerts': _registered_alerts, 'alerts': _alerts, 'priority': _alert_pr, 'n_type': _n_type, 'user_full_name': usr, 'active_al': active_al}, context) else: return HttpResponseRedirect('/home/')
def notifications(request): print "Notifications page load" context = RequestContext(request) device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) active_al = get_notifications() context.update({"active_al": active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) if request.user.get_profile().group.name.lower() == 'admin': usr = UserFullName.objects.filter(username=request.user)[0] _registered_alerts = [ob.as_json() for ob in ActiveAlert.objects.all()] _alerts = [ob.as_json() for ob in EventTrigger.objects.all()] _alert_pr = [ob.as_json() for ob in Priority.objects.all()] _n_type = [ob.as_json() for ob in NotificationChannel.objects.all()] active_al = get_notifications() # print context return render_to_response( 'admin/notifications.html', { 'registered_alerts': _registered_alerts, 'alerts': _alerts, 'priority': _alert_pr, 'n_type': _n_type, 'user_full_name': usr, 'active_al': active_al }, context) else: return HttpResponseRedirect('/home/')
def bemoss_home(request): context = RequestContext(request) username = request.user device_list_side_nav = get_device_list_side_navigation() device_count = {"devices": {}} all_zones = Building_Zone.objects.all() for zone in all_zones: th_count = Thermostat.objects.filter( network_status='ONLINE', zone_id=zone.zone_id, thermostat_id__approval_status='APR').count() vav_count = VAV.objects.filter(network_status='ONLINE', zone_id=zone.zone_id, vav_id__approval_status='APR').count() rtu_count = RTU.objects.filter(network_status='ONLINE', zone_id=zone.zone_id, rtu_id__approval_status='APR').count() t_count = th_count + vav_count + rtu_count pl_count = Plugload.objects.filter( network_status='ONLINE', zone_id=zone.zone_id, plugload_id__approval_status='APR').count() lt_count = Lighting.objects.filter( network_status='ONLINE', zone_id=zone.zone_id, lighting_id__approval_status='APR').count() device_count['devices'][zone.zone_id] = { 'th': 0, 'pl': 0, 'lt': 0, } device_count['devices'][zone.zone_id]['th'] = t_count device_count['devices'][zone.zone_id]['pl'] = pl_count device_count['devices'][zone.zone_id]['lt'] = lt_count zones_p = [ ob.data_dashboard() for ob in Building_Zone.objects.all().order_by('zone_nickname') ] for zone in zones_p: z_id = zone['id'] zone['t_count'] = device_count['devices'][z_id]['th'] zone['pl_count'] = device_count['devices'][z_id]['pl'] zone['lt_count'] = device_count['devices'][z_id]['lt'] active_al = get_notifications() context.update({'active_al': active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) context.update(device_list_side_nav) return render_to_response('dashboard/dashboard.html', {'zones_p': zones_p}, context)
def update_context(context): device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) active_al = get_notifications() context.update({'active_al': active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) return context
def lighting(request, mac): print 'inside lighting view method' context = RequestContext(request) username = request.session.get('user') print username if request.session.get('last_visit'): # The session has a value for the last visit last_visit_time = request.session.get('last_visit') visits = request.session.get('visits', 0) if (datetime.now() - datetime.strptime(last_visit_time[:-7], "%Y-%m-%d %H:%M:%S")).days > 0: request.session['visits'] = visits + 1 else: # The get returns None, and the session does not have a value for the last visit. request.session['last_visit'] = str(datetime.now()) request.session['visits'] = 1 mac = mac.encode('ascii', 'ignore') device_metadata = [ ob.device_control_page_info() for ob in DeviceMetadata.objects.filter(mac_address=mac) ] print device_metadata device_id = device_metadata[0]['device_id'] controller_type = device_metadata[0]['device_model_id'] controller_type = controller_type.device_model_id device_status = [ ob.data_as_json() for ob in Lighting.objects.filter(lighting_id=device_id) ] device_zone = device_status[0]['zone']['id'] device_nickname = device_status[0]['nickname'] zone_nickname = device_status[0]['zone']['zone_nickname'] _data = _helper.get_page_load_data(device_id, 'lighting', controller_type) device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) active_al = get_notifications() context.update({'active_al': active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) return render_to_response( 'lighting/lighting.html', { 'type': controller_type, 'device_data': _data, 'device_id': device_id, 'device_zone': device_zone, 'device_type': controller_type, 'mac_address': mac, 'zone_nickname': zone_nickname, 'device_nickname': device_nickname }, context)
def rtu_view(request, mac): print 'RTU pageload' context = RequestContext(request) mac = mac.encode('ascii', 'ignore') if request.session.get('last_visit'): # The session has a value for the last visit last_visit_time = request.session.get('last_visit') visits = request.session.get('visits', 0) if (datetime.now() - datetime.strptime(last_visit_time[:-7], "%Y-%m-%d %H:%M:%S")).days > 0: request.session['visits'] = visits + 1 else: # The get returns None, and the session does not have a value for the last visit. request.session['last_visit'] = str(datetime.now()) request.session['visits'] = 1 device_metadata = [ob.device_control_page_info() for ob in DeviceMetadata.objects.filter(mac_address=mac)] print device_metadata device_id = device_metadata[0]['device_id'] device_type = device_metadata[0]['device_type'] device_type_id = device_metadata[0]['device_model_id'] device_type_id = device_type_id.device_model_id device_status = [ob.as_json() for ob in RTU.objects.filter(rtu_id=device_id)] device_zone = device_status[0]['zone']['id'] device_nickname = device_status[0]['nickname'] zone_nickname = device_status[0]['zone']['zone_nickname'] #Using page_load.json vals = _helper.get_page_load_data(device_id, device_type, device_type_id) if vals['cooling_mode'] == 'NONE': vals['cooling_mode'] = "None" elif vals['cooling_mode'] == 'STG1': vals['cooling_mode'] = "Stage 1 Cooling" elif vals['cooling_mode'] == 'STG2': vals['cooling_mode'] = "Stage 2 Cooling" elif vals['cooling_mode'] == 'STG3': vals['cooling_mode'] = "Stage 3 Cooling" elif vals['cooling_mode'] == 'STG4': vals['cooling_mode'] = "Stage 4 Cooling" device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) active_al = get_notifications() context.update({'active_al':active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) return render_to_response( 'thermostat/rtu.html', {'device_id': device_id, 'device_zone': device_zone, 'zone_nickname': zone_nickname, 'mac_address': mac, 'device_nickname': device_nickname, 'device_status': vals, 'mac': mac}, context)
def vav_view(request, mac): print 'RTU pageload' context = RequestContext(request) mac = mac.encode('ascii', 'ignore') if request.session.get('last_visit'): # The session has a value for the last visit last_visit_time = request.session.get('last_visit') visits = request.session.get('visits', 0) if (datetime.now() - datetime.strptime(last_visit_time[:-7], "%Y-%m-%d %H:%M:%S")).days > 0: request.session['visits'] = visits + 1 else: # The get returns None, and the session does not have a value for the last visit. request.session['last_visit'] = str(datetime.now()) request.session['visits'] = 1 device_metadata = [ ob.device_control_page_info() for ob in DeviceMetadata.objects.filter(mac_address=mac) ] print device_metadata device_id = device_metadata[0]['device_id'] device_type = device_metadata[0]['device_type'] device_type_id = device_metadata[0]['device_model_id'] device_type_id = device_type_id.device_model_id device_status = [ ob.as_json() for ob in VAV.objects.filter(vav_id=device_id) ] device_zone = device_status[0]['zone']['id'] device_nickname = device_status[0]['nickname'] zone_nickname = device_status[0]['zone']['zone_nickname'] #Using page_load.json vals = _helper.get_page_load_data(device_id, device_type, device_type_id) device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) active_al = get_notifications() context.update({'active_al': active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) return render_to_response( 'thermostat/vav.html', { 'device_id': device_id, 'device_zone': device_zone, 'zone_nickname': zone_nickname, 'mac_address': mac, 'device_nickname': device_nickname, 'device_status': vals, 'mac': mac }, context)
def bemoss_home(request): context = RequestContext(request) username = request.user device_list_side_nav = get_device_list_side_navigation() device_count ={ "devices": { } } all_zones = Building_Zone.objects.all() for zone in all_zones: th_count = Thermostat.objects.filter(network_status='ONLINE', zone_id=zone.zone_id, thermostat_id__approval_status='APR').count() vav_count = VAV.objects.filter(network_status='ONLINE', zone_id=zone.zone_id, vav_id__approval_status='APR').count() rtu_count = RTU.objects.filter(network_status='ONLINE', zone_id=zone.zone_id, rtu_id__approval_status='APR').count() t_count = th_count + vav_count + rtu_count pl_count = Plugload.objects.filter(network_status='ONLINE', zone_id=zone.zone_id, plugload_id__approval_status='APR').count() lt_count = Lighting.objects.filter(network_status='ONLINE', zone_id=zone.zone_id, lighting_id__approval_status='APR').count() device_count['devices'][zone.zone_id] = {'th': 0, 'pl': 0, 'lt': 0, } device_count['devices'][zone.zone_id]['th'] = t_count device_count['devices'][zone.zone_id]['pl'] = pl_count device_count['devices'][zone.zone_id]['lt'] = lt_count zones_p = [ob.data_dashboard() for ob in Building_Zone.objects.all().order_by('zone_nickname')] for zone in zones_p: z_id = zone['id'] zone['t_count'] = device_count['devices'][z_id]['th'] zone['pl_count'] = device_count['devices'][z_id]['pl'] zone['lt_count'] = device_count['devices'][z_id]['lt'] active_al = get_notifications() context.update({'active_al':active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) context.update(device_list_side_nav) return render_to_response( 'dashboard/dashboard.html', {'zones_p': zones_p}, context)
def smartplug(request, mac): print 'inside plugload view method' context = RequestContext(request) username = request.session.get('user') print username if request.session.get('last_visit'): # The session has a value for the last visit last_visit_time = request.session.get('last_visit') visits = request.session.get('visits', 0) if (datetime.now() - datetime.strptime(last_visit_time[:-7], "%Y-%m-%d %H:%M:%S")).days > 0: request.session['visits'] = visits + 1 else: # The get returns None, and the session does not have a value for the last visit. request.session['last_visit'] = str(datetime.now()) request.session['visits'] = 1 print type(mac) mac = mac.encode('ascii', 'ignore') print type(mac) device_metadata = [ob.device_control_page_info() for ob in DeviceMetadata.objects.filter(mac_address=mac)] print device_metadata device_id = device_metadata[0]['device_id'] device_type_id = device_metadata[0]['device_model_id'] device_type_id = device_type_id.device_model_id device_status = [ob.data_as_json() for ob in Plugload.objects.filter(plugload_id=device_id)] device_zone = device_status[0]['zone']['id'] device_nickname = device_status[0]['nickname'] zone_nickname = device_status[0]['zone']['zone_nickname'] _data = _helper.get_page_load_data(device_id, 'plugload', device_type_id) device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) active_al = get_notifications() context.update({'active_al':active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) return render_to_response( 'plugload/plugload.html', {'device_data': _data, 'device_id': device_id, 'device_zone': device_zone, 'zone_nickname': zone_nickname, 'mac_address': mac, 'device_nickname': device_nickname, 'device_type_id': device_type_id}, context)
def discover_nodes(request): context = RequestContext(request) if request.user.get_profile().group.name.lower() == 'admin': device_list_side_nav = get_device_list_side_navigation() bemoss_lite = [ob.data_dashboard() for ob in NetworkStatus.objects.filter(node_status='ONLINE')] active_al = get_notifications() context.update({'active_al':active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) context.update(device_list_side_nav) return render_to_response( 'dashboard/node_discovery.html', {'lites': bemoss_lite}, context) else: return HttpResponseRedirect('/home/')
def discover_nodes(request): context = RequestContext(request) if request.user.get_profile().group.name.lower() == 'admin': device_list_side_nav = get_device_list_side_navigation() bemoss_lite = [ob.data_dashboard() for ob in NetworkStatus.objects.filter(node_status='ONLINE')] active_al = get_notifications() context.update({'active_al':active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) context.update(device_list_side_nav) return render_to_response( 'dashboard/node_discovery.html', {'lites': bemoss_lite}, context) else: return HttpResponseRedirect('/home/')
def user_manager(request): context = RequestContext(request) zones = [ob.as_json() for ob in Building_Zone.objects.all()] active_al = get_notifications() context.update({'active_al':active_al}) device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) if request.user.get_profile().group.name.lower() == 'admin': _users = User.objects.all() groups = Group.objects.all() print _users return render_to_response('admin/user_manager.html', {"users": _users, 'zones': zones, 'groups': groups}, context) else: return HttpResponseRedirect('/home/')
def discover(request): print "Discovering devices" context = RequestContext(request) username = request.user device_list_side_nav = get_device_list_side_navigation() print device_list_side_nav # Check Philips Hue Username Exists or not: # Set default value as no: hue_username_exists = 'no' DIR = os.path.dirname(__file__) DIR = DIR.replace('/bemoss_web_ui/apps/dashboard', '/bemoss_os/') LAUNCHFILES_DIR = os.path.join(DIR, 'Agents/LaunchFiles/') for idx in os.listdir(LAUNCHFILES_DIR): if '2HUE' in idx and '.json~' not in idx: _launch_file = os.path.join(LAUNCHFILES_DIR, idx) f = open(_launch_file, 'r') data = json.load(f) if 'username' in data.keys(): hue_username_exists = 'yes' if request.user.get_profile().group.name.lower() == 'admin': # Get data for display on discovery dashboard data_dashboard = get_device_list_dashboard() #Update side navigation context context.update(device_list_side_nav) #Get alerts and notifications list active_al = get_notifications() context.update({'active_al':active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) context.update({'username_exists': hue_username_exists}) return render_to_response( 'dashboard/discovery.html', data_dashboard, context) else: return HttpResponseRedirect('/home/')
def discover(request): print "Discovering devices" context = RequestContext(request) username = request.user device_list_side_nav = get_device_list_side_navigation() print device_list_side_nav # Check Philips Hue Username Exists or not: # Set default value as no: hue_username_exists = list() DIR = os.path.dirname(__file__) DIR = DIR.replace('/bemoss_web_ui/apps/dashboard', '/bemoss_os/') LAUNCHFILES_DIR = os.path.join(DIR, 'Agents/LaunchFiles/') for idx in os.listdir(LAUNCHFILES_DIR): if '2HUE' in idx and '.json~' not in idx: _launch_file = os.path.join(LAUNCHFILES_DIR, idx) f = open(_launch_file, 'r') data = json.load(f) if 'username' in data.keys(): hue_username_exists.append(data['macaddress']) if request.user.get_profile().group.name.lower() == 'admin': # Get data for display on discovery dashboard data_dashboard = get_device_list_dashboard() #Update side navigation context context.update(device_list_side_nav) #Get alerts and notifications list active_al = get_notifications() context.update({'active_al':active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) context.update({'username_exists': hue_username_exists}) return render_to_response( 'dashboard/discovery.html', data_dashboard, context) else: return HttpResponseRedirect('/home/')
def thermostat(request, mac): print 'Thermostat pageload' context = RequestContext(request) mac = mac.encode('ascii', 'ignore') device_metadata = [ob.device_control_page_info() for ob in DeviceMetadata.objects.filter(mac_address=mac)] print device_metadata device_type = device_metadata[0]['device_type'] device_id = device_metadata[0]['device_id'] device_type_id = device_metadata[0]['device_model_id'] device_type_id = device_type_id.device_model_id print device_type_id device_status = [ob.data_as_json() for ob in Thermostat.objects.filter(thermostat_id=device_id)] device_zone = device_status[0]['zone']['id'] device_nickname = device_status[0]['nickname'] zone_nickname = device_status[0]['zone']['zone_nickname'] override = device_status[0]['override'] hold = device_status[0]['hold'] #Using page_load.json vals = _helper.get_page_load_data(device_id, device_type, device_type_id) print vals weather_info = get_weather_info() device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) active_al = get_notifications() context.update({'active_al':active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) return render_to_response( 'thermostat/thermostat.html', {'device_id': device_id, 'device_zone': device_zone, 'device_type_id': device_type_id, 'zone_nickname': zone_nickname, 'mac_address': mac, 'device_nickname': device_nickname, 'device_data': vals, 'location': weather_info[0], 'temp_f': weather_info[1], 'humidity': weather_info[2], 'precip': weather_info[3], 'winds': weather_info[4], 'override': override, 'hold':hold, 'weather_icon': weather_info[6], 'weather': weather_info[5], 'mac': mac}, context)
def user_manager(request): context = RequestContext(request) zones = [ob.as_json() for ob in Building_Zone.objects.all()] active_al = get_notifications() context.update({'active_al': active_al}) device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) if request.user.get_profile().group.name.lower() == 'admin': _users = User.objects.all() groups = Group.objects.all() print _users return render_to_response('admin/user_manager.html', { "users": _users, 'zones': zones, 'groups': groups }, context) else: return HttpResponseRedirect('/home/')
def bemoss_settings(request): print 'BEMOSS Settings page load' context = RequestContext(request) if request.session.get('last_visit'): # The session has a value for the last visit last_visit_time = request.session.get('last_visit') visits = request.session.get('visits', 0) if (datetime.now() - datetime.strptime(last_visit_time[:-7], "%Y-%m-%d %H:%M:%S")).days > 0: request.session['visits'] = visits + 1 else: # The get returns None, and the session does not have a value for the last visit. request.session['last_visit'] = str(datetime.now()) request.session['visits'] = 1 holidays = [ob.as_json() for ob in Holiday.objects.all()] print holidays json_file = open(os.path.join(settings_tornado.PROJECT_DIR, 'resources/metadata/bemoss_metadata.json'), "r+") _json_data = json.load(json_file) b_location = _json_data['building_location_zipcode'] json_file.close() device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) active_al = get_notifications() context.update({'active_al':active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) if request.user.get_profile().group.name.lower() == 'admin': return render_to_response( 'admin/bemoss_settings.html', {'holidays': holidays, 'b_location': b_location}, context) else: return HttpResponseRedirect('/home/')
def device_status(request): print 'Device status page load' context = RequestContext(request) if request.session.get('last_visit'): # The session has a value for the last visit last_visit_time = request.session.get('last_visit') visits = request.session.get('visits', 0) if (datetime.now() - datetime.strptime(last_visit_time[:-7], "%Y-%m-%d %H:%M:%S")).days > 0: request.session['visits'] = visits + 1 else: # The get returns None, and the session does not have a value for the last visit. request.session['last_visit'] = str(datetime.now()) request.session['visits'] = 1 if request.user.get_profile().group.name.lower() == 'admin': thermostats = [ob.device_status() for ob in Thermostat.objects.filter(thermostat_id__approval_status='APR')] print thermostats vavs = [ob.device_status() for ob in VAV.objects.filter(vav_id__approval_status='APR')] rtus = [ob.device_status() for ob in RTU.objects.filter(rtu_id__approval_status='APR')] plugloads = [ob.device_status() for ob in Plugload.objects.filter(plugload_id__approval_status='APR')] print plugloads lighting = [ob.device_status() for ob in Lighting.objects.filter(lighting_id__approval_status='APR')] device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) active_al = get_notifications() context.update({'active_al':active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) return render_to_response( 'admin/device_status.html', {'thermostats': thermostats, 'vavs': vavs, 'rtus': rtus, 'plugloads': plugloads, 'lighting': lighting}, context) else: return HttpResponseRedirect('/home/')
def lighting_schedule(request, mac): print 'Inside Set Schedule method in Schedule app' context = RequestContext(request) username = request.user if request.user.get_profile().group.name.lower() == 'admin' or \ request.user.get_profile().group.name.lower() == 'zone manager': print username print type(mac) mac = mac.encode('ascii', 'ignore') print type(mac) device_metadata = [ ob.device_control_page_info() for ob in DeviceMetadata.objects.filter(mac_address=mac) ] print device_metadata device_id = device_metadata[0]['device_id'] device_type_id = device_metadata[0]['device_model_id'] device_type_id = device_type_id.device_model_id device_status = [ ob.data_as_json() for ob in Lighting.objects.filter(lighting_id=device_id) ] device_zone = device_status[0]['zone']['id'] device_nickname = device_status[0]['nickname'] zone_nickname = device_status[0]['zone']['zone_nickname'] # Send message to OS to launch application app_launcher_topic = '/ui/appLauncher/lighting_scheduler/' + device_id + '/launch' token = {"auth_token": "bemoss"} zmq_pub.requestAgent(app_launcher_topic, json.dumps(token), "application/json", "UI") _data = {} active_schedule = [] disabled_range = __.DISABLED_VALUES_LIGHTING #Check if schedule file for this device exists _file_name = os.path.join( settings_tornado.PROJECT_DIR, 'resources/scheduler_data/lighting/' + device_id + '_schedule.json') if os.path.isfile(_file_name): json_file = open(_file_name, 'r+') _json_data = json.load(json_file) if device_id in _json_data['lighting']: print 'device id present' _data = _json_data['lighting'][device_id]['schedulers'] active_schedule = _json_data['lighting'][device_id]['active'] active_schedule = [str(x) for x in active_schedule] disabled_range = get_disabled_date_ranges( _data, __.DISABLED_VALUES_LIGHTING) _data = json.dumps(_data) _data = json.loads(_data, object_hook=_decode_dict) json_file.close() else: #json_file = open(_file_name, 'w+') if device_type_id == '2SDB' or device_type_id == '2DB' or device_type_id == '2WSL': _json_data = { "lighting": { device_id: { "active": ['everyday', 'holiday'], "inactive": [], "schedulers": __.LIGHTING_DEFAULT_SCHEDULE_2DB_2SDB } } } elif device_type_id == '2HUE': _json_data = { "lighting": { device_id: { "active": ['everyday', 'holiday'], "inactive": [], "schedulers": __.LIGHTING_DEFAULT_SCHEDULE_2HUE } } } with open(_file_name, 'w') as _new_file: json.dump(_json_data, _new_file, sort_keys=True, indent=4, ensure_ascii=False) _new_file.close() if type(_json_data) is dict: _data = _json_data['lighting'][device_id]['schedulers'] else: _json_data = json.loads(_json_data) _data = _json_data['lighting'][device_id]['schedulers'] active_schedule = ['everyday', 'holiday'] disabled_range = get_disabled_date_ranges( _data, __.DISABLED_VALUES_LIGHTING) device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) active_al = get_notifications() context.update({'active_al': active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) return render_to_response( 'schedule/lt_sch.html', { 'device_id': device_id, 'device_zone': device_zone, 'zone_nickname': zone_nickname, 'mac_address': mac, 'device_nickname': device_nickname, 'schedule': _data, 'disabled_ranges': disabled_range, 'active_schedule': active_schedule, 'type': device_type_id }, context) else: return HttpResponseRedirect('/home/')
precip = parsed_json['current_observation']['precip_1hr_in'] winds = parsed_json['current_observation']['wind_mph'] icon = str(parsed_json['current_observation']['icon']) weather = parsed_json['current_observation']['weather'] except Exception: location = 'Arlington, VA (Zipcode Error. Update settings/Contact Admin.)' temp_f = '77' humidity = '10%' precip = '0.0' winds = '1.0' icon = 'mostlysunny' weather = 'Sunny' weather_icon = config_helper.get_weather_icon(icon) print "icon "+weather_icon device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) active_al = get_notifications() context.update({'active_al':active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) return render_to_response( 'thermostat/thermostat.html', {'device_id': device_id, 'device_zone': device_zone, 'device_type_id': device_type_id, 'zone_nickname': zone_nickname, 'mac_address': mac, 'device_nickname': device_nickname, 'device_data': vals, 'location': location, 'temp_f': temp_f, 'humidity': humidity, 'precip': precip, 'winds': winds, 'override': override, 'hold':hold, 'weather_icon': weather_icon, 'weather': weather, 'mac': mac}, context) def get_zip_code():
def lighting_schedule(request, mac): print 'Inside Set Schedule method in Schedule app' context = RequestContext(request) username = request.user if request.user.get_profile().group.name.lower() == 'admin' or \ request.user.get_profile().group.name.lower() == 'zone manager': print username print type(mac) mac = mac.encode('ascii', 'ignore') print type(mac) device_metadata = [ob.device_control_page_info() for ob in DeviceMetadata.objects.filter(mac_address=mac)] print device_metadata device_id = device_metadata[0]['device_id'] device_type_id = device_metadata[0]['device_model_id'] device_type_id = device_type_id.device_model_id device_status = [ob.data_as_json() for ob in Lighting.objects.filter(lighting_id=device_id)] device_zone = device_status[0]['zone']['id'] device_nickname = device_status[0]['nickname'] zone_nickname = device_status[0]['zone']['zone_nickname'] # Send message to OS to launch application app_launcher_topic = '/ui/appLauncher/lighting_scheduler/' + device_id + '/launch' token = {"auth_token": "bemoss"} zmq_pub.requestAgent(app_launcher_topic, json.dumps(token), "application/json", "UI") _data = {} active_schedule = [] disabled_range = __.DISABLED_VALUES_LIGHTING #Check if schedule file for this device exists _file_name = os.path.join(settings_tornado.PROJECT_DIR, 'resources/scheduler_data/lighting/' + device_id + '_schedule.json') if os.path.isfile(_file_name): json_file = open(_file_name, 'r+') _json_data = json.load(json_file) if device_id in _json_data['lighting']: print 'device id present' _data = _json_data['lighting'][device_id]['schedulers'] active_schedule = _json_data['lighting'][device_id]['active'] active_schedule = [str(x) for x in active_schedule] disabled_range = get_disabled_date_ranges(_data, __.DISABLED_VALUES_LIGHTING) _data = json.dumps(_data) _data = json.loads(_data, object_hook=_decode_dict) json_file.close() else: #json_file = open(_file_name, 'w+') if device_type_id == '2SDB' or device_type_id == '2DB' or device_type_id == '2WSL': _json_data = {"lighting": { device_id: { "active": ['everyday', 'holiday'], "inactive": [], "schedulers": __.LIGHTING_DEFAULT_SCHEDULE_2DB_2SDB }}} elif device_type_id == '2HUE': _json_data = {"lighting": { device_id: { "active": ['everyday', 'holiday'], "inactive": [], "schedulers": __.LIGHTING_DEFAULT_SCHEDULE_2HUE }}} with open(_file_name, 'w') as _new_file: json.dump(_json_data, _new_file, sort_keys=True, indent=4, ensure_ascii=False) _new_file.close() if type(_json_data) is dict: _data = _json_data['lighting'][device_id]['schedulers'] else: _json_data = json.loads(_json_data) _data = _json_data['lighting'][device_id]['schedulers'] active_schedule = ['everyday', 'holiday'] disabled_range = get_disabled_date_ranges(_data, __.DISABLED_VALUES_LIGHTING) device_list_side_nav = get_device_list_side_navigation() context.update(device_list_side_nav) active_al = get_notifications() context.update({'active_al':active_al}) bemoss_not = general_notifications() context.update({'b_al': bemoss_not}) return render_to_response( 'schedule/lt_sch.html', {'device_id': device_id, 'device_zone': device_zone, 'zone_nickname': zone_nickname, 'mac_address': mac, 'device_nickname': device_nickname, 'schedule': _data, 'disabled_ranges': disabled_range, 'active_schedule': active_schedule, 'type': device_type_id}, context) else: return HttpResponseRedirect('/home/')