示例#1
0
    def begin(self):
        """
        Begin the alarm monitor loop
        """

        # Read baseline
        self.state = get_zone_state()

        while self.enabled:
            # Read state
            new_state = get_zone_state()

            # Create a list of changed zones since the last call
            changed = [{"key": key, 
                        "name": ZONE_DEFINITIONS[key],
                        "state": value, 
                        "state_text": ZONE_STATE_TEXT[key][int(value)]}
                       for key, value in new_state.iteritems()
                       if value != self.state[key]]

            # This is now our state
            self.state = new_state

            # call the handlers
            if changed:
                for handler in self.handlers:
                    handler(changed)
                    
            time.sleep(.2)
示例#2
0
def record_data(nest_user, nest_password, weather_station):
    """
    Collect the data and send it to the database
    """

    weather = read_weather(weather_station)
    nest = Nest(nest_user, nest_password)
    nest.login()
    nest.read_status()

    irrigation_state = sprinkler_state()
    alarm_zones = get_zone_state()

    data = {
        "entryDate": datetime.now(),
        "irrigation_zone1": irrigation_state["zone1"],
        "irrigation_zone2": irrigation_state["zone2"],
        "irrigation_zone3": irrigation_state["zone3"],
        "irrigation_zone4": irrigation_state["zone4"],
        "alarm_zone1": alarm_zones["zone1"],
        "alarm_zone2": alarm_zones["zone2"],
        "alarm_zone3": alarm_zones["zone3"],
        "alarm_zone4": alarm_zones["zone4"],
        "alarm_zone5": alarm_zones["zone5"],
        "alarm_zone6": alarm_zones["zone6"],
        "alarm_zone7": alarm_zones["zone7"],
        "alarm_zone8": alarm_zones["zone8"],
        "alarm_zone9": alarm_zones["zone9"],
        "outside_temp": temperature(weather),
        "outside_humidity": humidity(weather),
        "rainfall": current_rain(weather),
        "wind_speed": wind_speed(weather),
    }

    data.update(nest.history_states())
    update_history(data)