def __init__(self, log): self._log = log self._log.debug('Inizializzazione switch') self.time_init = epoch_timestamp() self.time_day = second_since_midnight() self.swc = SwitcherCom(log) self.actual_state = SwitcherCom.state_unknow
def _update_timers(self, state): if state == self.actual_state: return delta = epoch_timestamp() - self.time_init self.time_tot += delta self.time_day += delta self._log.debug("Aggiorno contatori: stato %s, delta %s" % (state, delta)) if self.actual_state == SwitcherCom.state_on: self.time_on += delta elif self.actual_state == SwitcherCom.state_off: self.time_off += delta elif self.actual_state == SwitcherCom.state_unknow: self.time_err += delta self.actual_state = state # Log al cambio di giorno mid_sec = second_since_midnight() if self.time_day > mid_sec: self._log.debug("Riepilogo timer giornaliero") self._log.info( "Sistema Accesso per %s" % (second_to_time(self.time_on)) ) self._log.info( "Sistema spento per %s sec" % (second_to_time(self.time_off)) ) self._log.warning( "Sistema in stato indeterminato per %s" % (second_to_time(self.time_err)) ) self.time_day = mid_sec