예제 #1
0
 def GET(self):
     super(CoopGetStatus, self).GET()
     coop = Coop()
     coop.check()
     return render.index(
         coop.status,
         coop.rebooting,
         now().format('MMMM DD, hh:mm a'),
         coop.sunset_sunrise_sensor.state,
         coop.sunset_sunrise_sensor.status(),
         coop.sunset_sunrise_sensor.sunrise_display(display_extra=False),
         coop.sunset_sunrise_sensor.sunset_display(display_extra=False),
         coop.ambient_temp_humi_sensor.state,
         coop.ambient_temp_humi_sensor.status(),
         format_temp(coop.ambient_temp_humi_sensor.temp),
         format_humi(coop.ambient_temp_humi_sensor.humi),
         format_temp(coop.water_temp_sensor.temp),
         coop.water_temp_sensor.get_state_for_display(),
         coop.water_temp_sensor.status(),
         format_temp(coop.water_heater.temp_range[0]),
         format_temp(coop.water_heater.temp_range[1]),
         coop.water_heater.state,
         coop.water_heater.status(),
         coop.water_heater_relay.state,
         coop.door_dual_sensor.state,
         coop.sunset_sunrise_sensor.sunrise_display(include_extra=True,
                                                    display_extra=True,
                                                    include_day=False),
         coop.sunset_sunrise_sensor.sunset_display(include_extra=True,
                                                   display_extra=True,
                                                   include_day=False),
         coop.door.state,
         coop.door.status(),
         coop.water_level_dual_sensor.state,
         coop.water_level_dual_sensor.status(),
         coop.light.state,
         coop.light.status(),
         format_temp(coop.fan.temp_range[0]),
         format_temp(coop.fan.temp_range[1]),
         coop.fan.state,
         coop.fan.status(),
         format_temp(coop.heater.temp_range[0]),
         format_temp(coop.heater.temp_range[1]),
         coop.heater.state,
         coop.heater.status(),
         coop.heater_relay.state,
         coop.config['Webcam']['URL'],
     )
예제 #2
0
def validate_user(ctx, notify=False):
    if not ctx.env.get('HTTP_AUTHORIZATION'):
        return False
    username, password = get_username_password(
        ctx.env.get('HTTP_AUTHORIZATION'))
    coop = Coop()
    if username == coop.config['Authentication'][
            'USERNAME'] and password == coop.config['Authentication'][
                'PASSWORD']:
        return True
    else:
        if notify:
            coop.notifier_callback(
                Notification(
                    'WARN',
                    'Failed login attempt: username={username}, password={password}, ip={ip}',
                    username=username,
                    password=password,
                    ip=ctx['ip']))
        return False
예제 #3
0
 def GET(self, action):
     super(DoorOpenClose, self).GET()
     if action not in ('open', 'close'):
         raise web.seeother('/')
     coop = Coop()
     event = EventData(None, None, None, None, None,
                       {'switches': coop.door_dual_sensor})
     if action == 'open':
         coop.door.open(event)
         state = 'open'
     else:
         coop.door.close(event)
         state = 'closed'
     day_night = coop.sunset_sunrise_sensor.state
     if day_night == 'invalid':
         day_night = 'night'
     coop.door.set_state('manual-{}-{}'.format(state, day_night))
     raise web.seeother('/')
예제 #4
0
 def GET(self):
     coop = Coop()
     coop.check()
     return render.heartbeat(coop.status, coop.rebooting)
예제 #5
0
    def GET(self):
        super(TempHumiGraph, self).GET()
        get_data = web.input(range_days='7', action='read')
        range_days = get_data.range_days
        coop = Coop()
        db = get_db(coop)
        data = Data([
            scatter_graph_timeseries(db,
                                     'AMBIENT_TEMP',
                                     'Air Temperature',
                                     'red',
                                     range_days=range_days),
            scatter_graph_timeseries(db,
                                     'WATER_TEMP',
                                     'Water Temperature',
                                     'blue',
                                     range_days=range_days),
            scatter_graph_timeseries(db,
                                     'AMBIENT_HUMI',
                                     'Humidity',
                                     'green',
                                     width=1,
                                     yaxis2=True,
                                     range_days=range_days),
        ])
        min_x = min(min(data[0].x), min(data[1].x), min(data[2].x))
        max_x = max(max(data[0].x), max(data[1].x), max(data[2].x))
        temp_min = coop.config['Water']['HEATER_TEMP_RANGE'][1]
        temp_max = coop.config['AmbientTempHumi']['TEMP_FAN']
        layout = Layout(title='Temperature & Humidity',
                        height=600,
                        xaxis={
                            'title': 'Date',
                        },
                        yaxis={
                            'title': 'Temperature (F)',
                        },
                        yaxis2={
                            'title': 'Humidity (%)',
                            'type': 'linear',
                            'range': [0, 100],
                            'fixedrange': True,
                            'overlaying': 'y',
                            'side': 'right',
                            'showgrid': False,
                        },
                        shapes=[
                            {
                                'type': 'line',
                                'x0': min_x,
                                'y0': temp_max,
                                'x1': max_x,
                                'y1': temp_max,
                                'line': {
                                    'color': 'red',
                                    'width': 1,
                                    'dash': 'dot',
                                },
                            },
                            {
                                'type': 'line',
                                'x0': min_x,
                                'y0': temp_min,
                                'x1': max_x,
                                'y1': temp_min,
                                'line': {
                                    'color': 'blue',
                                    'width': 1,
                                    'dash': 'dot',
                                },
                            },
                        ])
        figure = Figure(data=data, layout=layout)
        graph = plot(figure, auto_open=False, output_type='div')

        return render.temp_humi_graph(
            coop.status,
            graph,
            range_days,
            coop.config['Webcam']['URL'],
        )
예제 #6
0
 def GET(self):
     super(Reboot, self).GET()
     username, _ = get_username_password(
         web.ctx.env.get('HTTP_AUTHORIZATION'))
     coop = Coop()
     coop.rebooting = True
     coop.notifier_callback(
         Notification('WARN',
                      'Reboot initiated by user {username}',
                      username=username))
     coop.stop()
     coop.join()
     coop.shutdown()
     call(['/usr/bin/sudo', '/sbin/shutdown', '-r', 'now'])
     raise web.seeother('/')
예제 #7
0
 def GET(self, mode):
     super(DoorSetMode, self).GET()
     coop = Coop()
     _single_relay_operated_object_set_mode(coop.door,
                                            mode,
                                            switches=coop.door_dual_sensor)
예제 #8
0
 def GET(self, state):
     super(LightSetOnOff, self).GET()
     coop = Coop()
     _single_relay_operated_object_set_on_off(coop.light, state)
예제 #9
0
 def GET(self, mode):
     super(LightSetMode, self).GET()
     coop = Coop()
     _single_relay_operated_object_set_mode(coop.light, mode)
예제 #10
0
 def GET(self, state):
     super(HeaterSetOnOff, self).GET()
     coop = Coop()
     _single_relay_operated_object_set_on_off(coop.heater, state)
예제 #11
0
 def GET(self, mode):
     super(HeaterSetMode, self).GET()
     coop = Coop()
     _single_relay_operated_object_set_mode(coop.heater, mode)
예제 #12
0
 def GET(self, mode):
     super(FanSetMode, self).GET()
     coop = Coop()
     _single_relay_operated_object_set_mode(coop.fan, mode)