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 set_system_state(to_state, current_state): if to_state == state.UNKNOWN: LOG.error( 'Trying to set system status UNKNOWN.... Uncool... bailing. Current state: %s', state.print_state(current_state)) return def _set_system_state(s): LOG.info('Setting system mode: %s', state.print_state(s)) if s == state.HEAT: _heat_on() elif s == state.COOL: _cool_on() elif s == state.FAN_ONLY: _fan_only() elif s == state.OFF: _off() # Verify that the system state was set currently threading._sleep(1) cs, _ = get_system_state() if s != cs: LOG.error( 'The system state was not set correctly! Expected state: %s, Actual state: %s', state.print_state(s), state.print_state(cs)) def _heat_on(): LOG.debug('Setting system mode to HEAT') _set_outputs(green=True, white=True) def _cool_on(): LOG.debug('Setting system mode to COOL') _set_outputs(green=True, white=True, yellow=True) def _fan_only(): LOG.debug('Setting system mode to FAN ONLY') _set_outputs(green=True) def _off(): LOG.debug('Setting system mode to OFF') _set_outputs() def _set_outputs(green=False, white=False, yellow=False): LOG.debug('Setting GREEN out pin to %s', 'ON' if green else 'OFF') GPIO.output(CONF.io.green_pin_out, green) LOG.debug('Setting WHITE out pin to %s', 'ON' if white else 'OFF') GPIO.output(CONF.io.white_pin_out, white) LOG.debug('Setting YELLOW out pin to %s', 'ON' if yellow else 'OFF') GPIO.output(CONF.io.yellow_pin_out, yellow) if current_state in [state.OFF, state.FAN_ONLY]: _set_system_state(to_state) else: # First set the system to fan only to let the system cool down for 2 minutes, then set the system state _set_system_state(state.FAN_ONLY) threading._sleep(CONF.hvac.on_mode_change_fan_interval) _set_system_state(to_state)
def __init__(self): LOG.debug('Display type: %s', CONF.display.type) self._format = CONF.display.default_format self._display = self._get_display() self._data = dict(mode=states.print_state(states.UNKNOWN), temp_f=0, temp_c=0)
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 _set_system_state(s): LOG.info('Setting system mode: %s', state.print_state(s)) if s == state.HEAT: _heat_on() elif s == state.COOL: _cool_on() elif s == state.FAN_ONLY: _fan_only() elif s == state.OFF: _off() # Verify that the system state was set currently threading._sleep(1) cs, _ = get_system_state() if s != cs: LOG.error('The system state was not set correctly! Expected state: %s, Actual state: %s', state.print_state(s), state.print_state(cs))
def _set_system_state(s): LOG.info('Setting system mode: %s', state.print_state(s)) if s == state.HEAT: _heat_on() elif s == state.COOL: _cool_on() elif s == state.FAN_ONLY: _fan_only() elif s == state.OFF: _off() # Verify that the system state was set currently threading._sleep(1) cs, _ = get_system_state() if s != cs: LOG.error( 'The system state was not set correctly! Expected state: %s, Actual state: %s', state.print_state(s), state.print_state(cs))
def set_system_state(to_state, current_state): if to_state == state.UNKNOWN: LOG.error('Trying to set system status UNKNOWN.... Uncool... bailing. Current state: %s', state.print_state(current_state)) return def _set_system_state(s): LOG.info('Setting system mode: %s', state.print_state(s)) if s == state.HEAT: _heat_on() elif s == state.COOL: _cool_on() elif s == state.FAN_ONLY: _fan_only() elif s == state.OFF: _off() # Verify that the system state was set currently threading._sleep(1) cs, _ = get_system_state() if s != cs: LOG.error('The system state was not set correctly! Expected state: %s, Actual state: %s', state.print_state(s), state.print_state(cs)) def _heat_on(): LOG.debug('Setting system mode to HEAT') _set_outputs(green=True, white=True) def _cool_on(): LOG.debug('Setting system mode to COOL') _set_outputs(green=True, white=True, yellow=True) def _fan_only(): LOG.debug('Setting system mode to FAN ONLY') _set_outputs(green=True) def _off(): LOG.debug('Setting system mode to OFF') _set_outputs() def _set_outputs(green=False, white=False, yellow=False): LOG.debug('Setting GREEN out pin to %s', 'ON' if green else 'OFF') GPIO.output(CONF.io.green_pin_out, green) LOG.debug('Setting WHITE out pin to %s', 'ON' if white else 'OFF') GPIO.output(CONF.io.white_pin_out, white) LOG.debug('Setting YELLOW out pin to %s', 'ON' if yellow else 'OFF') GPIO.output(CONF.io.yellow_pin_out, yellow) if current_state in [state.OFF, state.FAN_ONLY]: _set_system_state(to_state) else: # First set the system to fan only to let the system cool down for 2 minutes, then set the system state _set_system_state(state.FAN_ONLY) threading._sleep(CONF.hvac.on_mode_change_fan_interval) _set_system_state(to_state)
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')