def test_released_event(self): """Test handling an event from LiteJet.""" # Initial state is on. self.switch_pressed_callbacks[ENTITY_OTHER_SWITCH_NUMBER]() self.hass.block_till_done() assert switch.is_on(self.hass, ENTITY_OTHER_SWITCH) # Event indicates it is off now. self.switch_released_callbacks[ENTITY_OTHER_SWITCH_NUMBER]() self.hass.block_till_done() assert not switch.is_on(self.hass, ENTITY_OTHER_SWITCH) assert not switch.is_on(self.hass, ENTITY_SWITCH) assert self.other_switch().state == 'off' assert self.switch().state == 'off'
def test_released_event(self): """Test handling an event from LiteJet.""" # Initial state is on. self.switch_pressed_callbacks[ENTITY_OTHER_SWITCH_NUMBER]() self.hass.block_till_done() assert switch.is_on(self.hass, ENTITY_OTHER_SWITCH) # Event indicates it is off now. self.switch_released_callbacks[ENTITY_OTHER_SWITCH_NUMBER]() self.hass.block_till_done() assert not switch.is_on(self.hass, ENTITY_OTHER_SWITCH) assert not switch.is_on(self.hass, ENTITY_SWITCH) assert self.other_switch().state == "off" assert self.switch().state == "off"
async def test_released_event(hass, mock_litejet): """Test handling an event from LiteJet.""" await async_init_integration(hass, use_switch=True) # Initial state is on. mock_litejet.switch_pressed_callbacks[ENTITY_OTHER_SWITCH_NUMBER]() await hass.async_block_till_done() assert switch.is_on(hass, ENTITY_OTHER_SWITCH) # Event indicates it is off now. mock_litejet.switch_released_callbacks[ENTITY_OTHER_SWITCH_NUMBER]() await hass.async_block_till_done() assert not switch.is_on(hass, ENTITY_OTHER_SWITCH) assert not switch.is_on(hass, ENTITY_SWITCH) assert hass.states.get(ENTITY_SWITCH).state == "off" assert hass.states.get(ENTITY_OTHER_SWITCH).state == "off"
def test_pressed_event(self): """Test handling an event from LiteJet.""" # Switch 1 _LOGGER.info(self.switch_pressed_callbacks[ENTITY_SWITCH_NUMBER]) self.switch_pressed_callbacks[ENTITY_SWITCH_NUMBER]() self.hass.block_till_done() assert switch.is_on(self.hass, ENTITY_SWITCH) assert not switch.is_on(self.hass, ENTITY_OTHER_SWITCH) assert self.switch().state == "on" assert self.other_switch().state == "off" # Switch 2 self.switch_pressed_callbacks[ENTITY_OTHER_SWITCH_NUMBER]() self.hass.block_till_done() assert switch.is_on(self.hass, ENTITY_OTHER_SWITCH) assert switch.is_on(self.hass, ENTITY_SWITCH) assert self.other_switch().state == "on" assert self.switch().state == "on"
def test_pressed_event(self): """Test handling an event from LiteJet.""" # Switch 1 _LOGGER.info(self.switch_pressed_callbacks[ENTITY_SWITCH_NUMBER]) self.switch_pressed_callbacks[ENTITY_SWITCH_NUMBER]() self.hass.block_till_done() assert switch.is_on(self.hass, ENTITY_SWITCH) assert not switch.is_on(self.hass, ENTITY_OTHER_SWITCH) assert self.switch().state == 'on' assert self.other_switch().state == 'off' # Switch 2 self.switch_pressed_callbacks[ENTITY_OTHER_SWITCH_NUMBER]() self.hass.block_till_done() assert switch.is_on(self.hass, ENTITY_OTHER_SWITCH) assert switch.is_on(self.hass, ENTITY_SWITCH) assert self.other_switch().state == 'on' assert self.switch().state == 'on'
async def test_pressed_event(hass, mock_litejet): """Test handling an event from LiteJet.""" await async_init_integration(hass, use_switch=True) # Switch 1 mock_litejet.switch_pressed_callbacks[ENTITY_SWITCH_NUMBER]() await hass.async_block_till_done() assert switch.is_on(hass, ENTITY_SWITCH) assert not switch.is_on(hass, ENTITY_OTHER_SWITCH) assert hass.states.get(ENTITY_SWITCH).state == "on" assert hass.states.get(ENTITY_OTHER_SWITCH).state == "off" # Switch 2 mock_litejet.switch_pressed_callbacks[ENTITY_OTHER_SWITCH_NUMBER]() await hass.async_block_till_done() assert switch.is_on(hass, ENTITY_OTHER_SWITCH) assert switch.is_on(hass, ENTITY_SWITCH) assert hass.states.get(ENTITY_SWITCH).state == "on" assert hass.states.get(ENTITY_OTHER_SWITCH).state == "on"
def test_on_off(self): """Test turning the switch on and off.""" assert self.switch().state == 'off' assert self.other_switch().state == 'off' assert not switch.is_on(self.hass, ENTITY_SWITCH) switch.turn_on(self.hass, ENTITY_SWITCH) self.hass.block_till_done() self.mock_lj.press_switch.assert_called_with(ENTITY_SWITCH_NUMBER) switch.turn_off(self.hass, ENTITY_SWITCH) self.hass.block_till_done() self.mock_lj.release_switch.assert_called_with(ENTITY_SWITCH_NUMBER)
def test_on_off(self): """Test turning the switch on and off.""" assert self.switch().state == "off" assert self.other_switch().state == "off" assert not switch.is_on(self.hass, ENTITY_SWITCH) common.turn_on(self.hass, ENTITY_SWITCH) self.hass.block_till_done() self.mock_lj.press_switch.assert_called_with(ENTITY_SWITCH_NUMBER) common.turn_off(self.hass, ENTITY_SWITCH) self.hass.block_till_done() self.mock_lj.release_switch.assert_called_with(ENTITY_SWITCH_NUMBER)
async def test_on_off(hass, mock_litejet): """Test turning the switch on and off.""" await async_init_integration(hass, use_switch=True) assert hass.states.get(ENTITY_SWITCH).state == "off" assert hass.states.get(ENTITY_OTHER_SWITCH).state == "off" assert not switch.is_on(hass, ENTITY_SWITCH) await hass.services.async_call(switch.DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: ENTITY_SWITCH}, blocking=True) mock_litejet.press_switch.assert_called_with(ENTITY_SWITCH_NUMBER) await hass.services.async_call(switch.DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: ENTITY_SWITCH}, blocking=True) mock_litejet.release_switch.assert_called_with(ENTITY_SWITCH_NUMBER)
async def test_methods(hass, entities, enable_custom_integrations): """Test is_on, turn_on, turn_off methods.""" switch_1, switch_2, switch_3 = entities assert await async_setup_component( hass, switch.DOMAIN, {switch.DOMAIN: {CONF_PLATFORM: "test"}} ) await hass.async_block_till_done() assert switch.is_on(hass, switch_1.entity_id) assert not switch.is_on(hass, switch_2.entity_id) assert not switch.is_on(hass, switch_3.entity_id) await common.async_turn_off(hass, switch_1.entity_id) await common.async_turn_on(hass, switch_2.entity_id) assert not switch.is_on(hass, switch_1.entity_id) assert switch.is_on(hass, switch_2.entity_id) # Turn all off await common.async_turn_off(hass) assert not switch.is_on(hass, switch_1.entity_id) assert not switch.is_on(hass, switch_2.entity_id) assert not switch.is_on(hass, switch_3.entity_id) # Turn all on await common.async_turn_on(hass) assert switch.is_on(hass, switch_1.entity_id) assert switch.is_on(hass, switch_2.entity_id) assert switch.is_on(hass, switch_3.entity_id)
def test_methods(self): """ Test is_on, turn_on, turn_off methods. """ self.assertTrue(switch.is_on(self.hass)) self.assertEqual( STATE_ON, self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state) self.assertTrue(switch.is_on(self.hass, self.switch_1.entity_id)) self.assertFalse(switch.is_on(self.hass, self.switch_2.entity_id)) self.assertFalse(switch.is_on(self.hass, self.switch_3.entity_id)) switch.turn_off(self.hass, self.switch_1.entity_id) switch.turn_on(self.hass, self.switch_2.entity_id) self.hass.pool.block_till_done() self.assertTrue(switch.is_on(self.hass)) self.assertFalse(switch.is_on(self.hass, self.switch_1.entity_id)) self.assertTrue(switch.is_on(self.hass, self.switch_2.entity_id)) # Turn all off switch.turn_off(self.hass) self.hass.pool.block_till_done() self.assertFalse(switch.is_on(self.hass)) self.assertEqual( STATE_OFF, self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state) self.assertFalse(switch.is_on(self.hass, self.switch_1.entity_id)) self.assertFalse(switch.is_on(self.hass, self.switch_2.entity_id)) self.assertFalse(switch.is_on(self.hass, self.switch_3.entity_id)) # Turn all on switch.turn_on(self.hass) self.hass.pool.block_till_done() self.assertTrue(switch.is_on(self.hass)) self.assertEqual( STATE_ON, self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state) self.assertTrue(switch.is_on(self.hass, self.switch_1.entity_id)) self.assertTrue(switch.is_on(self.hass, self.switch_2.entity_id)) self.assertTrue(switch.is_on(self.hass, self.switch_3.entity_id))
def _is_heating(self): """ If the heater is currently heating. """ return switch.is_on(self.hass, self.heater_entity_id)
def _is_heating(self): """If the heater is currently heating.""" return switch.is_on(self.hass, self.heater_entity_id)
def test_methods(self): """Test is_on, turn_on, turn_off methods.""" self.assertTrue(setup_component( self.hass, switch.DOMAIN, {switch.DOMAIN: {CONF_PLATFORM: 'test'}} )) self.assertTrue(switch.is_on(self.hass)) self.assertEqual( STATE_ON, self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state) self.assertTrue(switch.is_on(self.hass, self.switch_1.entity_id)) self.assertFalse(switch.is_on(self.hass, self.switch_2.entity_id)) self.assertFalse(switch.is_on(self.hass, self.switch_3.entity_id)) switch.turn_off(self.hass, self.switch_1.entity_id) switch.turn_on(self.hass, self.switch_2.entity_id) self.hass.block_till_done() self.assertTrue(switch.is_on(self.hass)) self.assertFalse(switch.is_on(self.hass, self.switch_1.entity_id)) self.assertTrue(switch.is_on(self.hass, self.switch_2.entity_id)) # Turn all off switch.turn_off(self.hass) self.hass.block_till_done() self.assertFalse(switch.is_on(self.hass)) self.assertEqual( STATE_OFF, self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state) self.assertFalse(switch.is_on(self.hass, self.switch_1.entity_id)) self.assertFalse(switch.is_on(self.hass, self.switch_2.entity_id)) self.assertFalse(switch.is_on(self.hass, self.switch_3.entity_id)) # Turn all on switch.turn_on(self.hass) self.hass.block_till_done() self.assertTrue(switch.is_on(self.hass)) self.assertEqual( STATE_ON, self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state) self.assertTrue(switch.is_on(self.hass, self.switch_1.entity_id)) self.assertTrue(switch.is_on(self.hass, self.switch_2.entity_id)) self.assertTrue(switch.is_on(self.hass, self.switch_3.entity_id))
def _is_device_active(self): """If the toggleable device is currently active.""" return switch.is_on(self.hass, self.heater_entity_id)
def test_methods(self): """Test is_on, turn_on, turn_off methods.""" self.assertTrue( setup_component(self.hass, switch.DOMAIN, {switch.DOMAIN: { CONF_PLATFORM: 'test' }})) self.assertTrue(switch.is_on(self.hass)) self.assertEqual( STATE_ON, self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state) self.assertTrue(switch.is_on(self.hass, self.switch_1.entity_id)) self.assertFalse(switch.is_on(self.hass, self.switch_2.entity_id)) self.assertFalse(switch.is_on(self.hass, self.switch_3.entity_id)) common.turn_off(self.hass, self.switch_1.entity_id) common.turn_on(self.hass, self.switch_2.entity_id) self.hass.block_till_done() self.assertTrue(switch.is_on(self.hass)) self.assertFalse(switch.is_on(self.hass, self.switch_1.entity_id)) self.assertTrue(switch.is_on(self.hass, self.switch_2.entity_id)) # Turn all off common.turn_off(self.hass) self.hass.block_till_done() self.assertFalse(switch.is_on(self.hass)) self.assertEqual( STATE_OFF, self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state) self.assertFalse(switch.is_on(self.hass, self.switch_1.entity_id)) self.assertFalse(switch.is_on(self.hass, self.switch_2.entity_id)) self.assertFalse(switch.is_on(self.hass, self.switch_3.entity_id)) # Turn all on common.turn_on(self.hass) self.hass.block_till_done() self.assertTrue(switch.is_on(self.hass)) self.assertEqual( STATE_ON, self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state) self.assertTrue(switch.is_on(self.hass, self.switch_1.entity_id)) self.assertTrue(switch.is_on(self.hass, self.switch_2.entity_id)) self.assertTrue(switch.is_on(self.hass, self.switch_3.entity_id))
def test_methods(self): """Test is_on, turn_on, turn_off methods.""" assert setup_component( self.hass, switch.DOMAIN, {switch.DOMAIN: {CONF_PLATFORM: "test"}} ) assert switch.is_on(self.hass, self.switch_1.entity_id) assert not switch.is_on(self.hass, self.switch_2.entity_id) assert not switch.is_on(self.hass, self.switch_3.entity_id) common.turn_off(self.hass, self.switch_1.entity_id) common.turn_on(self.hass, self.switch_2.entity_id) self.hass.block_till_done() assert not switch.is_on(self.hass, self.switch_1.entity_id) assert switch.is_on(self.hass, self.switch_2.entity_id) # Turn all off common.turn_off(self.hass) self.hass.block_till_done() assert not switch.is_on(self.hass, self.switch_1.entity_id) assert not switch.is_on(self.hass, self.switch_2.entity_id) assert not switch.is_on(self.hass, self.switch_3.entity_id) # Turn all on common.turn_on(self.hass) self.hass.block_till_done() assert switch.is_on(self.hass, self.switch_1.entity_id) assert switch.is_on(self.hass, self.switch_2.entity_id) assert switch.is_on(self.hass, self.switch_3.entity_id)
def test_methods(self): """Test is_on, turn_on, turn_off methods.""" assert setup_component(self.hass, switch.DOMAIN, {switch.DOMAIN: { CONF_PLATFORM: "test" }}) assert switch.is_on(self.hass) assert STATE_ON == self.hass.states.get( switch.ENTITY_ID_ALL_SWITCHES).state assert switch.is_on(self.hass, self.switch_1.entity_id) assert not switch.is_on(self.hass, self.switch_2.entity_id) assert not switch.is_on(self.hass, self.switch_3.entity_id) common.turn_off(self.hass, self.switch_1.entity_id) common.turn_on(self.hass, self.switch_2.entity_id) self.hass.block_till_done() assert switch.is_on(self.hass) assert not switch.is_on(self.hass, self.switch_1.entity_id) assert switch.is_on(self.hass, self.switch_2.entity_id) # Turn all off common.turn_off(self.hass) self.hass.block_till_done() assert not switch.is_on(self.hass) assert STATE_OFF == self.hass.states.get( switch.ENTITY_ID_ALL_SWITCHES).state assert not switch.is_on(self.hass, self.switch_1.entity_id) assert not switch.is_on(self.hass, self.switch_2.entity_id) assert not switch.is_on(self.hass, self.switch_3.entity_id) # Turn all on common.turn_on(self.hass) self.hass.block_till_done() assert switch.is_on(self.hass) assert STATE_ON == self.hass.states.get( switch.ENTITY_ID_ALL_SWITCHES).state assert switch.is_on(self.hass, self.switch_1.entity_id) assert switch.is_on(self.hass, self.switch_2.entity_id) assert switch.is_on(self.hass, self.switch_3.entity_id)
def test_methods(self): """Test is_on, turn_on, turn_off methods.""" assert setup_component( self.hass, switch.DOMAIN, {switch.DOMAIN: {CONF_PLATFORM: 'test'}} ) assert switch.is_on(self.hass) assert STATE_ON == \ self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state assert switch.is_on(self.hass, self.switch_1.entity_id) assert not switch.is_on(self.hass, self.switch_2.entity_id) assert not switch.is_on(self.hass, self.switch_3.entity_id) common.turn_off(self.hass, self.switch_1.entity_id) common.turn_on(self.hass, self.switch_2.entity_id) self.hass.block_till_done() assert switch.is_on(self.hass) assert not switch.is_on(self.hass, self.switch_1.entity_id) assert switch.is_on(self.hass, self.switch_2.entity_id) # Turn all off common.turn_off(self.hass) self.hass.block_till_done() assert not switch.is_on(self.hass) assert STATE_OFF == \ self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state assert not switch.is_on(self.hass, self.switch_1.entity_id) assert not switch.is_on(self.hass, self.switch_2.entity_id) assert not switch.is_on(self.hass, self.switch_3.entity_id) # Turn all on common.turn_on(self.hass) self.hass.block_till_done() assert switch.is_on(self.hass) assert STATE_ON == \ self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state assert switch.is_on(self.hass, self.switch_1.entity_id) assert switch.is_on(self.hass, self.switch_2.entity_id) assert switch.is_on(self.hass, self.switch_3.entity_id)