def latest_reading(sensor_name): sc.init_db(DB % sensor_name, CREATE_SQL % sensor_name) v = sc.select(DB % sensor_name, LATEST_SQL % sensor_name, []) if len(v) > 0: return v[0] else: return None
def lights_on(): sc.init_db(DB, CREATE_SQL) v = sc.select(DB, LATEST_SQL, []) if v is None: return False else: return v == 1
def historical(start, stop): sc.init_db(DB, CREATE_SQL) return sc.select(DB, HISTORICAL_SQL, (start, stop))
def historical_charging(start, stop): sc.init_db(DB, CREATE_SQL) values = sc.select(DB, HISTORICAL_CHARGING_SQL, (start, stop)) return [(c, "bool", t) for (c, t) in values]
def historical_levels(start, stop): sc.init_db(DB, CREATE_SQL) values = sc.select(DB, HISTORICAL_LEVELS_SQL, (start, stop)) return [(p, "percent", t) for (p, t) in values]
def historical(sensor_name, start, stop): sc.init_db(DB % sensor_name, CREATE_SQL % sensor_name) return sc.select(DB % sensor_name, SELECT_SQL % sensor_name, (start, stop))