Example #1
0
def user_manager(request):
    context = RequestContext(request)
    zones = [ob.as_json() for ob in Building_Zone.objects.all()]
    thermostats_sn = [ob.data_side_nav() for ob in Thermostat.objects.filter(network_status='ONLINE', thermostat_id__bemoss=True)]
    vav_sn = [ob.data_side_nav() for ob in VAV.objects.filter(network_status='ONLINE', vav_id__bemoss=True)]
    rtu_sn = [ob.data_side_nav() for ob in RTU.objects.filter(network_status='ONLINE', rtu_id__bemoss=True)]
    lighting_sn = [ob.data_side_nav() for ob in Lighting.objects.filter(network_status='ONLINE', lighting_id__bemoss=True)]
    plugload_sn = [ob.data_side_nav() for ob in Plugload.objects.filter(network_status='ONLINE', plugload_id__bemoss=True)]
    occ_sensors_sn = [ob.data_side_nav() for ob in OccupancySensor.objects.filter(network_status='ONLINE', occupancy_sensor_id__bemoss=True)]
    lt_sensors_sn = [ob.data_side_nav() for ob in AmbientLightSensor.objects.filter(network_status='ONLINE', ambient_light_sensor_id__bemoss=True)]
    mtn_sensors_sn = [ob.data_side_nav() for ob in MotionSensor.objects.filter(network_status='ONLINE', motion_sensor_id__bemoss=True)]
    powermeters_sn = [ob.data_side_nav() for ob in PowerMeter.objects.filter(network_status='ONLINE', power_meter_id__bemoss=True)]
    active_al = get_notifications()
    context.update({'active_al':active_al})
    context.update({
        'zones': zones, 'thermostat_sn': thermostats_sn,
         'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn, 'occ_sensors_sn': occ_sensors_sn,
         'lt_sensors_sn': lt_sensors_sn, 'mtn_sensors_sn': mtn_sensors_sn,  'powermeters_sn': powermeters_sn,
         'vav_sn': vav_sn, 'rtu_sn': rtu_sn
    })

    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, 'thermostat_sn': thermostats_sn,
             'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn, 'occ_sensors_sn': occ_sensors_sn,
             'lt_sensors_sn': lt_sensors_sn, 'mtn_sensors_sn': mtn_sensors_sn,  'powermeters_sn': powermeters_sn,
             'vav_sn': vav_sn, 'rtu_sn': rtu_sn, 'groups': groups}, context)
    else:
        return HttpResponseRedirect('/home/')
Example #2
0
def discover(request):
    #print 'inside dashboard - device discovery page method'
    context = RequestContext(request)

    username = request.user
    #print username

    zones = [ob.as_json() for ob in Building_Zone.objects.all()]
    thermostats_sn = [ob.data_side_nav() for ob in Thermostat.objects.filter(network_status='ONLINE',
                                                                             thermostat_id__bemoss=True)]
    lighting_sn = [ob.data_side_nav() for ob in Lighting.objects.filter(network_status='ONLINE',
                                                                        lighting_id__bemoss=True)]
    plugload_sn = [ob.data_side_nav() for ob in Plugload.objects.filter(network_status='ONLINE',
                                                                        plugload_id__bemoss=True)]

    if request.user.get_profile().group.name.lower() == 'admin':
        thermostats = [ob.data_dashboard() for ob in Thermostat.objects.filter(network_status='ONLINE', thermostat_id__bemoss=True)]
        plugloads = [ob.data_dashboard() for ob in Plugload.objects.filter(network_status='ONLINE', plugload_id__bemoss=True)]
        lighting_loads = [ob.data_dashboard() for ob in Lighting.objects.filter(network_status='ONLINE', lighting_id__bemoss=True)]
        context.update({
            'zones': zones, 'thermostat_sn': thermostats_sn,
             'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn
        })
        active_al = get_notifications()
        context.update({'active_al':active_al})
        return render_to_response(
            'dashboard/discovery.html',
            {'thermostats': thermostats, 'plugloads':plugloads, 'lighting_loads':lighting_loads}, context)
    else:
        return HttpResponseRedirect('/home/')
Example #3
0
def network_status(request):
    print 'Network status page load'
    context = RequestContext(request)
    #username = request.session.get('user')
    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

    zones = [ob.as_json() for ob in Building_Zone.objects.all()]
    thermostats_sn = [
        ob.data_side_nav()
        for ob in Thermostat.objects.filter(network_status='ONLINE',
                                            thermostat_id__bemoss=True)
    ]
    lighting_sn = [
        ob.data_side_nav()
        for ob in Lighting.objects.filter(network_status='ONLINE',
                                          lighting_id__bemoss=True)
    ]
    plugload_sn = [
        ob.data_side_nav()
        for ob in Plugload.objects.filter(network_status='ONLINE',
                                          plugload_id__bemoss=True)
    ]

    active_al = get_notifications()
    context.update({'active_al': active_al})
    context.update({
        'zones': zones,
        'thermostat_sn': thermostats_sn,
        'lighting_sn': lighting_sn,
        'plugload_sn': plugload_sn
    })

    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,
                'zones': zones,
                'thermostat_sn': thermostats_sn,
                'lighting_sn': lighting_sn,
                'plugload_sn': plugload_sn
            }, context)
    else:
        return HttpResponseRedirect('/home/')
Example #4
0
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
    zones = [ob.as_json() for ob in Building_Zone.objects.all()]
    thermostats_sn = [ob.data_side_nav() for ob in Thermostat.objects.filter(network_status='ONLINE',
                                                                             thermostat_id__bemoss=True)]
    lighting_sn = [ob.data_side_nav() for ob in Lighting.objects.filter(network_status='ONLINE',
                                                                        lighting_id__bemoss=True)]
    plugload_sn = [ob.data_side_nav() for ob in Plugload.objects.filter(network_status='ONLINE',
                                                                        plugload_id__bemoss=True)]

    context.update({
        'zones': zones, 'thermostat_sn': thermostats_sn,
         'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn
    })

    #For the page
    if device_type == 'th':
        thermostats = [ob.data_as_json() for ob in Thermostat.objects.filter(zone_id=zone_id, thermostat_id__bemoss=True)]
        if len(thermostats) != 0:
            zone_nickname = thermostats[0]['zone']['zone_nickname']
        #print thermostats

        active_al = get_notifications()
        context.update({'active_al':active_al})
        return render_to_response(
            'dashboard/thermostats.html',
            {'thermostats': thermostats, 'zone_id': zone_id, 'zone_nickname': zone_nickname,
             'zones': zones, 'thermostat_sn': thermostats_sn, 'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn}, context)

    elif device_type == 'lt':
        lighting = [ob.data_as_json() for ob in Lighting.objects.filter(zone_id=zone_id, lighting_id__bemoss=True)]
        zone_nickname = lighting[0]['zone']['zone_nickname']
        #print lighting

        return render_to_response(
            'dashboard/lighting_loads.html',
            {'lighting_loads': lighting, 'zone_id': zone_id, 'zone_nickname': zone_nickname,
             'zones': zones, 'thermostat_sn': thermostats_sn, 'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn}, context)

    elif device_type == 'pl':
        plugloads = [ob.data_as_json() for ob in Plugload.objects.filter(zone_id=zone_id, plugload_id__bemoss=True)]
        zone_nickname = plugloads[0]['zone']['zone_nickname']
        #print plugloads

        return render_to_response(
            'dashboard/plugloads.html',
            {'plugloads': plugloads, 'zone_id': zone_id, 'zone_nickname': zone_nickname,
             'zones': zones, 'thermostat_sn': thermostats_sn, 'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn
             }, context)
Example #5
0
def bemoss_home(request):
    context = RequestContext(request)
    username = request.user

    zones = [ob.as_json() for ob in Building_Zone.objects.all()]
    thermostats_sn = [ob.data_side_nav() for ob in Thermostat.objects.filter(network_status='ONLINE',
                                                                             thermostat_id__bemoss=True)]
    lighting_sn = [ob.data_side_nav() for ob in Lighting.objects.filter(network_status='ONLINE',
                                                                        lighting_id__bemoss=True)]
    plugload_sn = [ob.data_side_nav() for ob in Plugload.objects.filter(network_status='ONLINE',
                                                                        plugload_id__bemoss=True)]
    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__bemoss=True).count()
        t_count = th_count

        pl_count = Plugload.objects.filter(network_status='ONLINE', zone_id=zone.zone_id, plugload_id__bemoss=True).count()
        lt_count = Lighting.objects.filter(network_status='ONLINE', zone_id=zone.zone_id, lighting_id__bemoss=True).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})
    context.update({
            'zones': zones, 'thermostat_sn': thermostats_sn,
             'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn
    })

    return render_to_response(
        'dashboard/dashboard.html',
        {'zones_p': zones_p}, context)
Example #6
0
def bemoss_settings(request):
    print 'BEMOSS Settings page load'
    context = RequestContext(request)
    #username = request.session.get('user')
    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.PROJECT_DIR, 'resources/metadata/bemoss_metadata.json'), "r+")
    _json_data = json.load(json_file)
    b_location = _json_data['building_location_zipcode']
    json_file.close()

    zones = [ob.as_json() for ob in Building_Zone.objects.all()]
    thermostats_sn = [ob.data_side_nav() for ob in Thermostat.objects.filter(network_status='ONLINE', thermostat_id__bemoss=True)]
    lighting_sn = [ob.data_side_nav() for ob in Lighting.objects.filter(network_status='ONLINE', lighting_id__bemoss=True)]
    plugload_sn = [ob.data_side_nav() for ob in Plugload.objects.filter(network_status='ONLINE', plugload_id__bemoss=True)]

    active_al = get_notifications()
    context.update({'active_al':active_al})
    context.update({
            'zones': zones, 'thermostat_sn': thermostats_sn,
             'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn
            })

    if request.user.get_profile().group.name.lower() == 'admin':
        return render_to_response(
            'admin/bemoss_settings.html',
            {'holidays': holidays, 'zones': zones, 'thermostat_sn': thermostats_sn,
             'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn, 'b_location': b_location},
            context)
    else:
        return HttpResponseRedirect('/home/')
Example #7
0
def device_status(request):
    print 'Device status page load'
    context = RequestContext(request)
    #username = request.session.get('user')
    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.all()]
        print thermostats
        plugloads = [ob.device_status() for ob in Plugload.objects.all()]
        print plugloads
        lighting = [ob.device_status() for ob in Lighting.objects.all()]

        zones = [ob.as_json() for ob in Building_Zone.objects.all()]
        thermostats_sn = [ob.data_side_nav() for ob in Thermostat.objects.filter(network_status='ONLINE', thermostat_id__bemoss=True)]
        lighting_sn = [ob.data_side_nav() for ob in Lighting.objects.filter(network_status='ONLINE', lighting_id__bemoss=True)]
        plugload_sn = [ob.data_side_nav() for ob in Plugload.objects.filter(network_status='ONLINE', plugload_id__bemoss=True)]
        active_al = get_notifications()
        context.update({'active_al':active_al})
        context.update({
            'zones': zones, 'thermostat_sn': thermostats_sn,
             'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn
            })

        return render_to_response(
            'admin/device_status.html',
            {'thermostats': thermostats, 'plugloads': plugloads, 'lighting': lighting,
             'zones': zones, 'thermostat_sn': thermostats_sn,
             'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn},
            context)
    else:
        return HttpResponseRedirect('/home/')
Example #8
0
def user_manager(request):
    context = RequestContext(request)
    zones = [ob.as_json() for ob in Building_Zone.objects.all()]
    thermostats_sn = [ob.data_side_nav() for ob in Thermostat.objects.filter(network_status='ONLINE', thermostat_id__bemoss=True)]
    lighting_sn = [ob.data_side_nav() for ob in Lighting.objects.filter(network_status='ONLINE', lighting_id__bemoss=True)]
    plugload_sn = [ob.data_side_nav() for ob in Plugload.objects.filter(network_status='ONLINE', plugload_id__bemoss=True)]

    active_al = get_notifications()
    context.update({'active_al':active_al})
    context.update({
        'zones': zones, 'thermostat_sn': thermostats_sn,
         'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn
    })

    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, 'thermostat_sn': thermostats_sn,
             'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn, 'groups': groups}, context)
    else:
        return HttpResponseRedirect('/home/')
Example #9
0
def device_status(request):
    print 'Device status page load'
    context = RequestContext(request)
    #username = request.session.get('user')
    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.all()]
        print thermostats
        vavs = [ob.device_status() for ob in VAV.objects.all()]
        rtus = [ob.device_status() for ob in RTU.objects.all()]
        plugloads = [ob.device_status() for ob in Plugload.objects.all()]
        print plugloads
        lighting = [ob.device_status() for ob in Lighting.objects.all()]
        occupancy_sensors = [
            ob.device_status() for ob in OccupancySensor.objects.all()
        ]
        light_sensors = [
            ob.device_status() for ob in AmbientLightSensor.objects.all()
        ]
        motion_sensors = [
            ob.device_status() for ob in MotionSensor.objects.all()
        ]
        powermeters = [ob.device_status() for ob in PowerMeter.objects.all()]

        zones = [ob.as_json() for ob in Building_Zone.objects.all()]
        thermostats_sn = [
            ob.data_side_nav()
            for ob in Thermostat.objects.filter(network_status='ONLINE',
                                                thermostat_id__bemoss=True)
        ]
        vav_sn = [
            ob.data_side_nav()
            for ob in VAV.objects.filter(network_status='ONLINE',
                                         vav_id__bemoss=True)
        ]
        rtu_sn = [
            ob.data_side_nav()
            for ob in RTU.objects.filter(network_status='ONLINE',
                                         rtu_id__bemoss=True)
        ]
        lighting_sn = [
            ob.data_side_nav()
            for ob in Lighting.objects.filter(network_status='ONLINE',
                                              lighting_id__bemoss=True)
        ]
        plugload_sn = [
            ob.data_side_nav()
            for ob in Plugload.objects.filter(network_status='ONLINE',
                                              plugload_id__bemoss=True)
        ]
        occ_sensors_sn = [
            ob.data_side_nav() for ob in OccupancySensor.objects.filter(
                network_status='ONLINE', occupancy_sensor_id__bemoss=True)
        ]
        lt_sensors_sn = [
            ob.data_side_nav() for ob in AmbientLightSensor.objects.filter(
                network_status='ONLINE', ambient_light_sensor_id__bemoss=True)
        ]
        mtn_sensors_sn = [
            ob.data_side_nav() for ob in MotionSensor.objects.filter(
                network_status='ONLINE', motion_sensor_id__bemoss=True)
        ]
        powermeters_sn = [
            ob.data_side_nav()
            for ob in PowerMeter.objects.filter(network_status='ONLINE',
                                                power_meter_id__bemoss=True)
        ]
        active_al = get_notifications()
        context.update({'active_al': active_al})
        context.update({
            'zones': zones,
            'thermostat_sn': thermostats_sn,
            'lighting_sn': lighting_sn,
            'plugload_sn': plugload_sn,
            'occ_sensors_sn': occ_sensors_sn,
            'lt_sensors_sn': lt_sensors_sn,
            'mtn_sensors_sn': mtn_sensors_sn,
            'powermeters_sn': powermeters_sn,
            'vav_sn': vav_sn,
            'rtu_sn': rtu_sn
        })

        return render_to_response(
            'admin/device_status.html', {
                'thermostats': thermostats,
                'vavs': vavs,
                'rtus': rtus,
                'plugloads': plugloads,
                'lighting': lighting,
                'occupancy_sensors': occupancy_sensors,
                'light_sensors': light_sensors,
                'motion_sensors': motion_sensors,
                'powermeters': powermeters,
                'zones': zones,
                'thermostat_sn': thermostats_sn,
                'lighting_sn': lighting_sn,
                'plugload_sn': plugload_sn,
                'occ_sensors_sn': occ_sensors_sn,
                'lt_sensors_sn': lt_sensors_sn,
                'mtn_sensors_sn': mtn_sensors_sn,
                'powermeters_sn': powermeters_sn,
                'vav_sn': vav_sn,
                'rtu_sn': rtu_sn
            }, context)
    else:
        return HttpResponseRedirect('/home/')
Example #10
0
def bemoss_settings(request):
    print 'BEMOSS Settings page load'
    context = RequestContext(request)
    #username = request.session.get('user')
    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.PROJECT_DIR,
                     'resources/metadata/bemoss_metadata.json'), "r+")
    _json_data = json.load(json_file)
    b_location = _json_data['building_location_zipcode']
    json_file.close()

    zones = [ob.as_json() for ob in Building_Zone.objects.all()]
    thermostats_sn = [
        ob.data_side_nav()
        for ob in Thermostat.objects.filter(network_status='ONLINE',
                                            thermostat_id__bemoss=True)
    ]
    vav_sn = [
        ob.data_side_nav()
        for ob in VAV.objects.filter(network_status='ONLINE',
                                     vav_id__bemoss=True)
    ]
    rtu_sn = [
        ob.data_side_nav()
        for ob in RTU.objects.filter(network_status='ONLINE',
                                     rtu_id__bemoss=True)
    ]
    lighting_sn = [
        ob.data_side_nav()
        for ob in Lighting.objects.filter(network_status='ONLINE',
                                          lighting_id__bemoss=True)
    ]
    plugload_sn = [
        ob.data_side_nav()
        for ob in Plugload.objects.filter(network_status='ONLINE',
                                          plugload_id__bemoss=True)
    ]
    occ_sensors_sn = [
        ob.data_side_nav() for ob in OccupancySensor.objects.filter(
            network_status='ONLINE', occupancy_sensor_id__bemoss=True)
    ]
    lt_sensors_sn = [
        ob.data_side_nav() for ob in AmbientLightSensor.objects.filter(
            network_status='ONLINE', ambient_light_sensor_id__bemoss=True)
    ]
    mtn_sensors_sn = [
        ob.data_side_nav()
        for ob in MotionSensor.objects.filter(network_status='ONLINE',
                                              motion_sensor_id__bemoss=True)
    ]
    powermeters_sn = [
        ob.data_side_nav()
        for ob in PowerMeter.objects.filter(network_status='ONLINE',
                                            power_meter_id__bemoss=True)
    ]
    active_al = get_notifications()
    context.update({'active_al': active_al})
    context.update({
        'zones': zones,
        'thermostat_sn': thermostats_sn,
        'lighting_sn': lighting_sn,
        'plugload_sn': plugload_sn,
        'occ_sensors_sn': occ_sensors_sn,
        'lt_sensors_sn': lt_sensors_sn,
        'mtn_sensors_sn': mtn_sensors_sn,
        'powermeters_sn': powermeters_sn,
        'vav_sn': vav_sn,
        'rtu_sn': rtu_sn
    })

    if request.user.get_profile().group.name.lower() == 'admin':
        return render_to_response(
            'admin/bemoss_settings.html', {
                'holidays': holidays,
                'zones': zones,
                'thermostat_sn': thermostats_sn,
                'lighting_sn': lighting_sn,
                'plugload_sn': plugload_sn,
                'occ_sensors_sn': occ_sensors_sn,
                'lt_sensors_sn': lt_sensors_sn,
                'mtn_sensors_sn': mtn_sensors_sn,
                'powermeters_sn': powermeters_sn,
                'vav_sn': vav_sn,
                'rtu_sn': rtu_sn,
                'b_location': b_location
            }, context)
    else:
        return HttpResponseRedirect('/home/')
Example #11
0
def powermeter(request, mac):
    print 'inside powermeter 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_type = device_metadata[0]['device_type']

    device_status = [
        ob.data_as_json()
        for ob in PowerMeter.objects.filter(power_meter_id=device_id)
    ]
    device_zone = device_status[0]['zone']['id']
    device_nickname = device_status[0]['nickname']
    zone_nickname = device_status[0]['zone']['zone_nickname']
    '''
    device_info = [ob.as_json() for ob in Device_Info.objects.filter(mac_address=mac)]
    device_id = device_info[0]['id']
    device_zone = device_info[0]['zone']['id']
    device_nickname = device_info[0]['nickname']
    zone_nickname = device_info[0]['zone']['zone_nickname']
    device_type_id = device_info[0]['device_type_id']
    print device_type_id
    print device_zone 
    '''

    info_required = "Update Hue data"
    powermeter_update_send_topic = '/ui/agent/bemoss/' + str(
        device_zone) + '/' + device_type + '/' + device_id + '/device_status'
    zmq_pub.requestAgent(powermeter_update_send_topic, info_required,
                         "text/plain", "UI")
    '''
    json_file = open(os.path.join(settings.PROJECT_DIR, 'resources/page_load/page_load.json'), "r+")
    _json_data = json.load(json_file)
    if device_id not in _json_data[device_type]:
        _json_data[device_type][device_id] = {"page_load": "{empty_string}"}

    json_file.seek(0)
    json_file.write(json.dumps(_json_data, indent=4, sort_keys=True))
    json_file.truncate()
    json_file.close()

    time.sleep(3)'''

    _data = _helper.get_page_load_data(device_id, device_type, device_type_id)

    zones = [ob.as_json() for ob in Building_Zone.objects.all()]
    thermostats_sn = [
        ob.data_side_nav()
        for ob in Thermostat.objects.filter(network_status='ONLINE',
                                            thermostat_id__bemoss=True)
    ]
    vav_sn = [
        ob.data_side_nav()
        for ob in VAV.objects.filter(network_status='ONLINE',
                                     vav_id__bemoss=True)
    ]
    rtu_sn = [
        ob.data_side_nav()
        for ob in RTU.objects.filter(network_status='ONLINE',
                                     rtu_id__bemoss=True)
    ]
    lighting_sn = [
        ob.data_side_nav()
        for ob in Lighting.objects.filter(network_status='ONLINE',
                                          lighting_id__bemoss=True)
    ]
    plugload_sn = [
        ob.data_side_nav()
        for ob in Plugload.objects.filter(network_status='ONLINE',
                                          plugload_id__bemoss=True)
    ]
    occ_sensors_sn = [
        ob.data_side_nav() for ob in OccupancySensor.objects.filter(
            network_status='ONLINE', occupancy_sensor_id__bemoss=True)
    ]
    lt_sensors_sn = [
        ob.data_side_nav() for ob in AmbientLightSensor.objects.filter(
            network_status='ONLINE', ambient_light_sensor_id__bemoss=True)
    ]
    mtn_sensors_sn = [
        ob.data_side_nav()
        for ob in MotionSensor.objects.filter(network_status='ONLINE',
                                              motion_sensor_id__bemoss=True)
    ]
    powermeters_sn = [
        ob.data_side_nav()
        for ob in PowerMeter.objects.filter(network_status='ONLINE',
                                            power_meter_id__bemoss=True)
    ]
    active_al = get_notifications()
    context.update({'active_al': active_al})
    context.update({
        'zones': zones,
        'thermostat_sn': thermostats_sn,
        'lighting_sn': lighting_sn,
        'plugload_sn': plugload_sn,
        'occ_sensors_sn': occ_sensors_sn,
        'lt_sensors_sn': lt_sensors_sn,
        'mtn_sensors_sn': mtn_sensors_sn,
        'powermeters_sn': powermeters_sn,
        'vav_sn': vav_sn,
        'rtu_sn': rtu_sn
    })

    return render_to_response(
        'powermeter/powermeter.html', {
            'device_data': _data,
            'device_id': device_id,
            'device_zone': device_zone,
            'zone_nickname': zone_nickname,
            'mac_address': mac,
            'device_nickname': device_nickname,
            'zones': zones,
            'thermostat_sn': thermostats_sn,
            'lighting_sn': lighting_sn,
            'plugload_sn': plugload_sn,
            'occ_sensors_sn': occ_sensors_sn,
            'lt_sensors_sn': lt_sensors_sn,
            'mtn_sensors_sn': mtn_sensors_sn,
            'powermeters_sn': powermeters_sn,
            'vav_sn': vav_sn,
            'rtu_sn': rtu_sn,
            'device_type_id': device_type_id
        }, context)
Example #12
0
            temp_f = '77'
            humidity = '10%'
            precip = '0.0'
            winds = '1.0'
            icon = 'mostlysunny'
            weather = 'Sunny'

        #weather_icon = SessionHelper.get_weather_icon(icon)
    weather_icon = config_helper.get_weather_icon(icon)
    print "icon "+weather_icon

    zones = [ob.as_json() for ob in Building_Zone.objects.all()]
    thermostats_sn = [ob.data_side_nav() for ob in Thermostat.objects.filter(network_status='ONLINE', thermostat_id__bemoss=True)]
    lighting_sn = [ob.data_side_nav() for ob in Lighting.objects.filter(network_status='ONLINE', lighting_id__bemoss=True)]
    plugload_sn = [ob.data_side_nav() for ob in Plugload.objects.filter(network_status='ONLINE', plugload_id__bemoss=True)]
    active_al = get_notifications()
    context.update({'active_al':active_al})
    context.update({
            'zones': zones, 'thermostat_sn': thermostats_sn,
             'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn})

    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, 'weather_icon': weather_icon, 'weather': weather, 'mac': mac},
        context)


def get_zip_code():
    try:
Example #13
0
    thermostats_sn = [
        ob.data_side_nav()
        for ob in Thermostat.objects.filter(network_status='ONLINE',
                                            thermostat_id__bemoss=True)
    ]
    lighting_sn = [
        ob.data_side_nav()
        for ob in Lighting.objects.filter(network_status='ONLINE',
                                          lighting_id__bemoss=True)
    ]
    plugload_sn = [
        ob.data_side_nav()
        for ob in Plugload.objects.filter(network_status='ONLINE',
                                          plugload_id__bemoss=True)
    ]
    active_al = get_notifications()
    context.update({'active_al': active_al})
    context.update({
        'zones': zones,
        'thermostat_sn': thermostats_sn,
        'lighting_sn': lighting_sn,
        'plugload_sn': plugload_sn
    })

    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,
Example #14
0
def thermostat_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':
        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 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']
        #Send message to OS to launch application
        app_launcher_topic = '/ui/appLauncher/thermostat_scheduler/' + device_id + '/launch'
        token = {"auth_token": "bemoss"}
        zmq_pub.requestAgent(app_launcher_topic, json.dumps(token),
                             "application/json", "UI")

        zones = [ob.as_json() for ob in Building_Zone.objects.all()]
        thermostats_sn = [
            ob.data_side_nav()
            for ob in Thermostat.objects.filter(network_status='ONLINE',
                                                thermostat_id__bemoss=True)
        ]
        lighting_sn = [
            ob.data_side_nav()
            for ob in Lighting.objects.filter(network_status='ONLINE',
                                              lighting_id__bemoss=True)
        ]
        plugload_sn = [
            ob.data_side_nav()
            for ob in Plugload.objects.filter(network_status='ONLINE',
                                              plugload_id__bemoss=True)
        ]

        active_al = get_notifications()
        context.update({'active_al': active_al})
        context.update({
            'zones': zones,
            'thermostat_sn': thermostats_sn,
            'lighting_sn': lighting_sn,
            'plugload_sn': plugload_sn
        })

        _data = {}
        active_schedule = []
        disabled_range = __.DISABLED_VALUES_THERMOSTAT

        #Check if schedule file for this device exists
        _file_name = os.path.join(
            settings.PROJECT_DIR, 'resources/scheduler_data/thermostat/' +
            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['thermostat']:
                print 'device id present'
                _data = _json_data['thermostat'][device_id]['schedulers']

                active_schedule = _json_data['thermostat'][device_id]['active']
                active_schedule = [str(x) for x in active_schedule]
                disabled_range = get_disabled_date_ranges_thermostat(_data)
                #disabled_range = get_disabled_date_ranges(_data, disabled_values_plugload)
                _data = json.dumps(_data)
                _data = json.loads(_data, object_hook=_decode_dict)
            json_file.close()
        else:
            #json_file = open(_file_name, 'w+')
            _json_data = {
                "thermostat": {
                    device_id: {
                        "active": ['everyday', 'holiday'],
                        "inactive": [],
                        "schedulers": __.THERMOSTAT_DEFAULT_SCHEDULE
                    }
                }
            }

            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['thermostat'][device_id]['schedulers']
            else:
                _json_data = json.loads(_json_data)
                _data = _json_data['thermostat'][device_id]['schedulers']
            active_schedule = ['everyday', 'holiday']
            disabled_range = get_disabled_date_ranges_thermostat(_data)

        return render_to_response(
            'schedule/th_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,
                'zones': zones,
                'thermostat_sn': thermostats_sn,
                'lighting_sn': lighting_sn,
                'plugload_sn': plugload_sn
            }, context)
    else:
        return HttpResponseRedirect('/home')
Example #15
0
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':
        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']

        '''
        device_info = [ob.as_json() for ob in Device_Info.objects.filter(mac_address=mac)]
        print device_info
        device_id = device_info[0]['id']
        device_id = device_id.encode('ascii', 'ignore')
        device_zone = device_info[0]['zone']['id']
        device_nickname = device_info[0]['nickname']
        zone_nickname = device_info[0]['zone']['zone_nickname']
        device_type_id = device_info[0]['device_type_id']
        print device_id
        print device_zone
        '''

        # 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.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)

        '''
        json_file = open(os.path.join(settings.PROJECT_DIR, 'resources/scheduler_data/lighting_schedule.json'), "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)
        else:
            _data = {}
            active_schedule = []
            disabled_range = disabled_values_lighting
        '''

        zones = [ob.as_json() for ob in Building_Zone.objects.all()]
        thermostats_sn = [ob.data_side_nav() for ob in Thermostat.objects.filter(network_status='ONLINE', thermostat_id__bemoss=True)]
        lighting_sn = [ob.data_side_nav() for ob in Lighting.objects.filter(network_status='ONLINE', lighting_id__bemoss=True)]
        plugload_sn = [ob.data_side_nav() for ob in Plugload.objects.filter(network_status='ONLINE', plugload_id__bemoss=True)]
        active_al = get_notifications()
        context.update({'active_al':active_al})
        context.update({
            'zones': zones, 'thermostat_sn': thermostats_sn,
             'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn
            })

        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,
             'zones': zones,
             'thermostat_sn': thermostats_sn,
             'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn}, context)
    else:
        return HttpResponseRedirect('/home/')
Example #16
0
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':
        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']

        '''
        device_info = [ob.as_json() for ob in Device_Info.objects.filter(mac_address=mac)]
        print device_info
        device_id = device_info[0]['id']
        device_id = device_id.encode('ascii', 'ignore')
        device_zone = device_info[0]['zone']['id']
        device_nickname = device_info[0]['nickname']
        zone_nickname = device_info[0]['zone']['zone_nickname']
        device_type_id = device_info[0]['device_type_id']
        print device_id
        print device_zone
        '''

        # 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.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)

        '''
        json_file = open(os.path.join(settings.PROJECT_DIR, 'resources/scheduler_data/lighting_schedule.json'), "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)
        else:
            _data = {}
            active_schedule = []
            disabled_range = disabled_values_lighting
        '''

        zones = [ob.as_json() for ob in Building_Zone.objects.all()]
        thermostats_sn = [ob.data_side_nav() for ob in Thermostat.objects.filter(network_status='ONLINE', thermostat_id__bemoss=True)]
        vav_sn = [ob.data_side_nav() for ob in VAV.objects.filter(network_status='ONLINE', vav_id__bemoss=True)]
        rtu_sn = [ob.data_side_nav() for ob in RTU.objects.filter(network_status='ONLINE', rtu_id__bemoss=True)]
        lighting_sn = [ob.data_side_nav() for ob in Lighting.objects.filter(network_status='ONLINE', lighting_id__bemoss=True)]
        plugload_sn = [ob.data_side_nav() for ob in Plugload.objects.filter(network_status='ONLINE', plugload_id__bemoss=True)]
        occ_sensors_sn = [ob.data_side_nav() for ob in OccupancySensor.objects.filter(network_status='ONLINE', occupancy_sensor_id__bemoss=True)]
        lt_sensors_sn = [ob.data_side_nav() for ob in AmbientLightSensor.objects.filter(network_status='ONLINE', ambient_light_sensor_id__bemoss=True)]
        mtn_sensors_sn = [ob.data_side_nav() for ob in MotionSensor.objects.filter(network_status='ONLINE', motion_sensor_id__bemoss=True)]
        powermeters_sn = [ob.data_side_nav() for ob in PowerMeter.objects.filter(network_status='ONLINE', power_meter_id__bemoss=True)]
        active_al = get_notifications()
        context.update({'active_al':active_al})
        context.update({
            'zones': zones, 'thermostat_sn': thermostats_sn,
             'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn, 'occ_sensors_sn': occ_sensors_sn,
             'lt_sensors_sn': lt_sensors_sn, 'mtn_sensors_sn': mtn_sensors_sn,  'powermeters_sn': powermeters_sn,
             'vav_sn': vav_sn, 'rtu_sn': rtu_sn
            })

        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,
             'zones': zones,
             'thermostat_sn': thermostats_sn,
             'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn, 'occ_sensors_sn': occ_sensors_sn,
             'lt_sensors_sn': lt_sensors_sn, 'mtn_sensors_sn': mtn_sensors_sn,  'powermeters_sn': powermeters_sn,
             'vav_sn': vav_sn, 'rtu_sn': rtu_sn}, context)
    else:
        return HttpResponseRedirect('/home/')
Example #17
0
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']

    kwargs = {'subscribe_address': 'ipc:///tmp/volttron-lite-agent-subscribe',
                    'publish_address': 'ipc:///tmp/volttron-lite-agent-publish'}
    _zmq_pub = zmqPub(**kwargs)
 
    print "created instance of the zmqpub class"
    info_required = "Update Hue data"
    wifi_3m50_update_send_topic = '/ui/agent/bemoss/' + str(device_zone) + '/lighting/' + device_id + '/device_status'
    _zmq_pub.requestAgent(wifi_3m50_update_send_topic, info_required, "text/plain", "UI")

    json_file = open(os.path.join(settings.PROJECT_DIR, 'resources/page_load/page_load.json'), "r+")
    _json_data = json.load(json_file)
    if device_id not in _json_data['lighting']:
        _json_data['lighting'][device_id] = {"page_load": "{empty_string}"}

    json_file.seek(0)
    json_file.write(json.dumps(_json_data, indent=4, sort_keys=True))
    json_file.truncate()
    json_file.close()

    time.sleep(3)

    _data = _helper.get_page_load_data(device_id, 'lighting', controller_type)

    zones = [ob.as_json() for ob in Building_Zone.objects.all()]
    thermostats_sn = [ob.data_side_nav() for ob in Thermostat.objects.filter(network_status='ONLINE', thermostat_id__bemoss=True)]
    lighting_sn = [ob.data_side_nav() for ob in Lighting.objects.filter(network_status='ONLINE', lighting_id__bemoss=True)]
    plugload_sn = [ob.data_side_nav() for ob in Plugload.objects.filter(network_status='ONLINE', plugload_id__bemoss=True)]
    active_al = get_notifications()
    context.update({'active_al':active_al})
    context.update({
            'zones': zones, 'thermostat_sn': thermostats_sn,
             'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn
            })

    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, 'zones': zones, 'thermostat_sn': thermostats_sn,
         'lighting_sn': lighting_sn, 'plugload_sn': plugload_sn}, context)