Beispiel #1
0
def ambient_lights():
    global previous_value
    count = 0
    if not cfg.getboolean('ambient', 'enabled'):
        log.debug("ambient not enabled...skipping.")
        return

    low_ambient_level  = cfg.getint('ambient', 'low')
    max_ambient_level  = cfg.getint('ambient', 'max')

    value = lightbot.query_sensor()
    log.debug("ambient_lights enabled=%s current=%s prev=%s" % \
            (lightbot.AMBIENT, value, previous_value))
    if lightbot.AMBIENT and \
       value <= low_ambient_level and \
       previous_value <= low_ambient_level:
        # brighten the lights, but give up after a few tries in case 
        # something has gone wrong
        while value and value < low_ambient_level and count < 20:
            log.debug("Increasing brightness.") 
            lightbot.lights_bright(repeat=2)
            count += 1
            value = lightbot.query_sensor()
            time.sleep(0.2)

        if count == 20:
            # increasing the brightness isn't doing anything for us...
            # it's likely dark now and the lights should be all on, so turn off
            # ambient lighting until the next time period
            log.debug("Reached maximum level.  Turning ambient lighting off.")
            lightbot.AMBIENT = False

    if value and value >= max_ambient_level and \
       previous_value >= max_ambient_level:
        log.debug("Sensor greater than max_ambient_level. Turning off lights.") 
        lightbot.lights_off()

    if value:
        previous_value = value
Beispiel #2
0
def turn_off_lights(disable_ambient=True):
    log.debug("Turning off lights") 
    lightbot.lights_off()
    lightbot.AMBIENT = not disable_ambient
Beispiel #3
0
def turn_off_lights():
    log.info("Turning off lights") 
    lightbot.lights_off()