async def test_learn_timeout(hass): """Test learn service.""" mock_device = MagicMock() mock_device.enter_learning.return_value = None mock_device.check_data.return_value = None async_setup_service(hass, DUMMY_HOST, mock_device) await hass.async_block_till_done() now = utcnow() with patch.object(hass.components.persistent_notification, 'async_create') as mock_create, \ patch('homeassistant.components.broadlink.utcnow') as mock_utcnow: mock_utcnow.side_effect = [now, now + timedelta(20)] await hass.services.async_call(DOMAIN, SERVICE_LEARN, { "host": DUMMY_HOST, }) await hass.async_block_till_done() assert mock_device.enter_learning.call_count == 1 assert mock_device.enter_learning.call_args == call() assert mock_create.call_count == 1 assert mock_create.call_args == call("No signal was received", title='Broadlink switch')
async def test_send(hass): """Test send service.""" mock_device = MagicMock() mock_device.send_data.return_value = None async_setup_service(hass, DUMMY_HOST, mock_device) await hass.async_block_till_done() await hass.services.async_call( DOMAIN, SERVICE_SEND, {"host": DUMMY_HOST, "packet": (DUMMY_IR_PACKET)} ) await hass.async_block_till_done() assert mock_device.send_data.call_count == 1 assert mock_device.send_data.call_args == call(b64decode(DUMMY_IR_PACKET))
async def test_learn(hass): """Test learn service.""" mock_device = MagicMock() mock_device.enter_learning.return_value = None mock_device.check_data.return_value = b64decode(DUMMY_IR_PACKET) with patch.object(hass.components.persistent_notification, "async_create") as mock_create: async_setup_service(hass, DUMMY_HOST, mock_device) await hass.async_block_till_done() await hass.services.async_call(DOMAIN, SERVICE_LEARN, {"host": DUMMY_HOST}) await hass.async_block_till_done() assert mock_device.enter_learning.call_count == 1 assert mock_device.enter_learning.call_args == call() assert mock_create.call_count == 1 assert mock_create.call_args == call( f"Received packet is: {DUMMY_IR_PACKET}", title="Broadlink switch")