async def test_heater_switch(hass, setup_comp_1): """Test heater switching test switch.""" platform = loader.get_component(hass, 'switch.test') platform.init() switch_1 = platform.DEVICES[1] assert await async_setup_component(hass, switch.DOMAIN, {'switch': { 'platform': 'test' }}) heater_switch = switch_1.entity_id assert await async_setup_component( hass, DOMAIN, { 'climate': { 'platform': 'generic_thermostat', 'name': 'test', 'heater': heater_switch, 'target_sensor': ENT_SENSOR } }) assert STATE_OFF == \ hass.states.get(heater_switch).state _setup_sensor(hass, 18) await hass.async_block_till_done() common.async_set_temperature(hass, 23) await hass.async_block_till_done() assert STATE_ON == \ hass.states.get(heater_switch).state
async def test_heater_input_boolean(hass, setup_comp_1): """Test heater switching input_boolean.""" heater_switch = 'input_boolean.test' assert await async_setup_component(hass, input_boolean.DOMAIN, {'input_boolean': { 'test': None }}) assert await async_setup_component( hass, DOMAIN, { 'climate': { 'platform': 'generic_thermostat', 'name': 'test', 'heater': heater_switch, 'target_sensor': ENT_SENSOR } }) assert STATE_OFF == \ hass.states.get(heater_switch).state _setup_sensor(hass, 18) await hass.async_block_till_done() common.async_set_temperature(hass, 23) await hass.async_block_till_done() assert STATE_ON == \ hass.states.get(heater_switch).state
async def test_heater_switch(hass, setup_comp_1): """Test heater switching test switch.""" platform = loader.get_component(hass, 'switch.test') platform.init() switch_1 = platform.DEVICES[1] assert await async_setup_component(hass, switch.DOMAIN, {'switch': { 'platform': 'test'}}) heater_switch = switch_1.entity_id assert await async_setup_component(hass, climate.DOMAIN, {'climate': { 'platform': 'generic_thermostat', 'name': 'test', 'heater': heater_switch, 'target_sensor': ENT_SENSOR }}) assert STATE_OFF == \ hass.states.get(heater_switch).state _setup_sensor(hass, 18) await hass.async_block_till_done() common.async_set_temperature(hass, 23) await hass.async_block_till_done() assert STATE_ON == \ hass.states.get(heater_switch).state
async def test_temp_change_ac_on_within_tolerance(hass, setup_comp_3): """Test if temperature change doesn't turn ac on within tolerance.""" calls = _setup_switch(hass, False) common.async_set_temperature(hass, 25) await hass.async_block_till_done() _setup_sensor(hass, 25.2) await hass.async_block_till_done() assert 0 == len(calls)
async def test_temp_change_heater_off_within_tolerance(hass, setup_comp_2): """Test if temperature change doesn't turn off within tolerance.""" calls = _setup_switch(hass, True) common.async_set_temperature(hass, 30) await hass.async_block_till_done() _setup_sensor(hass, 33) await hass.async_block_till_done() assert 0 == len(calls)
async def test_set_away_mode(hass, setup_comp_2): """Test the setting away mode.""" common.async_set_temperature(hass, 23) await hass.async_block_till_done() common.async_set_away_mode(hass, True) await hass.async_block_till_done() state = hass.states.get(ENTITY) assert 16 == state.attributes.get('temperature')
async def test_temp_change_ac_trigger_on_not_long_enough_2(hass, setup_comp_5): """Test if temperature change turn ac on.""" calls = _setup_switch(hass, False) common.async_set_temperature(hass, 25) await hass.async_block_till_done() _setup_sensor(hass, 30) await hass.async_block_till_done() assert 0 == len(calls)
async def test_temp_change_heater_trigger_on_not_long_enough( hass, setup_comp_6): """Test if temp change doesn't turn heater on because of time.""" calls = _setup_switch(hass, False) common.async_set_temperature(hass, 30) await hass.async_block_till_done() _setup_sensor(hass, 25) await hass.async_block_till_done() assert 0 == len(calls)
async def test_precision(hass, setup_comp_10): """Test that setting precision to tenths works as intended.""" common.async_set_operation_mode(hass, STATE_OFF) await hass.async_block_till_done() await hass.services.async_call('climate', SERVICE_TURN_OFF) await hass.async_block_till_done() common.async_set_temperature(hass, 23.27) await hass.async_block_till_done() state = hass.states.get(ENTITY) assert 23.3 == state.attributes.get('temperature')
async def test_set_target_temp(hass, setup_comp_2): """Test the setting of the target temperature.""" common.async_set_temperature(hass, 30) await hass.async_block_till_done() state = hass.states.get(ENTITY) assert 30.0 == state.attributes.get('temperature') common.async_set_temperature(hass, None) await hass.async_block_till_done() state = hass.states.get(ENTITY) assert 30.0 == state.attributes.get('temperature')
async def test_no_state_change_when_operation_mode_off_2(hass, setup_comp_3): """Test that the switch doesn't turn on when enabled is False.""" calls = _setup_switch(hass, False) common.async_set_temperature(hass, 30) await hass.async_block_till_done() common.async_set_operation_mode(hass, STATE_OFF) await hass.async_block_till_done() _setup_sensor(hass, 35) await hass.async_block_till_done() assert 0 == len(calls)
async def test_turn_away_mode_on_cooling(hass, setup_comp_3): """Test the setting away mode when cooling.""" _setup_sensor(hass, 25) await hass.async_block_till_done() common.async_set_temperature(hass, 19) await hass.async_block_till_done() common.async_set_away_mode(hass, True) await hass.async_block_till_done() state = hass.states.get(ENTITY) assert 30 == state.attributes.get('temperature')
async def test_set_target_temp_ac_off(hass, setup_comp_3): """Test if target temperature turn ac off.""" calls = _setup_switch(hass, True) _setup_sensor(hass, 25) await hass.async_block_till_done() common.async_set_temperature(hass, 30) await hass.async_block_till_done() assert 2 == len(calls) call = calls[0] assert HASS_DOMAIN == call.domain assert SERVICE_TURN_OFF == call.service assert ENT_SWITCH == call.data['entity_id']
async def test_running_when_operating_mode_is_off_2(hass, setup_comp_3): """Test that the switch turns off when enabled is set False.""" calls = _setup_switch(hass, True) common.async_set_temperature(hass, 30) await hass.async_block_till_done() common.async_set_operation_mode(hass, STATE_OFF) await hass.async_block_till_done() assert 1 == len(calls) call = calls[0] assert HASS_DOMAIN == call.domain assert SERVICE_TURN_OFF == call.service assert ENT_SWITCH == call.data['entity_id']
async def test_set_target_temp_heater_on(hass, setup_comp_2): """Test if target temperature turn heater on.""" calls = _setup_switch(hass, False) _setup_sensor(hass, 25) await hass.async_block_till_done() common.async_set_temperature(hass, 30) await hass.async_block_till_done() assert 1 == len(calls) call = calls[0] assert HASS_DOMAIN == call.domain assert SERVICE_TURN_ON == call.service assert ENT_SWITCH == call.data['entity_id']
async def test_temp_change_heater_off_outside_tolerance(hass, setup_comp_2): """Test if temperature change turn heater off outside hot tolerance.""" calls = _setup_switch(hass, True) common.async_set_temperature(hass, 30) await hass.async_block_till_done() _setup_sensor(hass, 35) await hass.async_block_till_done() assert 1 == len(calls) call = calls[0] assert HASS_DOMAIN == call.domain assert SERVICE_TURN_OFF == call.service assert ENT_SWITCH == call.data['entity_id']
async def test_temp_change_ac_on_outside_tolerance(hass, setup_comp_3): """Test if temperature change turn ac on.""" calls = _setup_switch(hass, False) common.async_set_temperature(hass, 25) await hass.async_block_till_done() _setup_sensor(hass, 30) await hass.async_block_till_done() assert 1 == len(calls) call = calls[0] assert HASS_DOMAIN == call.domain assert SERVICE_TURN_ON == call.service assert ENT_SWITCH == call.data['entity_id']
async def test_set_away_mode_and_restore_prev_temp(hass, setup_comp_2): """Test the setting and removing away mode. Verify original temperature is restored. """ common.async_set_temperature(hass, 23) await hass.async_block_till_done() common.async_set_away_mode(hass, True) await hass.async_block_till_done() state = hass.states.get(ENTITY) assert 16 == state.attributes.get('temperature') common.async_set_away_mode(hass, False) await hass.async_block_till_done() state = hass.states.get(ENTITY) assert 23 == state.attributes.get('temperature')
async def test_mode_change_ac_trigger_on_not_long_enough_2(hass, setup_comp_5): """Test if mode change turns ac on despite minimum cycle.""" calls = _setup_switch(hass, False) common.async_set_temperature(hass, 25) await hass.async_block_till_done() _setup_sensor(hass, 30) await hass.async_block_till_done() assert 0 == len(calls) common.async_set_operation_mode(hass, climate.STATE_HEAT) await hass.async_block_till_done() assert 1 == len(calls) call = calls[0] assert 'homeassistant' == call.domain assert SERVICE_TURN_ON == call.service assert ENT_SWITCH == call.data['entity_id']
async def test_mode_change_ac_trigger_on_not_long_enough_2(hass, setup_comp_5): """Test if mode change turns ac on despite minimum cycle.""" calls = _setup_switch(hass, False) common.async_set_temperature(hass, 25) await hass.async_block_till_done() _setup_sensor(hass, 30) await hass.async_block_till_done() assert 0 == len(calls) common.async_set_operation_mode(hass, STATE_HEAT) await hass.async_block_till_done() assert 1 == len(calls) call = calls[0] assert 'homeassistant' == call.domain assert SERVICE_TURN_ON == call.service assert ENT_SWITCH == call.data['entity_id']
async def test_temp_change_heater_trigger_off_long_enough(hass, setup_comp_6): """Test if temperature change turn heater off after min cycle.""" fake_changed = datetime.datetime(1918, 11, 11, 11, 11, 11, tzinfo=datetime.timezone.utc) with mock.patch('homeassistant.helpers.condition.dt_util.utcnow', return_value=fake_changed): calls = _setup_switch(hass, True) common.async_set_temperature(hass, 25) await hass.async_block_till_done() _setup_sensor(hass, 30) await hass.async_block_till_done() assert 1 == len(calls) call = calls[0] assert HASS_DOMAIN == call.domain assert SERVICE_TURN_OFF == call.service assert ENT_SWITCH == call.data['entity_id']
async def test_mode_change_heater_trigger_off_not_long_enough( hass, setup_comp_6): """Test if mode change turns heater off despite minimum cycle.""" calls = _setup_switch(hass, True) common.async_set_temperature(hass, 25) await hass.async_block_till_done() _setup_sensor(hass, 30) await hass.async_block_till_done() assert 0 == len(calls) common.async_set_operation_mode(hass, climate.STATE_OFF) await hass.async_block_till_done() assert 1 == len(calls) call = calls[0] assert 'homeassistant' == call.domain assert SERVICE_TURN_OFF == call.service assert ENT_SWITCH == call.data['entity_id']
async def test_mode_change_heater_trigger_off_not_long_enough( hass, setup_comp_6): """Test if mode change turns heater off despite minimum cycle.""" calls = _setup_switch(hass, True) common.async_set_temperature(hass, 25) await hass.async_block_till_done() _setup_sensor(hass, 30) await hass.async_block_till_done() assert 0 == len(calls) common.async_set_operation_mode(hass, STATE_OFF) await hass.async_block_till_done() assert 1 == len(calls) call = calls[0] assert 'homeassistant' == call.domain assert SERVICE_TURN_OFF == call.service assert ENT_SWITCH == call.data['entity_id']
async def test_operating_mode_cool(hass, setup_comp_3): """Test change mode from OFF to COOL. Switch turns on when temp below setpoint and mode changes. """ common.async_set_operation_mode(hass, STATE_OFF) common.async_set_temperature(hass, 25) _setup_sensor(hass, 30) await hass.async_block_till_done() calls = _setup_switch(hass, False) common.async_set_operation_mode(hass, climate.STATE_COOL) await hass.async_block_till_done() assert 1 == len(calls) call = calls[0] assert HASS_DOMAIN == call.domain assert SERVICE_TURN_ON == call.service assert ENT_SWITCH == call.data['entity_id']
async def test_operating_mode_cool(hass, setup_comp_3): """Test change mode from OFF to COOL. Switch turns on when temp below setpoint and mode changes. """ common.async_set_operation_mode(hass, STATE_OFF) common.async_set_temperature(hass, 25) _setup_sensor(hass, 30) await hass.async_block_till_done() calls = _setup_switch(hass, False) common.async_set_operation_mode(hass, STATE_COOL) await hass.async_block_till_done() assert 1 == len(calls) call = calls[0] assert HASS_DOMAIN == call.domain assert SERVICE_TURN_ON == call.service assert ENT_SWITCH == call.data['entity_id']
async def test_temp_change_heater_trigger_on_long_enough_2(hass, setup_comp_8): """Test if turn on signal is sent at keep-alive intervals.""" calls = _setup_switch(hass, True) await hass.async_block_till_done() _setup_sensor(hass, 20) await hass.async_block_till_done() common.async_set_temperature(hass, 25) await hass.async_block_till_done() test_time = datetime.datetime.now(pytz.UTC) _send_time_changed(hass, test_time) await hass.async_block_till_done() assert 0 == len(calls) _send_time_changed(hass, test_time + datetime.timedelta(minutes=5)) await hass.async_block_till_done() assert 0 == len(calls) _send_time_changed(hass, test_time + datetime.timedelta(minutes=10)) await hass.async_block_till_done() assert 1 == len(calls) call = calls[0] assert HASS_DOMAIN == call.domain assert SERVICE_TURN_ON == call.service assert ENT_SWITCH == call.data['entity_id']
async def test_heater_input_boolean(hass, setup_comp_1): """Test heater switching input_boolean.""" heater_switch = 'input_boolean.test' assert await async_setup_component(hass, input_boolean.DOMAIN, { 'input_boolean': {'test': None}}) assert await async_setup_component(hass, climate.DOMAIN, {'climate': { 'platform': 'generic_thermostat', 'name': 'test', 'heater': heater_switch, 'target_sensor': ENT_SENSOR }}) assert STATE_OFF == \ hass.states.get(heater_switch).state _setup_sensor(hass, 18) await hass.async_block_till_done() common.async_set_temperature(hass, 23) await hass.async_block_till_done() assert STATE_ON == \ hass.states.get(heater_switch).state