Exemplo n.º 1
0
    def process_windows(self, ow):
        """
        Process dictionary and set ventilation status, then update owl web file
        :param ow: dictionary, open windows
        :return: nothing
        """
        # if count of open windows >= number of windows, that mean ventilation
        if len(ow) >= self.setup.ventilate_num:
            self.var.ventilating = True
        else:
            self.var.ventilating = False

        # write second web file

        secweb.write("owl", ow)
        # write bridge value
        bridge.put("owl", ow)
        # if open window warning is on and open window(s) count < number of open windows, that mean ventilation
        # send warnings for these windows
        if not self.setup.no_oww and len(ow) < self.setup.ventilate_num:
            for k, v in ow.iteritems():
                if self._is_win_open_too_long(k):
                    logmsg.update("Warning condition for window " + str(k) +
                                  " met")
                    self.send_warning("window", k, "")
Exemplo n.º 2
0
 def process_msg(self):
     """
     Process message queue
     :return: nothing
     """
     cw_msg = bridge.rcw("msg")
     while len(self.var.msgQ) > 0:
         logmsg.update("Message queue=" + str(self.var.msgQ), 'D')
         while not str(bridge.get(cw_msg)) == "":
             time.sleep(self.setup.timeout)
             tosend = self.var.msgQ.pop()
             logmsg.update("Sending message [" + str(tosend) + "]", 'D')
             if tosend == "E":
                 self.var.error = True
                 self.var.err2Clear = True
             elif tosend == "C":
                 self.var.err2Clear = False
                 self.var.err2LastStatus = True
                 logmsg.update("Clearing error LED", 'D')
             elif tosend == "R":
                 bridge.save(self.setup.bridgefile)
             if self.setup.target == "yun":
                 bridge.put(cw_msg, tosend)
             elif self.setup.target == "rpi":
                 if tosend == "H":
                     # action.do(True)
                     pass
                 elif tosend == "S":
                     # action.do(False)
                     pass
Exemplo n.º 3
0
    def write_strings(self):
        """ construct and write CSV data, Log debug string and current status string """
        log_str = bridge.try_read("status", False) + ", "
        if self.setup.preference == "per":
            log_str += str(self.setup.valve_switch) + "%" + " at " + str(
                self.setup.valve_num) + " valve(s)."
        elif self.setup.preference == "total":
            log_str += "total value of " + str(self.setup.total_switch) + "."
        log_str += "\n"

        csvfile.write(time.strftime("%d/%m/%Y %H:%M:%S", time.localtime()),
                      1 if self.var.heating else 0,
                      1 if self.var.ventilating else 0)
        csvfile.write(self.eq3.csv())
        csvfile.write("\n")

        # second web
        # JSON formatted status
        json_status = self.eq3.json_status()
        secweb.write("status", json_status)
        # and bridge variable
        bridge.put("sys", json_status)
        # nice text web
        secweb.nice(log_str + self.eq3.plain())
        # readiness for dashboard
        bridge.save(secweb.sw.location["bridge"])
Exemplo n.º 4
0
    def update_ignores_2sit(self):
        """
        Update open window variables according to weather
        :return: nothing
        """
        self.var.situation = weather.weather_for_woeid(
            self.setup.yahoo_location, self.setup.owm_location,
            self.setup.owm_api_key)
        if None not in self.var.situation.viewvalues():
            temp = int(self.var.situation["current_temp"])
            if temp is not None:
                # modify OWW
                # interval for oww 5min to 360min
                tmr = weather.interval_scale(temp, (-35.0, 35.0), (0, 10),
                                             (5, 360), True)
                self.setup.intervals["oww"] = [
                    tmr * 60, (3 * tmr) * 60, (3 * tmr) * 60
                ]
                logmsg.update("OWW interval updated to " +
                              str(self.setup.intervals["oww"]))

                # and now modify valve ignore time
                # interval for valve ignore 20min to 120min
                tmr = weather.interval_scale(temp, (0.0, 35.0), (1.7, 3.0),
                                             (20, 120), False)
                self.eq3.ignore_time = self.setup.window_ignore_time + tmr
                bridge.put("ign_op", self.eq3.ignore_time)
                logmsg.update(
                    "Valve ignore interval updated to " +
                    str(self.eq3.ignore_time), 'D')
Exemplo n.º 5
0
 def _getcmd(self):
     cmd_cw = bridge.rcw("cmd")
     localcmd = bridge.get(cmd_cw)
     if localcmd is None:
         return ""
     elif len(localcmd) > 0:
         bridge.put(cmd_cw, "")
     return localcmd
Exemplo n.º 6
0
 def _do_heat(self, state):
     if state:
         bridge.put("ht", self.var.ht)
         self.queue_msg("H")
     else:
         self.queue_msg("S")
     self.var.heating = state
     self.update_counters(state)
     self._set_status()
Exemplo n.º 7
0
 def _do_heat(self, state):
     if state:
         bridge.put("ht", self.var.ht)
         self.queue_msg("H")
     else:
         self.queue_msg("S")
     self.var.heating = state
     self.update_counters(state)
     self._set_status()
Exemplo n.º 8
0
 def set_mode(self, value):
     if value[3] == "total":
         self.setup.total_switch = value[2]
     else:
         self.setup.valve_switch = value[2]
     self.setup.preference = value[3]
     self.setup.intervals["max"][0] = value[4]
     self.setup.valve_num = value[5]
     # just sleep value, always calculated as max[0] / slp[1]
     self.setup.intervals["slp"][0] = int(value[4] / self.setup.intervals["slp"][1])
     bridge.put("int", self.setup.intervals["max"][0])
Exemplo n.º 9
0
 def set_mode(self, value):
     if value[3] == "total":
         self.setup.total_switch = value[2]
     else:
         self.setup.valve_switch = value[2]
     self.setup.preference = value[3]
     self.setup.intervals["max"][0] = value[4]
     self.setup.valve_num = value[5]
     # just sleep value, always calculated as max[0] / slp[1]
     self.setup.intervals["slp"][0] = int(value[4] /
                                          self.setup.intervals["slp"][1])
     bridge.put("int", self.setup.intervals["max"][0])
Exemplo n.º 10
0
    def update_counters(self, heat_start):
        # save the date
        nw = datetime.datetime.date(
            datetime.datetime.now()).strftime("%d-%m-%Y")
        tm = time.time()
        support.call_home("applive")
        # is there a key for today?
        # logmsg.debug("ht=", self.var.ht, ", heat_start=", heat_start)
        if nw in self.var.ht:
            if heat_start:
                self.var.ht[nw][1] = tm
            elif self.var.heating:
                daily_heat_sum = int(self.var.ht[nw][0] +
                                     (tm - self.var.ht[nw][1]))
                logmsg.debug("Daily heat sum=", daily_heat_sum)
                self.var.ht[nw] = [daily_heat_sum, time.time()]
                bridge.put("ht", self.var.ht)
                logmsg.update("Daily heat counter updated to " +
                              str(datetime.timedelta(seconds=daily_heat_sum)))
        else:
            if len(self.var.ht) > 0:
                # if there a key, this must be old key(s)
                # save the old date, and flush values into log
                for k in self.var.ht.keys():
                    v = self.var.ht[k]
                    logmsg.update(
                        str(k) + " daily heating summary: " +
                        str(datetime.timedelta(seconds=v[0])), 'I')
                    logmsg.update("Deleting old daily key: " + str(k), 'D')
                    del self.var.ht[k]
                self.export_csv("close")

            # create the new key
            self.var.ht.update({nw: [0, time.time()]})
            logmsg.update("Creating new daily key: " + str(nw) + "=" +
                          str(self.var.ht[nw]))
            # so its a new day, update other values
            self.export_csv("init")
            # day readings warning, take number of heated readings and divide by 2
            drw = self.var.heat_readings / 2
            logmsg.update("Day reading warnings value=" + str(drw))
            for k, v in self.var.dev_log.iteritems():
                logmsg.update("Valve: " + str(k) + " has value " + str(v[0]))
                if v[0] > drw:
                    logmsg.update(
                        "Valve: " + str(k) +
                        " reports during heating too many same % positions, e.g. "
                        + str(v[0]) + " per " + str(drw))
                self.var.dev_log[k][0] = 0
            self.var.heat_readings = 0
            bridge.save(self.setup.bridge_file)
        bridge.put("ht", self.var.ht)
Exemplo n.º 11
0
    def update_ignores_2sit(self):
        self.var.situation = weather.weather_for_woeid(self.setup.location)
        temp = int(self.var.situation["current_temp"])

        # modify OWW
        tmr = weather.interval_scale(temp, (-35.0, 35.0), (0, 10), (10, 360), True)
        self.setup.intervals["oww"] = [tmr * 60, (3 * tmr) * 60, (3 * tmr) * 60]
        logmsg.update("OWW interval updated to " + str(self.setup.intervals["oww"]))

        # and now modify valve ignore time
        tmr = weather.interval_scale(temp, (0.0, 35.0), (1.7, 3.0), (15, 120), False)
        self.var.ignore_time = self.setup.window_ignore_time + tmr
        bridge.put("ign_op", self.var.ignore_time)
        logmsg.update("Valve ignore interval updated to " + str(self.var.ignore_time), 'D')
Exemplo n.º 12
0
    def update_counters(self, heat_start):
        # save the date
        nw = datetime.datetime.date(datetime.datetime.now()).strftime("%d-%m-%Y")
        tm = time.time()
        support.call_home("applive")
        # is there a key for today?
        # logmsg.debug("ht=", self.var.ht, ", heat_start=", heat_start)
        if nw in self.var.ht:
            if heat_start:
                self.var.ht[nw][1] = tm
            elif self.var.heating:
                daily_heat_sum = int(self.var.ht[nw][0] + (tm - self.var.ht[nw][1]))
                logmsg.debug("Daily heat sum=", daily_heat_sum)
                self.var.ht[nw] = [daily_heat_sum, time.time()]
                bridge.put("ht", self.var.ht)
                logmsg.update("Daily heat counter updated to " + str(datetime.timedelta(seconds=daily_heat_sum)))
        else:
            if len(self.var.ht) > 0:
                # if there a key, this must be old key(s)
                # save the old date, and flush values into log
                for k in self.var.ht.keys():
                    v = self.var.ht[k]
                    logmsg.update(str(k) + " daily heating summary: " + str(datetime.timedelta(seconds=v[0])), 'I')
                    logmsg.update("Deleting old daily key: " + str(k), 'D')
                    del self.var.ht[k]
                self.export_csv("close")

            # create the new key
            self.var.ht.update({nw: [0, time.time()]})
            logmsg.update("Creating new daily key: " + str(nw) + "=" + str(self.var.ht[nw]))
            # so its a new day, update other values
            self.export_csv("init")
            # day readings warning, take number of heated readings and divide by 2
            drw = self.var.heat_readings / 2
            logmsg.update("Day reading warnings value=" + str(drw))
            for k, v in self.var.dev_log.iteritems():
                logmsg.update("Valve: " + str(k) + " has value " + str(v[0]))
                if v[0] > drw:
                    logmsg.update("Valve: " + str(k) +
                                  " reports during heating too many same % positions, e.g. " +
                                  str(v[0]) + " per " + str(drw))
                self.var.dev_log[k][0] = 0
            self.var.heat_readings = 0
            bridge.save(self.setup.bridge_file)
        bridge.put("ht", self.var.ht)
Exemplo n.º 13
0
    def update_counters(self, heat_start):
        # save the date
        nw = datetime.datetime.date(datetime.datetime.now()).strftime("%d-%m-%Y")
        tm = time.time()

        # update total heat counter
        if self.var.heating:
            tmp = self.var.ht["total"][0]
            tmp += int(time.time() - self.var.ht["total"][1])
            bridge.put("ht", self.var.ht)
            bridge.put("htstr", datetime.timedelta(seconds=tmp))
            logmsg.update("Total heat counter updated to " + str(datetime.timedelta(seconds=tmp)))
            self.var.ht["total"][0] = tmp
            self.var.ht["total"][1] = time.time()

        # is there a key for today?
        if nw in self.var.ht:
            if heat_start:
                self.var.ht[nw][1] = tm
            elif self.var.heating:
                totalheat = int(self.var.ht[nw][0] + (tm - self.var.ht[nw][1]))
                self.var.ht[nw] = [totalheat, time.time()]
                bridge.put("ht", self.var.ht)
                bridge.put("daily", datetime.timedelta(seconds=totalheat))
        else:
            if len(self.var.ht) > 1:
                # if there a key, this must be old key(s)
                # save the old date, and flush values into log
                for k in self.var.ht.keys():
                    v = self.var.ht[k]
                    if not k == "total":
                        logmsg.update(str(k) + " heating daily summary: " + str(datetime.timedelta(seconds=v[0])), 'I')
                        logmsg.update("Deleting old daily key: " + str(k), 'D')
                        del self.var.ht[k]
                # and close CSV file
                self.export_csv("close")
            # create the new key
            logmsg.update("Creating new daily key: " + str(nw))
            self.var.ht.update({nw: [0, time.time()]})
            # so its a new day, update other values
            self.export_csv("init")
            # day readings warning, take number of heated readings and divide by 2
            drw = self.var.heatReadings / 2
            logmsg.update("Day reading warnings value=" + str(drw))
            for k, v in self.var.dev_log.iteritems():
                logmsg.update("Valve: " + str(k) + " has value " + str(v[0]))
                if v[0] > drw:
                    logmsg.update("Valve: " + str(k) +
                                  " reports during heating too many same % positions, e.g. " +
                                  str(v[0]) + " per " + str(drw))
                self.var.dev_log[k][0] = 0
            self.var.heatReadings = 0
            bridge.save(self.setup.bridgefile)
Exemplo n.º 14
0
    def update_ignores_2sit(self):
        """
        Update open window variables according to weather
        :return: nothing
        """
        self.var.situation = weather.weather_for_woeid(self.setup.yahoo_location, self.setup.owm_location,
                                                       self.setup.owm_api_key)
        if None not in self.var.situation.viewvalues():
            temp = int(self.var.situation["current_temp"])
            if temp is not None:
                # modify OWW
                # interval for oww 5min to 360min
                tmr = weather.interval_scale(temp, (-35.0, 35.0), (0, 10), (5, 360), True)
                self.setup.intervals["oww"] = [tmr * 60, (3 * tmr) * 60, (3 * tmr) * 60]
                logmsg.update("OWW interval updated to " + str(self.setup.intervals["oww"]))

                # and now modify valve ignore time
                # interval for valve ignore 20min to 120min
                tmr = weather.interval_scale(temp, (0.0, 35.0), (1.7, 3.0), (20, 120), False)
                self.eq3.ignore_time = self.setup.window_ignore_time + tmr
                bridge.put("ign_op", self.eq3.ignore_time)
                logmsg.update("Valve ignore interval updated to " + str(self.eq3.ignore_time), 'D')
Exemplo n.º 15
0
 def process_msg(self):
     """
     Process message queue
     :return: nothing
     """
     while len(self.var.msgQ) > 0:
         logmsg.update("Message queue: " + str(self.var.msgQ), 'D')
         wait_cycle = False
         if support.is_yun():
             # this is waiting routine to ensure that msg queue is processed by 32u4 part
             tmp_br = bridge.get("msg")
             if not support.is_empty(tmp_br):
                 time.sleep(self.setup.timeout)
                 wait_cycle = True
         if not wait_cycle:
             to_send = self.var.msgQ.pop()
             logmsg.update("Sending message [" + str(to_send) + "]", 'D')
             # if we are going to reset, save bridge file
             if to_send == "R":
                 bridge.save(self.setup.bridge_file)
             if support.is_yun():
                 # signal to 32u4 that we have something to process
                 bridge.put("msg", to_send)
             elif support.is_rpi():
                 if to_send == "H":
                     # TBI RPI
                     # uncomment line below for RPi
                     # action.do(True)
                     pass
                 elif to_send == "S":
                     # TBI RPI
                     # uncomment line below for RPi
                     # action.do(False)
                     pass
             elif support.is_win():
                 # insert windows code here
                 # print "nt"
                 logmsg.update("Processing message on Windows: " +
                               str(to_send))
Exemplo n.º 16
0
 def process_msg(self):
     """
     Process message queue
     :return: nothing
     """
     while len(self.var.msgQ) > 0:
         logmsg.update("Message queue: " + str(self.var.msgQ), 'D')
         wait_cycle = False
         if support.is_yun():
             # this is waiting routine to ensure that msg queue is processed by 32u4 part
             tmp_br = bridge.get("msg")
             if not support.is_empty(tmp_br):
                 time.sleep(self.setup.timeout)
                 wait_cycle = True
         if not wait_cycle:
             to_send = self.var.msgQ.pop()
             logmsg.update("Sending message [" + str(to_send) + "]", 'D')
             # if we are going to reset, save bridge file
             if to_send == "R":
                 bridge.save(self.setup.bridge_file)
             if support.is_yun():
                 # signal to 32u4 that we have something to process
                 bridge.put("msg", to_send)
             elif support.is_rpi():
                 if to_send == "H":
                     # TBI RPI
                     # uncomment line below for RPi
                     # action.do(True)
                     pass
                 elif to_send == "S":
                     # TBI RPI
                     # uncomment line below for RPi
                     # action.do(False)
                     pass
             elif support.is_win():
                 # insert windows code here
                 # print "nt"
                 logmsg.update("Processing message on Windows: " + str(to_send))
Exemplo n.º 17
0
    def process_windows(self, ow):
        """
        Process dictionary and set ventilation status, then update owl web file
        :param ow: dictionary, open windows
        :return: nothing
        """
        # if count of open windows >= number of windows, that mean ventilation
        if len(ow) >= self.setup.ventilate_num:
            self.var.ventilating = True
        else:
            self.var.ventilating = False

        # write second web file

        secweb.write("owl", ow)
        # write bridge value
        bridge.put("owl", ow)
        # if open window warning is on and open window(s) count < number of open windows, that mean ventilation
        # send warnings for these windows
        if not self.setup.no_oww and len(ow) < self.setup.ventilate_num:
            for k, v in ow.iteritems():
                if self._is_win_open_too_long(k):
                    logmsg.update("Warning condition for window " + str(k) + " met")
                    self.send_warning("window", k, "")
Exemplo n.º 18
0
    def write_strings(self):
        """ construct and write CSV data, Log debug string and current status string """
        log_str = bridge.try_read("status", False) + ", "
        if self.setup.preference == "per":
            log_str += str(self.setup.valve_switch) + "%" + " at " + str(self.setup.valve_num) + " valve(s)."
        elif self.setup.preference == "total":
            log_str += "total value of " + str(self.setup.total_switch) + "."
        log_str += "\n"

        csvfile.write(time.strftime("%d/%m/%Y %H:%M:%S", time.localtime()),
                      1 if self.var.heating else 0, 1 if self.var.ventilating else 0)
        csvfile.write(self.eq3.csv())
        csvfile.write("\n")

        # second web
        # JSON formatted status
        json_status = self.eq3.json_status()
        secweb.write("status", json_status)
        # and bridge variable
        bridge.put("sys", json_status)
        # nice text web
        secweb.nice(log_str + self.eq3.plain())
        # readiness for dashboard
        bridge.save(secweb.sw.location["bridge"])
Exemplo n.º 19
0
 def update(self, status_key):
     """
     Update status string
     :param status_key: string, key in status_str
     :return: nothing
     """
     if status_key not in self.status_str:
         key_error_str = "Key error"
         bridge.put("status", key_error_str)
         self.actual = key_error_str
     else:
         bridge.put("status", self.status_str[status_key])
         bridge.put("status_key", status_key)
         self.actual = self.status_str[status_key]
Exemplo n.º 20
0
 def update_uptime(self):
     tmp = time.time()
     bridge.put("uptime", support.get_uptime())
     bridge.put(
         "appuptime",
         datetime.timedelta(seconds=int(tmp - self.var.appStartTime)))
Exemplo n.º 21
0
 def update_uptime(self):
     tmp = time.time()
     bridge.put("uptime", self._get_uptime())
     bridge.put("appuptime", datetime.timedelta(seconds=int(tmp - self.var.appStartTime)))
Exemplo n.º 22
0
 def set_bridge_control_values(self):
     """ set control values to bridge """
     bridge.put("pref", self.setup.preference)
     bridge.put("valve", self.setup.valve_switch)
     bridge.put("svpnmw", self.setup.svpnmw)
     bridge.put("total", self.setup.total_switch)
     bridge.put("int", self.setup.intervals["max"][0])
     bridge.put("valves", self.setup.valve_num)
     bridge.put("au", self.setup.au)
     bridge.put("ign_op", self.eq3.ignore_time)
     bridge.put("no_oww", self.setup.no_oww)
     bridge.put("ht", self.var.ht)
     bridge.put("ign", self.eq3.ignored_valves)
Exemplo n.º 23
0
 def update(self, statmsg):
     bridge.put("status", self.statusMsg[statmsg])
     self.actual = self.statusMsg[statmsg]
Exemplo n.º 24
0
 def set_bridge_control_values(self):
     """ set control values to bridge """
     bridge.put("pref", self.setup.preference)
     bridge.put("valve", self.setup.valve_switch)
     bridge.put("svpnmw", self.setup.svpnmw)
     bridge.put("total", self.setup.total_switch)
     bridge.put("int", self.setup.intervals["max"][0])
     bridge.put("valves", self.setup.valve_num)
     bridge.put("au", self.setup.au)
     bridge.put("ign_op", self.eq3.ignore_time)
     bridge.put("no_oww", self.setup.no_oww)
     bridge.put("ht", self.var.ht)
     bridge.put("ign", self.eq3.ignored_valves)