def close(self): LOG.info('Stopping Program Manager') self.is_active = False while self.is_running: hub.sleep(1) current_state, _ = hvac.get_system_state() if current_state != states.OFF: hvac.set_system_state(states.OFF, current_state)
def get(self): rs, es = hvac.get_system_state() curr_temp = temp.get_current_temp() mode = sys_mode_factory.get_system_mode() data = dict(system_state=states.print_state(rs), expected_program_state=states.print_state(mode.get_state(curr_temp)), current_temp=curr_temp, system_mode=mode.to_dict()) if rs != es: data['error'] = True data['error_message'] = 'Current system state \'%s\' does not match expected system state \'%s\'' % \ (states.print_state(rs), states.print_state(es)) return data
def get(self): rs, es = hvac.get_system_state() curr_temp = temp.get_current_temp() mode = sys_mode_factory.get_system_mode() data = dict(system_state=states.print_state(rs), expected_program_state=states.print_state( mode.get_state(curr_temp)), current_temp=curr_temp, system_mode=mode.to_dict()) if rs != es: data['error'] = True data['error_message'] = 'Current system state \'%s\' does not match expected system state \'%s\'' % \ (states.print_state(rs), states.print_state(es)) return data
def run(self): try: LOG.debug('Running program interval...') current_state, _ = hvac.get_system_state() LOG.info('Current state: %s', states.print_state(current_state)) current_temp = temp.get_current_temp() if not current_temp: LOG.error( 'Bailing out of current progam run... No temp data found. Setting system state to OFF' ) hvac.set_system_state(states.OFF, current_state) return current_temp_c = (current_temp - 32) * 5.0 / 9.0 LOG.info('Current temp: %s', current_temp) mode = sys_mode_fac.get_system_mode() LOG.info('System mode: %s. Running program: %s', mode.name(), mode.program_name()) expected_state = mode.get_state(current_temp) LOG.debug('Expected state: %s', states.print_state(expected_state)) if current_state != expected_state: LOG.info('Setting system state to: %s', states.print_state(expected_state)) hvac.set_system_state(expected_state, current_state) else: LOG.debug( 'Seems like the system is already in the expected state, so I ain\'t gonna do crap!' ) display.update(mode=states.print_state(expected_state), program=mode.program_name(), temp_f=current_temp, temp_c=current_temp_c) except Exception: LOG.exception('CRAP!!!! Stuff happened')